From 92975cb8e4dbd8ad262d9e907e53f7d71d5e1c6b Mon Sep 17 00:00:00 2001 From: Serg Date: Sun, 13 Oct 2019 13:48:04 +0700 Subject: [PATCH 1/6] resolve existing varnings --- MTMR/ItemsParsing.swift | 30 +++++++++++++++--------------- MTMR/TouchBarController.swift | 22 +++++++++++----------- MTMR/Widgets/DarkModeBarItem.swift | 2 +- MTMR/Widgets/MusicBarItem.swift | 2 +- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index ac888da..ac43767 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -225,7 +225,7 @@ class SupportedTypesHolder { "inputsource": { _ in ( - item: .inputsource(), + item: .inputsource, action: .none, longAction: .none, parameters: [:] @@ -237,14 +237,14 @@ class SupportedTypesHolder { let container = try decoder.container(keyedBy: CodingKeys.self) if var img = try container.decodeIfPresent(Source.self, forKey: .image) { return ( - item: .volume(), + item: .volume, action: .none, longAction: .none, parameters: [.image: .image(source: img)] ) } else { return ( - item: .volume(), + item: .volume, action: .none, longAction: .none, parameters: [:] @@ -345,21 +345,21 @@ enum ItemType: Decodable { case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case timeButton(formatTemplate: String, timeZone: String?, locale: String?) - case battery() + case battery case dock(autoResize: Bool) - case volume() + case volume case brightness(refreshInterval: Double) case weather(interval: Double, units: String, api_key: String, icon_type: String) case yandexWeather(interval: Double) case currency(interval: Double, from: String, to: String, full: Bool) - case inputsource() + case inputsource case music(interval: Double, disableMarquee: Bool) case groupBar(items: [BarItemDefinition]) - case nightShift() - case dnd() + case nightShift + case dnd case pomodoro(workTime: Double, restTime: Double) case network(flip: Bool) - case darkMode() + case darkMode private enum CodingKeys: String, CodingKey { case type @@ -433,14 +433,14 @@ enum ItemType: Decodable { self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale) case .battery: - self = .battery() + self = .battery case .dock: let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false self = .dock(autoResize: autoResize) case .volume: - self = .volume() + self = .volume case .brightness: let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 0.5 @@ -465,7 +465,7 @@ enum ItemType: Decodable { self = .currency(interval: interval, from: from, to: to, full: full) case .inputsource: - self = .inputsource() + self = .inputsource case .music: let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0 @@ -477,10 +477,10 @@ enum ItemType: Decodable { self = .groupBar(items: items) case .nightShift: - self = .nightShift() + self = .nightShift case .dnd: - self = .dnd() + self = .dnd case .pomodoro: let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) ?? 1500.0 @@ -492,7 +492,7 @@ enum ItemType: Decodable { self = .network(flip: flip) case .darkMode: - self = .darkMode() + self = .darkMode } } } diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 7e38e39..0900052 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -27,11 +27,11 @@ extension ItemType { return "com.toxblh.mtmr.shellScriptButton." case .timeButton(formatTemplate: _, timeZone: _, locale: _): return "com.toxblh.mtmr.timeButton." - case .battery(): + case .battery: return "com.toxblh.mtmr.battery." case .dock(autoResize: _): return "com.toxblh.mtmr.dock" - case .volume(): + case .volume: return "com.toxblh.mtmr.volume" case .brightness(refreshInterval: _): return "com.toxblh.mtmr.brightness" @@ -41,21 +41,21 @@ extension ItemType { return "com.toxblh.mtmr.yandexWeather" case .currency(interval: _, from: _, to: _, full: _): return "com.toxblh.mtmr.currency" - case .inputsource(): + case .inputsource: return "com.toxblh.mtmr.inputsource." case .music(interval: _): return "com.toxblh.mtmr.music." case .groupBar(items: _): return "com.toxblh.mtmr.groupBar." - case .nightShift(items: _): + case .nightShift: return "com.toxblh.mtmr.nightShift." - case .dnd(items: _): + case .dnd: return "com.toxblh.mtmr.dnd." case .pomodoro(interval: _): return PomodoroBarItem.identifier case .network(flip: _): return NetworkBarItem.identifier - case .darkMode(items: _): + case .darkMode: return DarkModeBarItem.identifier } } @@ -266,7 +266,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval) case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale): barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale) - case .battery(): + case .battery: barItem = BatteryBarItem(identifier: identifier) case let .dock(autoResize: autoResize): barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize) @@ -288,21 +288,21 @@ class TouchBarController: NSObject, NSTouchBarDelegate { barItem = YandexWeatherBarItem(identifier: identifier, interval: interval) case let .currency(interval: interval, from: from, to: to, full: full): barItem = CurrencyBarItem(identifier: identifier, interval: interval, from: from, to: to, full: full) - case .inputsource(): + case .inputsource: barItem = InputSourceBarItem(identifier: identifier) case let .music(interval: interval, disableMarquee: disableMarquee): barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee) case let .groupBar(items: items): barItem = GroupBarItem(identifier: identifier, items: items) - case .nightShift(): + case .nightShift: barItem = NightShiftBarItem(identifier: identifier) - case .dnd(): + case .dnd: barItem = DnDBarItem(identifier: identifier) case let .pomodoro(workTime: workTime, restTime: restTime): barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime) case let .network(flip: flip): barItem = NetworkBarItem(identifier: identifier, flip: flip) - case .darkMode(): + case .darkMode: barItem = DarkModeBarItem(identifier: identifier) } diff --git a/MTMR/Widgets/DarkModeBarItem.swift b/MTMR/Widgets/DarkModeBarItem.swift index 60fecb6..ceaba78 100644 --- a/MTMR/Widgets/DarkModeBarItem.swift +++ b/MTMR/Widgets/DarkModeBarItem.swift @@ -47,7 +47,7 @@ struct DarkMode { static func toggle(force: Bool? = nil) { let value = force.map(String.init) ?? "not dark mode" - runAppleScript("\(prefix) set dark mode to \(value)") + _ = runAppleScript("\(prefix) set dark mode to \(value)") } } diff --git a/MTMR/Widgets/MusicBarItem.swift b/MTMR/Widgets/MusicBarItem.swift index 28a82b2..5bc8e7b 100644 --- a/MTMR/Widgets/MusicBarItem.swift +++ b/MTMR/Widgets/MusicBarItem.swift @@ -180,7 +180,7 @@ class MusicBarItem: CustomButtonTouchBarItem { var iconUpdated = false var titleUpdated = false - for var ident in playerBundleIdentifiers { + for ident in playerBundleIdentifiers { if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) { if musicPlayer.isRunning { var tempTitle = "" From e68fa10c429ee65f549d61f4c4d7fa0e3956d171 Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 17 Oct 2019 23:23:24 +0700 Subject: [PATCH 2/6] update swift to 5.0 --- MTMR.xcodeproj/project.pbxproj | 12 ++++++------ MTMR/AppDelegate.swift | 4 ++-- MTMR/TouchBarController.swift | 2 +- MTMR/Widgets/AppScrubberTouchBarItem.swift | 4 ++-- MTMR/Widgets/NetworkBarItem.swift | 10 ++++++---- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index 603b705..c5b31ff 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -362,7 +362,7 @@ TargetAttributes = { B082B24E205C7D8000BC04DC = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; SystemCapabilities = { com.apple.Sandbox = { @@ -372,7 +372,7 @@ }; B082B260205C7D8000BC04DC = { CreatedOnToolsVersion = 9.2; - LastSwiftMigration = 1000; + LastSwiftMigration = 1020; }; }; }; @@ -640,7 +640,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -663,7 +663,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -676,7 +676,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -691,7 +691,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index 08932de..0c9c060 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -56,7 +56,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { } if frontmostApplicationIdentifier != nil { - isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil + isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil } else { isBlockedApp = false } @@ -81,7 +81,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { @objc func toggleBlackListedApp(_: Any?) { let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier if appIdentifier != nil { - if let index = TouchBarController.shared.blacklistAppIdentifiers.index(of: appIdentifier!) { + if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier!) { TouchBarController.shared.blacklistAppIdentifiers.remove(at: index) } else { TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!) diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 0900052..a56e8c9 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -161,7 +161,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { } func updateActiveApp() { - if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil { + if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil { dismissTouchBar() } else { presentTouchBar() diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index 51043da..0466be7 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -80,7 +80,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub func updateRunningApplication() { let newApplications = launchedApplications() - let index = newApplications.index { + let index = newApplications.firstIndex { $0.bundleIdentifier == frontmostApplicationIdentifier } @@ -202,7 +202,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub } } else { HapticFeedback.shared?.tap(strong: 6) - if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) { + if let index = self.persistentAppIdentifiers.firstIndex(of: bundleIdentifier!) { persistentAppIdentifiers.remove(at: index) } else { persistentAppIdentifiers.append(bundleIdentifier!) diff --git a/MTMR/Widgets/NetworkBarItem.swift b/MTMR/Widgets/NetworkBarItem.swift index 21c5820..57de0bf 100644 --- a/MTMR/Widgets/NetworkBarItem.swift +++ b/MTMR/Widgets/NetworkBarItem.swift @@ -31,7 +31,7 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget { var dSpeed: UInt64? var uSpeed: UInt64? var curr: Array? - var dataAvailable: NSObjectProtocol! + var dataAvailable: NSObjectProtocol? pipe = Pipe() bandwidthProcess = Process() @@ -64,19 +64,21 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget { } } outputHandle.waitForDataInBackgroundAndNotify() - } else { + } else if let dataAvailable = dataAvailable { NotificationCenter.default.removeObserver(dataAvailable) } } - var dataReady: NSObjectProtocol! + var dataReady: NSObjectProtocol? dataReady = NotificationCenter.default.addObserver( forName: Process.didTerminateNotification, object: outputHandle, queue: nil ) { _ -> Void in print("Task terminated!") - NotificationCenter.default.removeObserver(dataReady) + if let observer = dataReady { + NotificationCenter.default.removeObserver(observer) + } } bandwidthProcess?.launch() From 2635e2611f011addd277e3a1fb7f1b00645ee8ff Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 17 Oct 2019 23:40:41 +0700 Subject: [PATCH 3/6] switch to modern build system --- .../xcshareddata/WorkspaceSettings.xcsettings | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/MTMR.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/MTMR.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings index 949b678..0c67376 100644 --- a/MTMR.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +++ b/MTMR.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -1,8 +1,5 @@ - - BuildSystemType - Original - + From 820853d300427eb86d63509e02ce11c28ed4237d Mon Sep 17 00:00:00 2001 From: Serg Date: Thu, 17 Oct 2019 23:58:23 +0700 Subject: [PATCH 4/6] little cleanup --- MTMR/AppDelegate.swift | 21 ++++++--------------- MTMR/TouchBarController.swift | 3 +-- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/MTMR/AppDelegate.swift b/MTMR/AppDelegate.swift index 0c9c060..5a3d4ee 100644 --- a/MTMR/AppDelegate.swift +++ b/MTMR/AppDelegate.swift @@ -46,17 +46,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @objc func updateIsBlockedApp() { - var blacklistAppIdentifiers: [String] = [] - if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { - blacklistAppIdentifiers = blackListed - } - var frontmostApplicationIdentifier: String? { - guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil } - return frontmostId - } - - if frontmostApplicationIdentifier != nil { - isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil + if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier { + let blacklistAppIdentifiers = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") ?? [] + isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostAppId) != nil } else { isBlockedApp = false } @@ -79,12 +71,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { } @objc func toggleBlackListedApp(_: Any?) { - let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier - if appIdentifier != nil { - if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier!) { + if let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier { + if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier) { TouchBarController.shared.blacklistAppIdentifiers.remove(at: index) } else { - TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!) + TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier) } UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps") diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index a56e8c9..28b9d5e 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -101,8 +101,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate { var blacklistAppIdentifiers: [String] = [] var frontmostApplicationIdentifier: String? { - guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil } - return frontmostId + return NSWorkspace.shared.frontmostApplication?.bundleIdentifier } private override init() { From f2e6959b71625e98eba83b0a1b75edf31efef4c3 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Thu, 17 Oct 2019 18:27:44 +0100 Subject: [PATCH 5/6] upd travis-ci 10 to 11.2 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 30b542e..c0870c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: swift xcode_project: MTMR.xcodeproj xcode_scheme: UnitTests -osx_image: xcode10 +osx_image: xcode11.2 install: gem install xcpretty script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}" From 3f78bbe42c47f30c98522bf03ca27f5336a324d7 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Fri, 18 Oct 2019 12:18:50 +0100 Subject: [PATCH 6/6] CI osx_image 11.2 -> 11.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c0870c1..8fd2c35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: swift xcode_project: MTMR.xcodeproj xcode_scheme: UnitTests -osx_image: xcode11.2 +osx_image: xcode11.1 install: gem install xcpretty script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}"