diff --git a/Resources/Settings.bundle/Root.plist b/Resources/Settings.bundle/Root.plist index a2355f1..5bac309 100644 --- a/Resources/Settings.bundle/Root.plist +++ b/Resources/Settings.bundle/Root.plist @@ -7,6 +7,8 @@ Type PSGroupSpecifier + Title + Version Info DefaultValue @@ -14,7 +16,17 @@ Key version_preference Title - Version Info + WireGuard iOS + Type + PSTitleValueSpecifier + + + DefaultValue + Set at build time. + Key + wireguard_version_preference + Title + WireGuard Go Type PSTitleValueSpecifier diff --git a/Scripts/extract_wireguard_go_version.sh b/Scripts/extract_wireguard_go_version.sh new file mode 100755 index 0000000..7a5153c --- /dev/null +++ b/Scripts/extract_wireguard_go_version.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +sed=$(sh /etc/profile; which sed) +wireguard_go_version=$("$sed" -n 's/.*WireGuardGoVersion = "\(.*\)\".*/\1/p' wireguard-go/version.go) + +target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" +dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist" + +for plist in "$target_plist" "$dsym_plist"; do + if [ -f "$plist" ]; then + echo $wireguard_go_version + /usr/libexec/PlistBuddy -c "Set :WireGuardGoVersion $wireguard_go_version" "$plist" + fi +done + +settings_root_plist="$TARGET_BUILD_DIR/WireGuard.app/Settings.bundle/Root.plist" + +if [ -f "$settings_root_plist" ]; then + /usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:2:DefaultValue $wireguard_go_version" "$settings_root_plist" +else + echo "Could not find: $settings_root_plist" + exit 1 +fi diff --git a/Scripts/set_build_number.sh b/Scripts/set_build_number.sh index d857f03..1c49437 100755 --- a/Scripts/set_build_number.sh +++ b/Scripts/set_build_number.sh @@ -7,13 +7,17 @@ number_of_commits=$("$git" rev-list HEAD --count) date_timestamp=$("$date" +%Y%m%d) target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" +echo $target_plist dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist" +echo $dsym_plist for plist in "$target_plist" "$dsym_plist"; do if [ -f "$plist" ]; then echo $date_timestamp - /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${number_of_commits}" "$plist" - /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 0.0.${date_timestamp}" "$plist" + echo $plist + echo $number_of_commits + /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist" + /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 0.0.$date_timestamp" "$plist" fi done @@ -28,3 +32,4 @@ else echo "Could not find: $settings_root_plist" exit 1 fi + diff --git a/WireGuard.xcodeproj/project.pbxproj b/WireGuard.xcodeproj/project.pbxproj index 7209ab8..8bbdf91 100644 --- a/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard.xcodeproj/project.pbxproj @@ -417,6 +417,7 @@ 4A4BACDE20B5F1BF00F12B28 /* Sources */, 4A4BACDF20B5F1BF00F12B28 /* Frameworks */, 4A4BACE020B5F1BF00F12B28 /* Resources */, + 4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */, 4A4BAD0920B5F56200F12B28 /* Set build number */, 6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */, 4A61D83220D98CE2006C7A76 /* Embed App Extensions */, @@ -597,6 +598,24 @@ shellPath = /bin/sh; shellScript = "$SRCROOT/Scripts/set_build_number.sh\n"; }; + 4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Set wireguard go version"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "$SRCROOT/Scripts/extract_wireguard_go_version.sh\n"; + }; 6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift index d19422c..9961043 100644 --- a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift +++ b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift @@ -12,26 +12,6 @@ enum GoVersionCoordinatorError: Error { } extension AppCoordinator: SettingsTableViewControllerDelegate { - func goVersionInformation() -> Promise { - return Promise(resolver: { (resolver) in - guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else { - resolver.reject(GoVersionCoordinatorError.noEnabledSession) - return - } - do { - try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in - guard let data = data, let responseString = String(data: data, encoding: .utf8) else { - resolver.reject(GoVersionCoordinatorError.noResponse) - return - } - resolver.fulfill(responseString) - }) - } catch { - resolver.reject(error) - } - }) - } - func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) { self.exportConfigs(sourceView: sourceView) } diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift index 07f8aa1..b3a29c3 100644 --- a/WireGuard/Coordinators/AppCoordinator.swift +++ b/WireGuard/Coordinators/AppCoordinator.swift @@ -329,7 +329,9 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_ func connect(tunnel: Tunnel) { _ = refreshProviderManagers().then { () -> Promise in - let manager = self.providerManager(for: tunnel)! + guard let manager = self.providerManager(for: tunnel) else { + return Promise.value(()) + } let block = { switch manager.connection.status { case .invalid, .disconnected: @@ -411,6 +413,26 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_ return tunnelIdentifier == tunnel.tunnelIdentifier } } + + func extensionGoVersionInformation() -> Promise { + return Promise(resolver: { (resolver) in + guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else { + resolver.reject(GoVersionCoordinatorError.noEnabledSession) + return + } + do { + try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in + guard let data = data, let responseString = String(data: data, encoding: .utf8) else { + resolver.reject(GoVersionCoordinatorError.noResponse) + return + } + resolver.fulfill(responseString) + }) + } catch { + resolver.reject(error) + } + }) + } } class AppDocumentPickerDelegate: NSObject, UIDocumentPickerDelegate { diff --git a/WireGuard/Info.plist b/WireGuard/Info.plist index 4c2bc46..842a2a2 100644 --- a/WireGuard/Info.plist +++ b/WireGuard/Info.plist @@ -67,6 +67,8 @@ 6.0 CFBundleName $(PRODUCT_NAME) + WireGuardGoVersion + unknown CFBundlePackageType APPL CFBundleShortVersionString diff --git a/WireGuard/ViewControllers/SetttingsTableViewController.swift b/WireGuard/ViewControllers/SetttingsTableViewController.swift index 8f87bb7..50832eb 100644 --- a/WireGuard/ViewControllers/SetttingsTableViewController.swift +++ b/WireGuard/ViewControllers/SetttingsTableViewController.swift @@ -11,7 +11,6 @@ enum GoVersionError: Error { protocol SettingsTableViewControllerDelegate: class { func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) - func goVersionInformation() -> Promise } class SettingsTableViewController: UITableViewController { @@ -27,24 +26,7 @@ class SettingsTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() versionInfoLabel.text = versionInformation - _ = firstly { () -> Promise in - self.goVersionInfoLabel.text = NSLocalizedString("Loading...", comment: "") - return goVersionInformation() - }.then { (goVersion: String) -> Guarantee in - if let label = self.goVersionInfoLabel { - label.text = goVersion - } - return Guarantee.value(()) - }.recover({ (error) in - switch error { - case GoVersionCoordinatorError.noEnabledSession: - self.goVersionInfoLabel.text = NSLocalizedString("Unavailable", comment: "") - self.showNotEnabledAlert() - default: - self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "") - } - - }) + goVersionInfoLabel.text = goVersionInformation } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -72,8 +54,8 @@ class SettingsTableViewController: UITableViewController { return versionElements.joined(separator: " ") } - func goVersionInformation() -> Promise { - return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate) + var goVersionInformation: String { + return Bundle.main.infoDictionary!["WireGuardGoVersion"] as? String ?? "Unknown!!!" } private func showNotEnabledAlert() {