1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-11 17:38:38 +00:00

Merge pull request #229 from Toxblh/ReDetection-warnings

Redetection warnings
This commit is contained in:
Serg 2019-10-18 22:06:29 +07:00 committed by GitHub
commit 0eef872f2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 63 deletions

View File

@ -1,6 +1,6 @@
language: swift language: swift
xcode_project: MTMR.xcodeproj xcode_project: MTMR.xcodeproj
xcode_scheme: UnitTests xcode_scheme: UnitTests
osx_image: xcode10 osx_image: xcode11.1
install: gem install xcpretty install: gem install xcpretty
script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}" script: "xcodebuild test -project MTMR.xcodeproj -scheme 'UnitTests' | xcpretty -c && exit ${PIPESTATUS[0]}"

View File

@ -362,7 +362,7 @@
TargetAttributes = { TargetAttributes = {
B082B24E205C7D8000BC04DC = { B082B24E205C7D8000BC04DC = {
CreatedOnToolsVersion = 9.2; CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1000; LastSwiftMigration = 1020;
ProvisioningStyle = Manual; ProvisioningStyle = Manual;
SystemCapabilities = { SystemCapabilities = {
com.apple.Sandbox = { com.apple.Sandbox = {
@ -372,7 +372,7 @@
}; };
B082B260205C7D8000BC04DC = { B082B260205C7D8000BC04DC = {
CreatedOnToolsVersion = 9.2; CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1000; LastSwiftMigration = 1020;
}; };
}; };
}; };
@ -640,7 +640,7 @@
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
SWIFT_VERSION = 4.2; SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
}; };
@ -663,7 +663,7 @@
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h"; SWIFT_OBJC_BRIDGING_HEADER = "MTMR/CBridge/TouchBarPrivateApi-Bridging.h";
SWIFT_VERSION = 4.2; SWIFT_VERSION = 5.0;
}; };
name = Release; name = Release;
}; };
@ -676,7 +676,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2; SWIFT_VERSION = 5.0;
}; };
name = Debug; name = Debug;
}; };
@ -691,7 +691,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests; PRODUCT_BUNDLE_IDENTIFIER = Toxblh.MTMRTests;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2; SWIFT_VERSION = 5.0;
}; };
name = Release; name = Release;
}; };

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict/>
<key>BuildSystemType</key>
<string>Original</string>
</dict>
</plist> </plist>

View File

@ -46,17 +46,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} }
@objc func updateIsBlockedApp() { @objc func updateIsBlockedApp() {
var blacklistAppIdentifiers: [String] = [] if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") { let blacklistAppIdentifiers = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") ?? []
blacklistAppIdentifiers = blackListed isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostAppId) != nil
}
var frontmostApplicationIdentifier: String? {
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil }
return frontmostId
}
if frontmostApplicationIdentifier != nil {
isBlockedApp = blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil
} else { } else {
isBlockedApp = false isBlockedApp = false
} }
@ -79,12 +71,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
} }
@objc func toggleBlackListedApp(_: Any?) { @objc func toggleBlackListedApp(_: Any?) {
let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier if let appIdentifier = TouchBarController.shared.frontmostApplicationIdentifier {
if appIdentifier != nil { if let index = TouchBarController.shared.blacklistAppIdentifiers.firstIndex(of: appIdentifier) {
if let index = TouchBarController.shared.blacklistAppIdentifiers.index(of: appIdentifier!) {
TouchBarController.shared.blacklistAppIdentifiers.remove(at: index) TouchBarController.shared.blacklistAppIdentifiers.remove(at: index)
} else { } else {
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier!) TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier)
} }
UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps") UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps")

View File

@ -225,7 +225,7 @@ class SupportedTypesHolder {
"inputsource": { _ in "inputsource": { _ in
( (
item: .inputsource(), item: .inputsource,
action: .none, action: .none,
longAction: .none, longAction: .none,
parameters: [:] parameters: [:]
@ -237,14 +237,14 @@ class SupportedTypesHolder {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
if var img = try container.decodeIfPresent(Source.self, forKey: .image) { if var img = try container.decodeIfPresent(Source.self, forKey: .image) {
return ( return (
item: .volume(), item: .volume,
action: .none, action: .none,
longAction: .none, longAction: .none,
parameters: [.image: .image(source: img)] parameters: [.image: .image(source: img)]
) )
} else { } else {
return ( return (
item: .volume(), item: .volume,
action: .none, action: .none,
longAction: .none, longAction: .none,
parameters: [:] parameters: [:]
@ -345,21 +345,21 @@ enum ItemType: Decodable {
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case shellScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
case timeButton(formatTemplate: String, timeZone: String?, locale: String?) case timeButton(formatTemplate: String, timeZone: String?, locale: String?)
case battery() case battery
case dock(autoResize: Bool) case dock(autoResize: Bool)
case volume() case volume
case brightness(refreshInterval: Double) case brightness(refreshInterval: Double)
case weather(interval: Double, units: String, api_key: String, icon_type: String) case weather(interval: Double, units: String, api_key: String, icon_type: String)
case yandexWeather(interval: Double) case yandexWeather(interval: Double)
case currency(interval: Double, from: String, to: String, full: Bool) case currency(interval: Double, from: String, to: String, full: Bool)
case inputsource() case inputsource
case music(interval: Double, disableMarquee: Bool) case music(interval: Double, disableMarquee: Bool)
case groupBar(items: [BarItemDefinition]) case groupBar(items: [BarItemDefinition])
case nightShift() case nightShift
case dnd() case dnd
case pomodoro(workTime: Double, restTime: Double) case pomodoro(workTime: Double, restTime: Double)
case network(flip: Bool) case network(flip: Bool)
case darkMode() case darkMode
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case type case type
@ -433,14 +433,14 @@ enum ItemType: Decodable {
self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale) self = .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale)
case .battery: case .battery:
self = .battery() self = .battery
case .dock: case .dock:
let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
self = .dock(autoResize: autoResize) self = .dock(autoResize: autoResize)
case .volume: case .volume:
self = .volume() self = .volume
case .brightness: case .brightness:
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 0.5 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) self = .currency(interval: interval, from: from, to: to, full: full)
case .inputsource: case .inputsource:
self = .inputsource() self = .inputsource
case .music: case .music:
let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0 let interval = try container.decodeIfPresent(Double.self, forKey: .refreshInterval) ?? 5.0
@ -477,10 +477,10 @@ enum ItemType: Decodable {
self = .groupBar(items: items) self = .groupBar(items: items)
case .nightShift: case .nightShift:
self = .nightShift() self = .nightShift
case .dnd: case .dnd:
self = .dnd() self = .dnd
case .pomodoro: case .pomodoro:
let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) ?? 1500.0 let workTime = try container.decodeIfPresent(Double.self, forKey: .workTime) ?? 1500.0
@ -492,7 +492,7 @@ enum ItemType: Decodable {
self = .network(flip: flip) self = .network(flip: flip)
case .darkMode: case .darkMode:
self = .darkMode() self = .darkMode
} }
} }
} }

View File

@ -27,11 +27,11 @@ extension ItemType {
return "com.toxblh.mtmr.shellScriptButton." return "com.toxblh.mtmr.shellScriptButton."
case .timeButton(formatTemplate: _, timeZone: _, locale: _): case .timeButton(formatTemplate: _, timeZone: _, locale: _):
return "com.toxblh.mtmr.timeButton." return "com.toxblh.mtmr.timeButton."
case .battery(): case .battery:
return "com.toxblh.mtmr.battery." return "com.toxblh.mtmr.battery."
case .dock(autoResize: _): case .dock(autoResize: _):
return "com.toxblh.mtmr.dock" return "com.toxblh.mtmr.dock"
case .volume(): case .volume:
return "com.toxblh.mtmr.volume" return "com.toxblh.mtmr.volume"
case .brightness(refreshInterval: _): case .brightness(refreshInterval: _):
return "com.toxblh.mtmr.brightness" return "com.toxblh.mtmr.brightness"
@ -41,21 +41,21 @@ extension ItemType {
return "com.toxblh.mtmr.yandexWeather" return "com.toxblh.mtmr.yandexWeather"
case .currency(interval: _, from: _, to: _, full: _): case .currency(interval: _, from: _, to: _, full: _):
return "com.toxblh.mtmr.currency" return "com.toxblh.mtmr.currency"
case .inputsource(): case .inputsource:
return "com.toxblh.mtmr.inputsource." return "com.toxblh.mtmr.inputsource."
case .music(interval: _): case .music(interval: _):
return "com.toxblh.mtmr.music." return "com.toxblh.mtmr.music."
case .groupBar(items: _): case .groupBar(items: _):
return "com.toxblh.mtmr.groupBar." return "com.toxblh.mtmr.groupBar."
case .nightShift(items: _): case .nightShift:
return "com.toxblh.mtmr.nightShift." return "com.toxblh.mtmr.nightShift."
case .dnd(items: _): case .dnd:
return "com.toxblh.mtmr.dnd." return "com.toxblh.mtmr.dnd."
case .pomodoro(interval: _): case .pomodoro(interval: _):
return PomodoroBarItem.identifier return PomodoroBarItem.identifier
case .network(flip: _): case .network(flip: _):
return NetworkBarItem.identifier return NetworkBarItem.identifier
case .darkMode(items: _): case .darkMode:
return DarkModeBarItem.identifier return DarkModeBarItem.identifier
} }
} }
@ -101,8 +101,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
var blacklistAppIdentifiers: [String] = [] var blacklistAppIdentifiers: [String] = []
var frontmostApplicationIdentifier: String? { var frontmostApplicationIdentifier: String? {
guard let frontmostId = NSWorkspace.shared.frontmostApplication?.bundleIdentifier else { return nil } return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
return frontmostId
} }
private override init() { private override init() {
@ -161,7 +160,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
} }
func updateActiveApp() { func updateActiveApp() {
if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.index(of: frontmostApplicationIdentifier!) != nil { if frontmostApplicationIdentifier != nil && blacklistAppIdentifiers.firstIndex(of: frontmostApplicationIdentifier!) != nil {
dismissTouchBar() dismissTouchBar()
} else { } else {
presentTouchBar() presentTouchBar()
@ -266,7 +265,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval) barItem = ShellScriptTouchBarItem(identifier: identifier, source: source, interval: interval)
case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale): case let .timeButton(formatTemplate: template, timeZone: timeZone, locale: locale):
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale) barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone, locale: locale)
case .battery(): case .battery:
barItem = BatteryBarItem(identifier: identifier) barItem = BatteryBarItem(identifier: identifier)
case let .dock(autoResize: autoResize): case let .dock(autoResize: autoResize):
barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize) barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize)
@ -288,21 +287,21 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
barItem = YandexWeatherBarItem(identifier: identifier, interval: interval) barItem = YandexWeatherBarItem(identifier: identifier, interval: interval)
case let .currency(interval: interval, from: from, to: to, full: full): case let .currency(interval: interval, from: from, to: to, full: full):
barItem = CurrencyBarItem(identifier: identifier, 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) barItem = InputSourceBarItem(identifier: identifier)
case let .music(interval: interval, disableMarquee: disableMarquee): case let .music(interval: interval, disableMarquee: disableMarquee):
barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee) barItem = MusicBarItem(identifier: identifier, interval: interval, disableMarquee: disableMarquee)
case let .groupBar(items: items): case let .groupBar(items: items):
barItem = GroupBarItem(identifier: identifier, items: items) barItem = GroupBarItem(identifier: identifier, items: items)
case .nightShift(): case .nightShift:
barItem = NightShiftBarItem(identifier: identifier) barItem = NightShiftBarItem(identifier: identifier)
case .dnd(): case .dnd:
barItem = DnDBarItem(identifier: identifier) barItem = DnDBarItem(identifier: identifier)
case let .pomodoro(workTime: workTime, restTime: restTime): case let .pomodoro(workTime: workTime, restTime: restTime):
barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime) barItem = PomodoroBarItem(identifier: identifier, workTime: workTime, restTime: restTime)
case let .network(flip: flip): case let .network(flip: flip):
barItem = NetworkBarItem(identifier: identifier, flip: flip) barItem = NetworkBarItem(identifier: identifier, flip: flip)
case .darkMode(): case .darkMode:
barItem = DarkModeBarItem(identifier: identifier) barItem = DarkModeBarItem(identifier: identifier)
} }

View File

@ -80,7 +80,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
func updateRunningApplication() { func updateRunningApplication() {
let newApplications = launchedApplications() let newApplications = launchedApplications()
let index = newApplications.index { let index = newApplications.firstIndex {
$0.bundleIdentifier == frontmostApplicationIdentifier $0.bundleIdentifier == frontmostApplicationIdentifier
} }
@ -202,7 +202,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
} }
} else { } else {
HapticFeedback.shared?.tap(strong: 6) 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) persistentAppIdentifiers.remove(at: index)
} else { } else {
persistentAppIdentifiers.append(bundleIdentifier!) persistentAppIdentifiers.append(bundleIdentifier!)

View File

@ -47,7 +47,7 @@ struct DarkMode {
static func toggle(force: Bool? = nil) { static func toggle(force: Bool? = nil) {
let value = force.map(String.init) ?? "not dark mode" let value = force.map(String.init) ?? "not dark mode"
runAppleScript("\(prefix) set dark mode to \(value)") _ = runAppleScript("\(prefix) set dark mode to \(value)")
} }
} }

View File

@ -180,7 +180,7 @@ class MusicBarItem: CustomButtonTouchBarItem {
var iconUpdated = false var iconUpdated = false
var titleUpdated = false var titleUpdated = false
for var ident in playerBundleIdentifiers { for ident in playerBundleIdentifiers {
if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) { if let musicPlayer = SBApplication(bundleIdentifier: ident.rawValue) {
if musicPlayer.isRunning { if musicPlayer.isRunning {
var tempTitle = "" var tempTitle = ""

View File

@ -31,7 +31,7 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
var dSpeed: UInt64? var dSpeed: UInt64?
var uSpeed: UInt64? var uSpeed: UInt64?
var curr: Array<Substring>? var curr: Array<Substring>?
var dataAvailable: NSObjectProtocol! var dataAvailable: NSObjectProtocol?
pipe = Pipe() pipe = Pipe()
bandwidthProcess = Process() bandwidthProcess = Process()
@ -64,19 +64,21 @@ class NetworkBarItem: CustomButtonTouchBarItem, Widget {
} }
} }
outputHandle.waitForDataInBackgroundAndNotify() outputHandle.waitForDataInBackgroundAndNotify()
} else { } else if let dataAvailable = dataAvailable {
NotificationCenter.default.removeObserver(dataAvailable) NotificationCenter.default.removeObserver(dataAvailable)
} }
} }
var dataReady: NSObjectProtocol! var dataReady: NSObjectProtocol?
dataReady = NotificationCenter.default.addObserver( dataReady = NotificationCenter.default.addObserver(
forName: Process.didTerminateNotification, forName: Process.didTerminateNotification,
object: outputHandle, object: outputHandle,
queue: nil queue: nil
) { _ -> Void in ) { _ -> Void in
print("Task terminated!") print("Task terminated!")
NotificationCenter.default.removeObserver(dataReady) if let observer = dataReady {
NotificationCenter.default.removeObserver(observer)
}
} }
bandwidthProcess?.launch() bandwidthProcess?.launch()