From 10e1da61c415ab51fe6a50c3840e88aa5b4c8e0c Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 17:32:06 +0100 Subject: [PATCH 01/16] Read from plist method --- Launcher/Classes/Constants.swift | 1 + Launcher/Classes/PlistOperations.swift | 40 ++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Launcher/Classes/Constants.swift b/Launcher/Classes/Constants.swift index 3dc0fa1..16e625d 100644 --- a/Launcher/Classes/Constants.swift +++ b/Launcher/Classes/Constants.swift @@ -8,6 +8,7 @@ enum Constants { static let installSimulator = "Please install an iOS simulator.".localized static let installSimulatorOrPluginDevice = "Please install a simulator or plug-in your device.".localized static let notCompatibleWithDeviceType = "not compatible with chosen device type." + static let linkInfoKey = "linksInfo" } enum FilePaths { diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index 9dfb988..8e8924f 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -1,17 +1,39 @@ import Foundation class PlistOperations { - func createPlist(data : [String : Any]) { - let fileManager = FileManager.default - + + var plistPath: String + let fileManager = FileManager.default + + public init(defaultPlistPath: String = "/CalabashLauncherSettings.plist") { let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String - let path = documentDirectory.appending("/CalabashLauncherSettings.plist") - - if !fileManager.fileExists(atPath: path) { - try? fileManager.removeItem(atPath: path) + plistPath = documentDirectory.appending(defaultPlistPath) + } + + func createPlist(data : [String : Any]) { + if !fileManager.fileExists(atPath: plistPath) { + try? fileManager.removeItem(atPath: plistPath) } - let someData = NSDictionary(dictionary: data) - someData.write(toFile: path, atomically: true) + someData.write(toFile: plistPath, atomically: true) + } + + func readFromPlist(forKey: String) -> ([String], [String]) { + var plistDictionary: NSDictionary? + var keysArray = [String]() + var valuesArray = [String]() + + if fileManager.fileExists(atPath: plistPath) { + plistDictionary = NSDictionary(contentsOfFile: plistPath) + } + if let objectsArray = plistDictionary?.mutableArrayValue(forKey: forKey) { + objectsArray.forEach { dictionary in + if let dict = dictionary as? NSDictionary, let firstKey = dict.allKeys.first as? String, let firstValue = dict.allValues.first as? String, !dict.allKeys.isEmpty { + keysArray.append(firstKey) + valuesArray.append(firstValue) + } + } + } + return(keysArray, valuesArray) } } From 5f1c9739a3393bcd931b815ded4bcc3f3ea3db15 Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 17:33:14 +0100 Subject: [PATCH 02/16] Read from plist to fill the fields on Settings opening --- .../SettingsViewController.swift | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Launcher/Classes/ViewControllers/SettingsViewController.swift b/Launcher/Classes/ViewControllers/SettingsViewController.swift index 9a0f987..be8734f 100644 --- a/Launcher/Classes/ViewControllers/SettingsViewController.swift +++ b/Launcher/Classes/ViewControllers/SettingsViewController.swift @@ -3,12 +3,12 @@ import AppKit class SettingsViewController: NSViewController { let applicationStateHandler = ApplicationStateHandler() let plistOperations = PlistOperations() - var linkData: [String: Any] = ["items" : []] + let linkInfoKey = Constants.Strings.linkInfoKey var pathChanged = false var hasWarnings = false var singleLinkData: [String: String] = [:] var elements: [(NSTextField, NSTextField)] = [] - + @IBOutlet var fileBrowser: NSPathControl! @IBOutlet weak var cucumberProfileField: NSTextField! @IBOutlet weak var linkField1: NSTextField! @@ -39,18 +39,30 @@ class SettingsViewController: NSViewController { if let cucumberProfile = applicationStateHandler.cucumberProfile { cucumberProfileField.stringValue = cucumberProfile } + + let linkInfoArray = plistOperations.readFromPlist(forKey: linkInfoKey) + let linksArray = linkInfoArray.0 + let linkDescriptionArray = linkInfoArray.1 + + for (index, element) in linksArray.enumerated() { + elements[index].0.stringValue = element + } + + for (index, element) in linkDescriptionArray.enumerated() { + elements[index].1.stringValue = element + } } - @IBAction func clickProceedButton(_ sender: Any) { self.dismiss(true) } @IBAction func clickSaveButton(_ sender: Any) { - linkData["items"] = [:] + var linkData: [String: Any] = [linkInfoKey : []] + linkData[linkInfoKey] = [:] hasWarnings = false var warningState = false - var existingItems = linkData["items"] as? [[String: String]] ?? [] + var existingItems = linkData[linkInfoKey] as? [[String: String]] ?? [] for element in elements { (singleLinkData, warningState) = getLinkDataFrom(linkField: element.0, linkDescriptionField: element.1) @@ -65,12 +77,19 @@ class SettingsViewController: NSViewController { if hasWarnings { existingItems = [[:]] } else { - linkData["items"] = existingItems + linkData[linkInfoKey] = existingItems plistOperations.createPlist(data: linkData) } applicationStateHandler.cucumberProfile = cucumberProfileField.stringValue + // Reload build picker to get new elements + if + let tabViewController = NSApplication.shared.mainWindow?.contentViewController as? NSTabViewController, + let tasksViewController = tabViewController.childViewControllers.first as? TasksViewController { + tasksViewController.getValuesForBuildPicker() + } + // Restart APP after new path is available. Close Settings and save settings otherwise. if pathChanged { AppHandler().restartApplication() From 5ffc8083760547e06de6cbe20443df74f5e9a525 Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 17:34:15 +0100 Subject: [PATCH 03/16] Fill the build picker on the main view --- .../ViewControllers/TasksViewController.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 614072f..eee9b70 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -312,6 +312,19 @@ class TasksViewController: NSViewController { } } + func getValuesForBuildPicker() { + buildPicker.removeAllItems() + let linkInfoArray = plistOperations.readFromPlist(forKey: Constants.Strings.linkInfoKey) + buildPicker.addItems(withTitles: linkInfoArray.1) + + buildPicker.selectItem(at: applicationStateHandler.buildNumber) + if buildPicker.selectedItem == nil { + downloadButton.isEnabled = false + } else { + downloadButton.isEnabled = true + } + } + func quitIrbSession() { commands.executeCommand(at: Constants.FilePaths.Bash.quitIRBSession ?? "", arguments: []) } From 0d5b002337373ab015ca9b476b9a60150a643eb9 Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 17:34:54 +0100 Subject: [PATCH 04/16] Add Download button --- .../ViewControllers/TasksViewController.swift | 11 +++++++- .../Storyboards/Base.lproj/Main.storyboard | 27 ++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index eee9b70..5e93f4c 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -18,11 +18,13 @@ class TasksViewController: NSViewController { @IBOutlet var cautionBuildImage: NSImageView! @IBOutlet weak var textField: NSTextField! @IBOutlet weak var progressBar: NSProgressIndicator! + @IBOutlet weak var downloadButton: NSButton! let localization = Localization() let deviceCollector = DeviceCollector() var textViewPrinter: TextViewPrinter! let commands = CommandsCore.CommandExecutor() + let plistOperations = PlistOperations() var deviceListIsEmpty = false @objc dynamic var isRunning = false let applicationStateHandler = ApplicationStateHandler() @@ -126,8 +128,15 @@ class TasksViewController: NSViewController { commands.executeCommand(at: Constants.FilePaths.Bash.killProcess ?? "", arguments: []) } + @IBAction func clickDownloadButton(_ sender: Any) { + // buildPicker.indexOfSelectedItem + } + @IBAction func buildPicker(_ sender: Any) { - // To be developed + applicationStateHandler.buildNumber = buildPicker.indexOfSelectedItem + if buildPicker.selectedItem != nil { + downloadButton.isEnabled = true + } } @IBAction func clearBufferButton(_ sender: Any) { diff --git a/Launcher/Storyboards/Base.lproj/Main.storyboard b/Launcher/Storyboards/Base.lproj/Main.storyboard index 5e545f8..85e75fd 100644 --- a/Launcher/Storyboards/Base.lproj/Main.storyboard +++ b/Launcher/Storyboards/Base.lproj/Main.storyboard @@ -310,23 +310,28 @@ - + - + - - - - - - - + + @@ -480,6 +485,7 @@ + @@ -986,9 +992,6 @@ - - - From 5bdc4b31194b70a2e85b6def2d29547c862f94b6 Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 17:35:12 +0100 Subject: [PATCH 05/16] A bit of cleanup --- Launcher/Classes/ViewControllers/TasksViewController.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 5e93f4c..ab12b32 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -44,9 +44,8 @@ class TasksViewController: NSViewController { placeholderText.setAttributes([.foregroundColor: NSColor.lightGray], range: NSRange(location: 0, length: "Console Input (Beta)".count)) textField.placeholderAttributedString = placeholderText timer = .scheduledTimer(timeInterval: 40, target: self, selector: #selector(self.limitOfChars), userInfo: nil, repeats: true); - + getValuesForBuildPicker() // Disable these elements for the moment, as it cannot work for people outside XING - buildPicker.isEnabled = false getDeviceButton.isEnabled = false physicalDeviceRadioButton.isEnabled = false simulatorRadioButton.state = .on @@ -341,11 +340,7 @@ class TasksViewController: NSViewController { func statePreservation() { applicationStateHandler.simulatorRadioButtonState = simulatorRadioButton.state.rawValue applicationStateHandler.physicalButtonState = physicalDeviceRadioButton.state.rawValue - applicationStateHandler.buildNumber = buildPicker.indexOfSelectedItem - applicationStateHandler.phoneName = phoneComboBox.titleOfSelectedItem - applicationStateHandler.language = languagePopUpButton.title applicationStateHandler.tag = tagPicker.stringValue - applicationStateHandler.debugState = debugCheckbox.state.rawValue } func runScript() { From 00769050937e5642858a47a011acb965b4ca393b Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Mon, 30 Oct 2017 18:30:50 +0100 Subject: [PATCH 06/16] Add download command --- Calabash Launcher.xcodeproj/project.pbxproj | 4 ++++ Launcher/Classes/Constants.swift | 1 + .../ViewControllers/TasksViewController.swift | 18 +++++++++++++-- Scripts/bash/app_download.command | 23 +++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 Scripts/bash/app_download.command diff --git a/Calabash Launcher.xcodeproj/project.pbxproj b/Calabash Launcher.xcodeproj/project.pbxproj index 7246ddf..5c764bd 100644 --- a/Calabash Launcher.xcodeproj/project.pbxproj +++ b/Calabash Launcher.xcodeproj/project.pbxproj @@ -35,6 +35,7 @@ ED66FA821E0AB8570081A30D /* quit_irb_session.command in Resources */ = {isa = PBXBuildFile; fileRef = ED66FA811E0AB8570081A30D /* quit_irb_session.command */; }; ED7045051DD61B9000272059 /* get_screen.command in Resources */ = {isa = PBXBuildFile; fileRef = ED7045041DD61B9000272059 /* get_screen.command */; }; ED7045071DD6202400272059 /* get_elements_by_offset.command in Resources */ = {isa = PBXBuildFile; fileRef = ED7045061DD6202400272059 /* get_elements_by_offset.command */; }; + ED7278961FA78E050022505E /* app_download.command in Resources */ = {isa = PBXBuildFile; fileRef = ED7278951FA78E050022505E /* app_download.command */; }; ED85D2ED1F94D8A000E5E2D8 /* change_sim_language.command in Resources */ = {isa = PBXBuildFile; fileRef = ED85D2EC1F94D8A000E5E2D8 /* change_sim_language.command */; }; ED85D2F01F950A9400E5E2D8 /* LanguageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED85D2EF1F950A9400E5E2D8 /* LanguageViewController.swift */; }; ED9472941E365F9D00FE2982 /* ElementConstructorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED9472931E365F9C00FE2982 /* ElementConstructorViewController.swift */; }; @@ -98,6 +99,7 @@ ED66FA811E0AB8570081A30D /* quit_irb_session.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = quit_irb_session.command; sourceTree = ""; }; ED7045041DD61B9000272059 /* get_screen.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = get_screen.command; sourceTree = ""; }; ED7045061DD6202400272059 /* get_elements_by_offset.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = get_elements_by_offset.command; sourceTree = ""; }; + ED7278951FA78E050022505E /* app_download.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = app_download.command; sourceTree = ""; }; ED85D2EC1F94D8A000E5E2D8 /* change_sim_language.command */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = change_sim_language.command; sourceTree = ""; }; ED85D2EF1F950A9400E5E2D8 /* LanguageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageViewController.swift; sourceTree = ""; }; ED9472931E365F9C00FE2982 /* ElementConstructorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ElementConstructorViewController.swift; sourceTree = ""; }; @@ -197,6 +199,7 @@ EDD303941F8F86B00042E27F /* bash */ = { isa = PBXGroup; children = ( + ED7278951FA78E050022505E /* app_download.command */, ED85D2EC1F94D8A000E5E2D8 /* change_sim_language.command */, ED9472951E37BD3E00FE2982 /* get_uniq_elements.command */, ED66FA811E0AB8570081A30D /* quit_irb_session.command */, @@ -354,6 +357,7 @@ ED4C14F01DB2A10E00A1190E /* BuildScript.command in Resources */, EDBC88071DFEE8A6004CB840 /* kill_process.command in Resources */, D74D80851F97F7BA0049A84F /* click_image.png in Resources */, + ED7278961FA78E050022505E /* app_download.command in Resources */, ED7045051DD61B9000272059 /* get_screen.command in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Launcher/Classes/Constants.swift b/Launcher/Classes/Constants.swift index 16e625d..d0bb3c9 100644 --- a/Launcher/Classes/Constants.swift +++ b/Launcher/Classes/Constants.swift @@ -18,6 +18,7 @@ enum Constants { static let buildScript = main.path(forResource: "BuildScript", ofType: .bash) static let killProcess = main.path(forResource: "kill_process", ofType: .bash) static let flash = main.path(forResource: "flash", ofType: .bash) + static let appDownload = main.path(forResource: "app_download", ofType: .bash) // Interactive Ruby Shell static let createIRBSession = main.path(forResource: "create_irb_session", ofType: .bash) diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index ab12b32..7fed621 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -32,6 +32,7 @@ class TasksViewController: NSViewController { var devices = [""] var timer: Timer! var pathToCalabashFolder = "" + var linkInfoArray: ([String], [String]) = ([], []) var isDeviceListEmpty: Bool { return phoneComboBox.numberOfItems == 0 } @@ -128,7 +129,7 @@ class TasksViewController: NSViewController { } @IBAction func clickDownloadButton(_ sender: Any) { - // buildPicker.indexOfSelectedItem + downloadAppFromLink(link: linkInfoArray.0[buildPicker.indexOfSelectedItem]) } @IBAction func buildPicker(_ sender: Any) { @@ -322,7 +323,7 @@ class TasksViewController: NSViewController { func getValuesForBuildPicker() { buildPicker.removeAllItems() - let linkInfoArray = plistOperations.readFromPlist(forKey: Constants.Strings.linkInfoKey) + linkInfoArray = plistOperations.readFromPlist(forKey: Constants.Strings.linkInfoKey) buildPicker.addItems(withTitles: linkInfoArray.1) buildPicker.selectItem(at: applicationStateHandler.buildNumber) @@ -333,6 +334,19 @@ class TasksViewController: NSViewController { } } + func downloadAppFromLink(link: String) { + if let launchPath = Constants.FilePaths.Bash.appDownload { + let outputStream = CommandsCore.CommandTextOutputStream() + outputStream.textHandler = {text in + DispatchQueue.main.async { + self.textViewPrinter.printToTextView(text) + } + } + let commands = CommandsCore.CommandExecutor() + commands.executeCommand(at: launchPath, arguments: [link, pathToCalabashFolder], outputStream: outputStream) + } + } + func quitIrbSession() { commands.executeCommand(at: Constants.FilePaths.Bash.quitIRBSession ?? "", arguments: []) } diff --git a/Scripts/bash/app_download.command b/Scripts/bash/app_download.command new file mode 100755 index 0000000..eac45f6 --- /dev/null +++ b/Scripts/bash/app_download.command @@ -0,0 +1,23 @@ +#!/bin/bash --login +export LANG=en_US.UTF-8 +export LANGUAGE=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 + +filename=${1##*/} +extension=${filename##*.} + +cd ${2} +rm ${filename} +curl -O ${1} +if [ -e "$filename" ]; then + echo "${filename} has been succesfully downloaded" +else + echo "Whoops, looks like your link is incorrect: '${1}'" +fi + +if [ ${extension} == "zip" ]; then + echo "Extracting APP from archieve" + ditto -xk ${filename} . + rm ${filename} + echo "Extracted Succesfully" +fi From a8d5acaafbcdc6c031be45b2942c6c52d04b0ea0 Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Mon, 30 Oct 2017 23:58:00 +0100 Subject: [PATCH 07/16] Improve buildPicker state handling --- Launcher/Classes/ApplicationStateHandler.swift | 8 ++++---- Launcher/Classes/Constants.swift | 1 + .../ViewControllers/TasksViewController.swift | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Launcher/Classes/ApplicationStateHandler.swift b/Launcher/Classes/ApplicationStateHandler.swift index 4ed2e9e..f10ce99 100644 --- a/Launcher/Classes/ApplicationStateHandler.swift +++ b/Launcher/Classes/ApplicationStateHandler.swift @@ -8,7 +8,7 @@ class ApplicationStateHandler { case simulatorRadioButtonState = "simRadioButton" case physicalRadioButtonState = "phyRadioButton" case isLaunched = "wasLaunched" - case buildNumber = "buildNumber" + case buildName = "buildName" case filePath = "FilePath" case phoneName = "PhoneName" case phoneUDID = "PhoneUDID" @@ -46,12 +46,12 @@ class ApplicationStateHandler { } } - var buildNumber: Int { + var buildName: String? { get { - return defaults.integer(forKey: .buildNumber) + return defaults.string(forKey: .buildName) } set { - defaults.set(newValue, forKey: .buildNumber) + defaults.set(newValue, forKey: .buildName) } } diff --git a/Launcher/Classes/Constants.swift b/Launcher/Classes/Constants.swift index d0bb3c9..61050d8 100644 --- a/Launcher/Classes/Constants.swift +++ b/Launcher/Classes/Constants.swift @@ -7,6 +7,7 @@ enum Constants { static let pluginDevice = "Please plug-in your device.".localized static let installSimulator = "Please install an iOS simulator.".localized static let installSimulatorOrPluginDevice = "Please install a simulator or plug-in your device.".localized + static let useLocalBuild = "Skip download. Use local APP version.".localized static let notCompatibleWithDeviceType = "not compatible with chosen device type." static let linkInfoKey = "linksInfo" } diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 7fed621..5f8dd3b 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -133,8 +133,10 @@ class TasksViewController: NSViewController { } @IBAction func buildPicker(_ sender: Any) { - applicationStateHandler.buildNumber = buildPicker.indexOfSelectedItem - if buildPicker.selectedItem != nil { + applicationStateHandler.buildName = buildPicker.titleOfSelectedItem + if buildPicker.titleOfSelectedItem == Constants.Strings.useLocalBuild { + downloadButton.isEnabled = false + } else { downloadButton.isEnabled = true } } @@ -325,9 +327,15 @@ class TasksViewController: NSViewController { buildPicker.removeAllItems() linkInfoArray = plistOperations.readFromPlist(forKey: Constants.Strings.linkInfoKey) buildPicker.addItems(withTitles: linkInfoArray.1) + buildPicker.addItem(withTitle: Constants.Strings.useLocalBuild) + + if let buildName = applicationStateHandler.buildName, buildPicker.itemTitles.contains(buildName) { + buildPicker.selectItem(withTitle: buildName) + } else { + buildPicker.selectItem(withTitle: Constants.Strings.useLocalBuild) + } - buildPicker.selectItem(at: applicationStateHandler.buildNumber) - if buildPicker.selectedItem == nil { + if buildPicker.titleOfSelectedItem == Constants.Strings.useLocalBuild { downloadButton.isEnabled = false } else { downloadButton.isEnabled = true From 8c34d799e868b03ef468d38350706097f04cd3b2 Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Tue, 31 Oct 2017 00:07:08 +0100 Subject: [PATCH 08/16] Update Changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index e3db943..12bb7cf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ - Removed unused "Physical device" functionality ([#35](https://github.com/JoeSSS/calabash-launcher/pull/35)) - Improved launch time ([#34](https://github.com/JoeSSS/calabash-launcher/pull/34)) - Added "Reset to default" functionality ([#36](https://github.com/JoeSSS/calabash-launcher/pull/36)) +- Added functionality to download APP from link # 0.1 From 855dfe2b800cd78b2aaee82fe8f6b71da89081da Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Tue, 31 Oct 2017 23:42:30 +0100 Subject: [PATCH 09/16] Apply PR recommendations --- Calabash Launcher.xcodeproj/project.pbxproj | 4 ++++ .../Controllers/CommandsController.swift | 23 +++++++++++++++++++ Launcher/Classes/PlistOperations.swift | 4 ++-- .../SettingsViewController.swift | 4 ++-- .../ViewControllers/TasksViewController.swift | 17 ++------------ 5 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 Launcher/Classes/Controllers/CommandsController.swift diff --git a/Calabash Launcher.xcodeproj/project.pbxproj b/Calabash Launcher.xcodeproj/project.pbxproj index 5c764bd..e786261 100644 --- a/Calabash Launcher.xcodeproj/project.pbxproj +++ b/Calabash Launcher.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ D71FD8681F9E6C140091FD30 /* AppHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D71FD8671F9E6C140091FD30 /* AppHandler.swift */; }; D74D80851F97F7BA0049A84F /* click_image.png in Resources */ = {isa = PBXBuildFile; fileRef = D74D80841F97F7BA0049A84F /* click_image.png */; }; D7CAAEC01F940B76006F8AE8 /* Gemfile.lock in Resources */ = {isa = PBXBuildFile; fileRef = D7CAAEBF1F940B76006F8AE8 /* Gemfile.lock */; }; + D7DDE9AC1FA92DBA0083D00E /* CommandsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DDE9AB1FA92DBA0083D00E /* CommandsController.swift */; }; D7E21B4A1F969FDD0044169A /* Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E21B491F969FDD0044169A /* Localization.swift */; }; D7E21B4C1F96B0470044169A /* RegexHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7E21B4B1F96B0470044169A /* RegexHandler.swift */; }; ED06A0E21E850CA70092C96E /* BashOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED06A0E11E850CA70092C96E /* BashOutput.swift */; }; @@ -78,6 +79,7 @@ D71FD8671F9E6C140091FD30 /* AppHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppHandler.swift; sourceTree = ""; }; D74D80841F97F7BA0049A84F /* click_image.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = click_image.png; sourceTree = ""; }; D7CAAEBF1F940B76006F8AE8 /* Gemfile.lock */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Gemfile.lock; sourceTree = ""; }; + D7DDE9AB1FA92DBA0083D00E /* CommandsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandsController.swift; sourceTree = ""; }; D7E21B491F969FDD0044169A /* Localization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Localization.swift; sourceTree = ""; }; D7E21B4B1F96B0470044169A /* RegexHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegexHandler.swift; sourceTree = ""; }; ED06A0E11E850CA70092C96E /* BashOutput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BashOutput.swift; sourceTree = ""; }; @@ -271,6 +273,7 @@ isa = PBXGroup; children = ( FD1047071F90AB2100A89D1C /* TagsController.swift */, + D7DDE9AB1FA92DBA0083D00E /* CommandsController.swift */, ); path = Controllers; sourceTree = ""; @@ -378,6 +381,7 @@ FD4D0F351F8D086100EAD142 /* ApplicationStateHandler.swift in Sources */, ED9472941E365F9D00FE2982 /* ElementConstructorViewController.swift in Sources */, EDB433361DD49AF5001BABEC /* InspectorViewController.swift in Sources */, + D7DDE9AC1FA92DBA0083D00E /* CommandsController.swift in Sources */, 5D948C941F8F556D0001BC50 /* Language.swift in Sources */, ED85D2F01F950A9400E5E2D8 /* LanguageViewController.swift in Sources */, EDC4C6331F9A1DC000EAE830 /* TextViewPrinter.swift in Sources */, diff --git a/Launcher/Classes/Controllers/CommandsController.swift b/Launcher/Classes/Controllers/CommandsController.swift new file mode 100644 index 0000000..1e62eb0 --- /dev/null +++ b/Launcher/Classes/Controllers/CommandsController.swift @@ -0,0 +1,23 @@ +import AppKit +import CommandsCore + +class CommandsController { + let applicationStateHandler = ApplicationStateHandler() + + func downloadAppFromLink(link: String, textView: NSTextView) { + let textViewPrinter = TextViewPrinter(textView: textView) + if let launchPath = Constants.FilePaths.Bash.appDownload { + let outputStream = CommandTextOutputStream() + outputStream.textHandler = {text in + DispatchQueue.main.async { + textViewPrinter.printToTextView(text) + } + } + let commands = CommandExecutor() + if let path = applicationStateHandler.filePath { + let filePath = path.absoluteString.replacingOccurrences(of: "file://", with: "") + commands.executeCommand(at: launchPath, arguments: [link, filePath], outputStream: outputStream) + } + } + } +} diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index 8e8924f..eff33ce 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -10,7 +10,7 @@ class PlistOperations { plistPath = documentDirectory.appending(defaultPlistPath) } - func createPlist(data : [String : Any]) { + func create(data : [String : Any]) { if !fileManager.fileExists(atPath: plistPath) { try? fileManager.removeItem(atPath: plistPath) } @@ -18,7 +18,7 @@ class PlistOperations { someData.write(toFile: plistPath, atomically: true) } - func readFromPlist(forKey: String) -> ([String], [String]) { + func read(forKey: String) -> ([String], [String]) { var plistDictionary: NSDictionary? var keysArray = [String]() var valuesArray = [String]() diff --git a/Launcher/Classes/ViewControllers/SettingsViewController.swift b/Launcher/Classes/ViewControllers/SettingsViewController.swift index be8734f..4c89c1c 100644 --- a/Launcher/Classes/ViewControllers/SettingsViewController.swift +++ b/Launcher/Classes/ViewControllers/SettingsViewController.swift @@ -40,7 +40,7 @@ class SettingsViewController: NSViewController { cucumberProfileField.stringValue = cucumberProfile } - let linkInfoArray = plistOperations.readFromPlist(forKey: linkInfoKey) + let linkInfoArray = plistOperations.read(forKey: linkInfoKey) let linksArray = linkInfoArray.0 let linkDescriptionArray = linkInfoArray.1 @@ -78,7 +78,7 @@ class SettingsViewController: NSViewController { existingItems = [[:]] } else { linkData[linkInfoKey] = existingItems - plistOperations.createPlist(data: linkData) + plistOperations.create(data: linkData) } applicationStateHandler.cucumberProfile = cucumberProfileField.stringValue diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 5f8dd3b..6bd4bab 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -129,7 +129,7 @@ class TasksViewController: NSViewController { } @IBAction func clickDownloadButton(_ sender: Any) { - downloadAppFromLink(link: linkInfoArray.0[buildPicker.indexOfSelectedItem]) + CommandsController().downloadAppFromLink(link: linkInfoArray.0[buildPicker.indexOfSelectedItem], textView: textView) } @IBAction func buildPicker(_ sender: Any) { @@ -325,7 +325,7 @@ class TasksViewController: NSViewController { func getValuesForBuildPicker() { buildPicker.removeAllItems() - linkInfoArray = plistOperations.readFromPlist(forKey: Constants.Strings.linkInfoKey) + linkInfoArray = plistOperations.read(forKey: Constants.Strings.linkInfoKey) buildPicker.addItems(withTitles: linkInfoArray.1) buildPicker.addItem(withTitle: Constants.Strings.useLocalBuild) @@ -342,19 +342,6 @@ class TasksViewController: NSViewController { } } - func downloadAppFromLink(link: String) { - if let launchPath = Constants.FilePaths.Bash.appDownload { - let outputStream = CommandsCore.CommandTextOutputStream() - outputStream.textHandler = {text in - DispatchQueue.main.async { - self.textViewPrinter.printToTextView(text) - } - } - let commands = CommandsCore.CommandExecutor() - commands.executeCommand(at: launchPath, arguments: [link, pathToCalabashFolder], outputStream: outputStream) - } - } - func quitIrbSession() { commands.executeCommand(at: Constants.FilePaths.Bash.quitIRBSession ?? "", arguments: []) } From d352392ffc639703a3e7dc5b961a565d77f11ebe Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Wed, 1 Nov 2017 10:53:33 +0100 Subject: [PATCH 10/16] Fix merge conflict --- Launcher/Classes/Controllers/CommandsController.swift | 4 ++-- Launcher/Classes/ViewControllers/TasksViewController.swift | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Launcher/Classes/Controllers/CommandsController.swift b/Launcher/Classes/Controllers/CommandsController.swift index 1e62eb0..28b8fc6 100644 --- a/Launcher/Classes/Controllers/CommandsController.swift +++ b/Launcher/Classes/Controllers/CommandsController.swift @@ -13,10 +13,10 @@ class CommandsController { textViewPrinter.printToTextView(text) } } - let commands = CommandExecutor() + if let path = applicationStateHandler.filePath { let filePath = path.absoluteString.replacingOccurrences(of: "file://", with: "") - commands.executeCommand(at: launchPath, arguments: [link, filePath], outputStream: outputStream) + CommandExecutor(launchPath: launchPath,arguments: [link, filePath], outputStream: outputStream).execute() } } } diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index fe3ba35..3a4eab7 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -23,7 +23,6 @@ class TasksViewController: NSViewController { let localization = Localization() let deviceCollector = DeviceCollector() var textViewPrinter: TextViewPrinter! - let commands = CommandsCore.CommandExecutor() let plistOperations = PlistOperations() var deviceListIsEmpty = false @objc dynamic var isRunning = false From 20d149cace3b666844d88adb310bca15ab685e9f Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Wed, 1 Nov 2017 11:00:08 +0100 Subject: [PATCH 11/16] Remore unnecessary file removal --- Calabash Launcher.xcodeproj/project.pbxproj | 5 +++-- Launcher/Classes/PlistOperations.swift | 3 --- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Calabash Launcher.xcodeproj/project.pbxproj b/Calabash Launcher.xcodeproj/project.pbxproj index e786261..f10ee65 100644 --- a/Calabash Launcher.xcodeproj/project.pbxproj +++ b/Calabash Launcher.xcodeproj/project.pbxproj @@ -311,6 +311,7 @@ TargetAttributes = { ED4C14DC1DB29FB700A1190E = { CreatedOnToolsVersion = 8.0; + DevelopmentTeam = 677393NEQ3; LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; @@ -525,7 +526,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 677393NEQ3; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Launcher/Frameworks", @@ -549,7 +550,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = 677393NEQ3; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Launcher/Frameworks", diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index eff33ce..fa0a2bb 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -11,9 +11,6 @@ class PlistOperations { } func create(data : [String : Any]) { - if !fileManager.fileExists(atPath: plistPath) { - try? fileManager.removeItem(atPath: plistPath) - } let someData = NSDictionary(dictionary: data) someData.write(toFile: plistPath, atomically: true) } From c3db732dd90de64ab706b56aa232e2260c1a99be Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Wed, 1 Nov 2017 18:42:15 +0100 Subject: [PATCH 12/16] Remove development team --- Calabash Launcher.xcodeproj/project.pbxproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Calabash Launcher.xcodeproj/project.pbxproj b/Calabash Launcher.xcodeproj/project.pbxproj index f10ee65..e786261 100644 --- a/Calabash Launcher.xcodeproj/project.pbxproj +++ b/Calabash Launcher.xcodeproj/project.pbxproj @@ -311,7 +311,6 @@ TargetAttributes = { ED4C14DC1DB29FB700A1190E = { CreatedOnToolsVersion = 8.0; - DevelopmentTeam = 677393NEQ3; LastSwiftMigration = 0910; ProvisioningStyle = Automatic; }; @@ -526,7 +525,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 677393NEQ3; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Launcher/Frameworks", @@ -550,7 +549,7 @@ CODE_SIGN_IDENTITY = "Mac Developer"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = 677393NEQ3; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Launcher/Frameworks", From 6629bd678226d0687f405b1f8b258c88771405eb Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Wed, 1 Nov 2017 21:30:41 +0100 Subject: [PATCH 13/16] Restructure PlistOperations --- Launcher/Classes/PlistOperations.swift | 30 +++++++++++++------ .../SettingsViewController.swift | 28 ++++++++--------- .../ViewControllers/TasksViewController.swift | 10 +++---- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index fa0a2bb..8f6cab9 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -4,8 +4,10 @@ class PlistOperations { var plistPath: String let fileManager = FileManager.default + var dictionaryKey = "" - public init(defaultPlistPath: String = "/CalabashLauncherSettings.plist") { + public init(forKey: String, defaultPlistPath: String = "/CalabashLauncherSettings.plist") { + dictionaryKey = forKey let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String plistPath = documentDirectory.appending(defaultPlistPath) } @@ -15,22 +17,32 @@ class PlistOperations { someData.write(toFile: plistPath, atomically: true) } - func read(forKey: String) -> ([String], [String]) { + func read() -> [NSDictionary] { var plistDictionary: NSDictionary? - var keysArray = [String]() - var valuesArray = [String]() + var keysArray = [NSDictionary]() if fileManager.fileExists(atPath: plistPath) { plistDictionary = NSDictionary(contentsOfFile: plistPath) } - if let objectsArray = plistDictionary?.mutableArrayValue(forKey: forKey) { + if let objectsArray = plistDictionary?.mutableArrayValue(forKey: dictionaryKey) { objectsArray.forEach { dictionary in - if let dict = dictionary as? NSDictionary, let firstKey = dict.allKeys.first as? String, let firstValue = dict.allValues.first as? String, !dict.allKeys.isEmpty { - keysArray.append(firstKey) - valuesArray.append(firstValue) + if let dict = dictionary as? NSDictionary, !dict.allKeys.isEmpty { + keysArray.append(dict) } } } - return(keysArray, valuesArray) + return(keysArray) + } + + func readValues() -> [String] { + let dictionaryData = self.read() + let valuesArray = dictionaryData.flatMap { $0.allValues } as? [String] + return valuesArray ?? [""] + } + + func readKeys() -> [String] { + let dictionaryData = self.read() + let keysArray = dictionaryData.flatMap { $0.allKeys } as? [String] + return keysArray ?? [""] } } diff --git a/Launcher/Classes/ViewControllers/SettingsViewController.swift b/Launcher/Classes/ViewControllers/SettingsViewController.swift index 50f91f4..8cfba46 100644 --- a/Launcher/Classes/ViewControllers/SettingsViewController.swift +++ b/Launcher/Classes/ViewControllers/SettingsViewController.swift @@ -2,8 +2,7 @@ import AppKit class SettingsViewController: NSViewController { let applicationStateHandler = ApplicationStateHandler() - let plistOperations = PlistOperations() - let linkInfoKey = Constants.Strings.linkInfoKey + let plistOperations = PlistOperations(forKey: Constants.Strings.linkInfoKey) var pathChanged = false var hasWarnings = false var singleLinkData: [String: String] = [:] @@ -41,18 +40,17 @@ class SettingsViewController: NSViewController { cucumberProfileField.stringValue = cucumberProfile } - let linkInfoArray = plistOperations.read(forKey: linkInfoKey) - let linksArray = linkInfoArray.0 - let linkDescriptionArray = linkInfoArray.1 - - for (index, element) in linksArray.enumerated() { - elements[index].0.stringValue = element + let linkArray = plistOperations.readKeys() + let linkDescriptionArray = plistOperations.readValues() + + for (index, element) in linkArray.enumerated() { + elements[index].0.stringValue = String(describing: element) } - + for (index, element) in linkDescriptionArray.enumerated() { - elements[index].1.stringValue = element + elements[index].1.stringValue = String(describing: element) } - + if let additionalParameters = applicationStateHandler.additionalRunParameters { additionalRunParameters.stringValue = additionalParameters } @@ -63,11 +61,11 @@ class SettingsViewController: NSViewController { } @IBAction func clickSaveButton(_ sender: Any) { - var linkData: [String: Any] = [linkInfoKey : []] - linkData[linkInfoKey] = [:] + var linkData: [String: Any] = [Constants.Strings.linkInfoKey : []] + linkData[Constants.Strings.linkInfoKey] = [:] hasWarnings = false var warningState = false - var existingItems = linkData[linkInfoKey] as? [[String: String]] ?? [] + var existingItems = linkData[Constants.Strings.linkInfoKey] as? [[String: String]] ?? [] for element in elements { (singleLinkData, warningState) = getLinkDataFrom(linkField: element.0, linkDescriptionField: element.1) @@ -82,7 +80,7 @@ class SettingsViewController: NSViewController { if hasWarnings { existingItems = [[:]] } else { - linkData[linkInfoKey] = existingItems + linkData[Constants.Strings.linkInfoKey] = existingItems plistOperations.create(data: linkData) } diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 3a4eab7..1afa93a 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -22,8 +22,8 @@ class TasksViewController: NSViewController { let localization = Localization() let deviceCollector = DeviceCollector() + let plistOperations = PlistOperations(forKey: Constants.Strings.linkInfoKey) var textViewPrinter: TextViewPrinter! - let plistOperations = PlistOperations() var deviceListIsEmpty = false @objc dynamic var isRunning = false let applicationStateHandler = ApplicationStateHandler() @@ -31,7 +31,7 @@ class TasksViewController: NSViewController { var devices = [""] var timer: Timer! var pathToCalabashFolder = "" - var linkInfoArray: ([String], [String]) = ([], []) + var linkInfoArray = [""] var isDeviceListEmpty: Bool { return phoneComboBox.numberOfItems == 0 } @@ -128,7 +128,7 @@ class TasksViewController: NSViewController { } @IBAction func clickDownloadButton(_ sender: Any) { - CommandsController().downloadAppFromLink(link: linkInfoArray.0[buildPicker.indexOfSelectedItem], textView: textView) + CommandsController().downloadAppFromLink(link: linkInfoArray[buildPicker.indexOfSelectedItem], textView: textView) } @IBAction func buildPicker(_ sender: Any) { @@ -324,8 +324,8 @@ class TasksViewController: NSViewController { func getValuesForBuildPicker() { buildPicker.removeAllItems() - linkInfoArray = plistOperations.read(forKey: Constants.Strings.linkInfoKey) - buildPicker.addItems(withTitles: linkInfoArray.1) + linkInfoArray = plistOperations.readValues() + buildPicker.addItems(withTitles: linkInfoArray) buildPicker.addItem(withTitle: Constants.Strings.useLocalBuild) if let buildName = applicationStateHandler.buildName, buildPicker.itemTitles.contains(buildName) { From a0d2ee8fd57ab7a35aa2dc3305ab94af2c90ad1e Mon Sep 17 00:00:00 2001 From: JoeSSS Date: Wed, 1 Nov 2017 21:47:30 +0100 Subject: [PATCH 14/16] Renaming --- Launcher/Classes/PlistOperations.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index 8f6cab9..895995b 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -19,7 +19,7 @@ class PlistOperations { func read() -> [NSDictionary] { var plistDictionary: NSDictionary? - var keysArray = [NSDictionary]() + var dictionaryArray = [NSDictionary]() if fileManager.fileExists(atPath: plistPath) { plistDictionary = NSDictionary(contentsOfFile: plistPath) @@ -27,11 +27,11 @@ class PlistOperations { if let objectsArray = plistDictionary?.mutableArrayValue(forKey: dictionaryKey) { objectsArray.forEach { dictionary in if let dict = dictionary as? NSDictionary, !dict.allKeys.isEmpty { - keysArray.append(dict) + dictionaryArray.append(dict) } } } - return(keysArray) + return(dictionaryArray) } func readValues() -> [String] { From 7916bd3ece707945e5b28bb322b9af1231d7fb66 Mon Sep 17 00:00:00 2001 From: Bas Broek Date: Thu, 2 Nov 2017 16:46:54 +0100 Subject: [PATCH 15/16] Cleanup --- Launcher/Classes/Constants.swift | 9 ++-- .../Controllers/CommandsController.swift | 22 +++++----- Launcher/Classes/PlistOperations.swift | 44 +++++++------------ .../SettingsViewController.swift | 14 +++--- .../ViewControllers/TasksViewController.swift | 5 ++- .../Storyboards/Base.lproj/Main.storyboard | 12 ++--- Scripts/bash/BuildScript.command | 2 +- Scripts/bash/app_download.command | 2 +- Scripts/bash/console.command | 2 +- 9 files changed, 52 insertions(+), 60 deletions(-) diff --git a/Launcher/Classes/Constants.swift b/Launcher/Classes/Constants.swift index 61050d8..5195b8a 100644 --- a/Launcher/Classes/Constants.swift +++ b/Launcher/Classes/Constants.swift @@ -7,9 +7,12 @@ enum Constants { static let pluginDevice = "Please plug-in your device.".localized static let installSimulator = "Please install an iOS simulator.".localized static let installSimulatorOrPluginDevice = "Please install a simulator or plug-in your device.".localized - static let useLocalBuild = "Skip download. Use local APP version.".localized - static let notCompatibleWithDeviceType = "not compatible with chosen device type." - static let linkInfoKey = "linksInfo" + static let useLocalBuild = "Skipping download. Use a local app version.".localized + static let notCompatibleWithDeviceType = "not compatible with chosen device type.".localized + } + + enum Keys { + static let linkInfo = "linksInfo" } enum FilePaths { diff --git a/Launcher/Classes/Controllers/CommandsController.swift b/Launcher/Classes/Controllers/CommandsController.swift index 28b8fc6..8b1d180 100644 --- a/Launcher/Classes/Controllers/CommandsController.swift +++ b/Launcher/Classes/Controllers/CommandsController.swift @@ -4,20 +4,18 @@ import CommandsCore class CommandsController { let applicationStateHandler = ApplicationStateHandler() - func downloadAppFromLink(link: String, textView: NSTextView) { + func downloadApp(from url: URL, textView: NSTextView) { let textViewPrinter = TextViewPrinter(textView: textView) - if let launchPath = Constants.FilePaths.Bash.appDownload { - let outputStream = CommandTextOutputStream() - outputStream.textHandler = {text in - DispatchQueue.main.async { - textViewPrinter.printToTextView(text) - } - } - - if let path = applicationStateHandler.filePath { - let filePath = path.absoluteString.replacingOccurrences(of: "file://", with: "") - CommandExecutor(launchPath: launchPath,arguments: [link, filePath], outputStream: outputStream).execute() + guard let launchPath = Constants.FilePaths.Bash.appDownload else { return } + let outputStream = CommandTextOutputStream() + outputStream.textHandler = { text in + DispatchQueue.main.async { + textViewPrinter.printToTextView(text) } } + + guard let path = applicationStateHandler.filePath else { return } + let filePath = path.absoluteString.replacingOccurrences(of: "file://", with: "") + CommandExecutor(launchPath: launchPath,arguments: [url.absoluteString, filePath], outputStream: outputStream).execute() } } diff --git a/Launcher/Classes/PlistOperations.swift b/Launcher/Classes/PlistOperations.swift index 895995b..8cf6351 100644 --- a/Launcher/Classes/PlistOperations.swift +++ b/Launcher/Classes/PlistOperations.swift @@ -2,47 +2,37 @@ import Foundation class PlistOperations { - var plistPath: String + let plistPath: String let fileManager = FileManager.default - var dictionaryKey = "" + let dictionaryKey: String - public init(forKey: String, defaultPlistPath: String = "/CalabashLauncherSettings.plist") { - dictionaryKey = forKey + public init(forKey key: String, defaultPlistPath path: String = "/CalabashLauncherSettings.plist") { + dictionaryKey = key let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String - plistPath = documentDirectory.appending(defaultPlistPath) + plistPath = documentDirectory.appending(path) } - func create(data : [String : Any]) { - let someData = NSDictionary(dictionary: data) + func create(from dictionary: [String: Any]) { + let someData = NSDictionary(dictionary: dictionary) someData.write(toFile: plistPath, atomically: true) } - func read() -> [NSDictionary] { - var plistDictionary: NSDictionary? - var dictionaryArray = [NSDictionary]() - - if fileManager.fileExists(atPath: plistPath) { - plistDictionary = NSDictionary(contentsOfFile: plistPath) - } - if let objectsArray = plistDictionary?.mutableArrayValue(forKey: dictionaryKey) { - objectsArray.forEach { dictionary in - if let dict = dictionary as? NSDictionary, !dict.allKeys.isEmpty { - dictionaryArray.append(dict) - } - } + private func read() -> [NSDictionary] { + guard + fileManager.fileExists(atPath: plistPath), + let dictionary = NSDictionary(contentsOfFile: plistPath) else { return [] } + + return dictionary.mutableArrayValue(forKey: dictionaryKey).flatMap { element -> NSDictionary? in + guard let dictionary = element as? NSDictionary else { return nil } + return dictionary } - return(dictionaryArray) } func readValues() -> [String] { - let dictionaryData = self.read() - let valuesArray = dictionaryData.flatMap { $0.allValues } as? [String] - return valuesArray ?? [""] + return read().flatMap { $0.allValues } as? [String] ?? [] } func readKeys() -> [String] { - let dictionaryData = self.read() - let keysArray = dictionaryData.flatMap { $0.allKeys } as? [String] - return keysArray ?? [""] + return read().flatMap { $0.allKeys } as? [String] ?? [] } } diff --git a/Launcher/Classes/ViewControllers/SettingsViewController.swift b/Launcher/Classes/ViewControllers/SettingsViewController.swift index 8cfba46..a76459e 100644 --- a/Launcher/Classes/ViewControllers/SettingsViewController.swift +++ b/Launcher/Classes/ViewControllers/SettingsViewController.swift @@ -2,7 +2,7 @@ import AppKit class SettingsViewController: NSViewController { let applicationStateHandler = ApplicationStateHandler() - let plistOperations = PlistOperations(forKey: Constants.Strings.linkInfoKey) + let plistOperations = PlistOperations(forKey: Constants.Keys.linkInfo) var pathChanged = false var hasWarnings = false var singleLinkData: [String: String] = [:] @@ -61,11 +61,11 @@ class SettingsViewController: NSViewController { } @IBAction func clickSaveButton(_ sender: Any) { - var linkData: [String: Any] = [Constants.Strings.linkInfoKey : []] - linkData[Constants.Strings.linkInfoKey] = [:] + var linkData: [String: Any] = [Constants.Keys.linkInfo : []] + linkData[Constants.Keys.linkInfo] = [:] hasWarnings = false var warningState = false - var existingItems = linkData[Constants.Strings.linkInfoKey] as? [[String: String]] ?? [] + var existingItems = linkData[Constants.Keys.linkInfo] as? [[String: String]] ?? [] for element in elements { (singleLinkData, warningState) = getLinkDataFrom(linkField: element.0, linkDescriptionField: element.1) @@ -80,8 +80,8 @@ class SettingsViewController: NSViewController { if hasWarnings { existingItems = [[:]] } else { - linkData[Constants.Strings.linkInfoKey] = existingItems - plistOperations.create(data: linkData) + linkData[Constants.Keys.linkInfo] = existingItems + plistOperations.create(from: linkData) } applicationStateHandler.cucumberProfile = cucumberProfileField.stringValue @@ -94,7 +94,7 @@ class SettingsViewController: NSViewController { tasksViewController.getValuesForBuildPicker() } - // Restart APP after new path is available. Close Settings and save settings otherwise. + // Restart app after new path is available. Close Settings and save settings otherwise. if pathChanged { AppHandler().restartApplication() } else if !hasWarnings { diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 1afa93a..3f0c8ba 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -22,7 +22,7 @@ class TasksViewController: NSViewController { let localization = Localization() let deviceCollector = DeviceCollector() - let plistOperations = PlistOperations(forKey: Constants.Strings.linkInfoKey) + let plistOperations = PlistOperations(forKey: Constants.Keys.linkInfo) var textViewPrinter: TextViewPrinter! var deviceListIsEmpty = false @objc dynamic var isRunning = false @@ -128,7 +128,8 @@ class TasksViewController: NSViewController { } @IBAction func clickDownloadButton(_ sender: Any) { - CommandsController().downloadAppFromLink(link: linkInfoArray[buildPicker.indexOfSelectedItem], textView: textView) + guard let url = URL(string: linkInfoArray[buildPicker.indexOfSelectedItem]) else { return } + CommandsController().downloadApp(from: url, textView: textView) } @IBAction func buildPicker(_ sender: Any) { diff --git a/Launcher/Storyboards/Base.lproj/Main.storyboard b/Launcher/Storyboards/Base.lproj/Main.storyboard index 9b82684..2b2ddb9 100644 --- a/Launcher/Storyboards/Base.lproj/Main.storyboard +++ b/Launcher/Storyboards/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -1007,7 +1007,7 @@ - + @@ -1016,7 +1016,7 @@ - + @@ -1025,7 +1025,7 @@ - + @@ -1070,7 +1070,7 @@ - + diff --git a/Scripts/bash/BuildScript.command b/Scripts/bash/BuildScript.command index 5e91fd0..3fdb147 100755 --- a/Scripts/bash/BuildScript.command +++ b/Scripts/bash/BuildScript.command @@ -3,7 +3,7 @@ file=${3}/Gemfile if [ ! -e "$file" ]; then echo $file -echo "The path to Calabash folder is incorrect, please choose the right one. File chooser is in the APP Settings" +echo "The path to Calabash folder is incorrect; please choose the right one. File chooser is in the app Settings" exit fi diff --git a/Scripts/bash/app_download.command b/Scripts/bash/app_download.command index eac45f6..9f19bc3 100755 --- a/Scripts/bash/app_download.command +++ b/Scripts/bash/app_download.command @@ -16,7 +16,7 @@ else fi if [ ${extension} == "zip" ]; then - echo "Extracting APP from archieve" + echo "Extracting app from archive" ditto -xk ${filename} . rm ${filename} echo "Extracted Succesfully" diff --git a/Scripts/bash/console.command b/Scripts/bash/console.command index 255c890..ed63a83 100755 --- a/Scripts/bash/console.command +++ b/Scripts/bash/console.command @@ -4,7 +4,7 @@ file=${1}/Gemfile if [ ! -e "$file" ]; then echo $file -echo "The path to Calabash folder is incorrect, please choose the right one. File chooser is in the APP Settings" +echo "The path to Calabash folder is incorrect; please choose the right one. File chooser is in the app Settings" else if open -Ra "iTerm" ; then From 895bb42a5355377be022d500ba1a5a364e8a867c Mon Sep 17 00:00:00 2001 From: Serghei Moret Date: Thu, 2 Nov 2017 17:53:43 +0100 Subject: [PATCH 16/16] small bug fixes --- Launcher/Classes/Controllers/CommandsController.swift | 4 +++- Launcher/Classes/ViewControllers/TasksViewController.swift | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Launcher/Classes/Controllers/CommandsController.swift b/Launcher/Classes/Controllers/CommandsController.swift index 8b1d180..0020ee1 100644 --- a/Launcher/Classes/Controllers/CommandsController.swift +++ b/Launcher/Classes/Controllers/CommandsController.swift @@ -16,6 +16,8 @@ class CommandsController { guard let path = applicationStateHandler.filePath else { return } let filePath = path.absoluteString.replacingOccurrences(of: "file://", with: "") - CommandExecutor(launchPath: launchPath,arguments: [url.absoluteString, filePath], outputStream: outputStream).execute() + DispatchQueue.global(qos: .background).async { + CommandExecutor(launchPath: launchPath,arguments: [url.absoluteString, filePath], outputStream: outputStream).execute() + } } } diff --git a/Launcher/Classes/ViewControllers/TasksViewController.swift b/Launcher/Classes/ViewControllers/TasksViewController.swift index 3f0c8ba..b5f69d7 100644 --- a/Launcher/Classes/ViewControllers/TasksViewController.swift +++ b/Launcher/Classes/ViewControllers/TasksViewController.swift @@ -128,7 +128,7 @@ class TasksViewController: NSViewController { } @IBAction func clickDownloadButton(_ sender: Any) { - guard let url = URL(string: linkInfoArray[buildPicker.indexOfSelectedItem]) else { return } + guard let url = URL(string: plistOperations.readKeys()[buildPicker.indexOfSelectedItem]) else { return } CommandsController().downloadApp(from: url, textView: textView) }