From 3bde1fe4b1224e74163de5f62aac53ce14cd7659 Mon Sep 17 00:00:00 2001 From: willsunnn Date: Thu, 9 May 2019 22:04:10 -0700 Subject: [PATCH] Created and passed the autoResize parameter to the dock widget --- MTMR.xcodeproj/project.pbxproj | 4 ++-- MTMR/Base.lproj/Main.storyboard | 6 +++--- MTMR/Info.plist | 2 +- MTMR/ItemsParsing.swift | 15 ++++++++++----- MTMR/TouchBarController.swift | 6 +++--- MTMR/Widgets/AppScrubberTouchBarItem.swift | 10 ++++++++-- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index 4251a02..5ea5b1e 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -283,7 +283,6 @@ 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */, 607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */, B081732B213739FE005D4908 /* DnDBarItem.swift */, - 60669B4220AD8FA80074E817 /* GroupBarItem.swift */, 60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */, 60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */, B0846A742220C968000288A7 /* NetworkBarItem.swift */, @@ -293,6 +292,7 @@ 6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */, 607EEA4A2087835F009DA5F0 /* WeatherBarItem.swift */, B08126F0217BE19000A98970 /* WidgetProtocol.swift */, + 60669B4220AD8FA80074E817 /* GroupBarItem.swift */, ); path = Widgets; sourceTree = ""; @@ -633,7 +633,7 @@ CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - DEVELOPMENT_TEAM = D6D8BR2QNB; + DEVELOPMENT_TEAM = P5KK92AA97; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", diff --git a/MTMR/Base.lproj/Main.storyboard b/MTMR/Base.lproj/Main.storyboard index 925123a..3f295b2 100644 --- a/MTMR/Base.lproj/Main.storyboard +++ b/MTMR/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + @@ -619,7 +619,7 @@ - + diff --git a/MTMR/Info.plist b/MTMR/Info.plist index df5f206..71da62c 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.20.3 CFBundleVersion - 201 + 220 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/ItemsParsing.swift b/MTMR/ItemsParsing.swift index 01095de..0adf2a5 100644 --- a/MTMR/ItemsParsing.swift +++ b/MTMR/ItemsParsing.swift @@ -197,9 +197,12 @@ class SupportedTypesHolder { ) }, - "dock": { _ in - ( - item: .dock(), + "dock": { decoder in + enum CodingKeys: String, CodingKey { case autoResize } + let container = try decoder.container(keyedBy: CodingKeys.self) + let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false + return ( + item: .dock(autoResize: autoResize), action: .none, longAction: .none, parameters: [:] @@ -327,7 +330,7 @@ enum ItemType: Decodable { case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case timeButton(formatTemplate: String, timeZone: String?) case battery() - case dock() + case dock(autoResize: Bool) case volume() case brightness(refreshInterval: Double) case weather(interval: Double, units: String, api_key: String, icon_type: String) @@ -360,6 +363,7 @@ enum ItemType: Decodable { case workTime case restTime case flip + case autoResize } enum ItemTypeRaw: String, Decodable { @@ -403,7 +407,8 @@ enum ItemType: Decodable { self = .battery() case .dock: - self = .dock() + let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false + self = .dock(autoResize: autoResize) case .volume: self = .volume() diff --git a/MTMR/TouchBarController.swift b/MTMR/TouchBarController.swift index 43776a9..1384a81 100644 --- a/MTMR/TouchBarController.swift +++ b/MTMR/TouchBarController.swift @@ -27,7 +27,7 @@ extension ItemType { return "com.toxblh.mtmr.timeButton." case .battery(): return "com.toxblh.mtmr.battery." - case .dock(): + case .dock(autoResize: _): return "com.toxblh.mtmr.dock" case .volume(): return "com.toxblh.mtmr.volume" @@ -251,8 +251,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate { barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone) case .battery(): barItem = BatteryBarItem(identifier: identifier) - case .dock: - barItem = AppScrubberTouchBarItem(identifier: identifier) + case let .dock(autoResize: autoResize): + barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize) case .volume: if case let .image(source)? = item.additionalParameters[.image] { barItem = VolumeViewController(identifier: identifier, image: source.image) diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index 8d15966..e9fb8ac 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -17,6 +17,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub private let minTicks: Int = 5 private let maxTicks: Int = 20 private var lastSelected: Int = 0 + private var autoResize: Bool = false private var persistentAppIdentifiers: [String] = [] private var runningAppsIdentifiers: [String] = [] @@ -27,10 +28,15 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub } private var applications: [DockItem] = [] + + convenience override init(identifier: NSTouchBarItem.Identifier) { + self.init(identifier: identifier, autoResize: false) + } - override init(identifier: NSTouchBarItem.Identifier) { + init(identifier: NSTouchBarItem.Identifier, autoResize: Bool) { super.init(identifier: identifier) - + self.autoResize = autoResize + scrubber = NSScrubber() scrubber.delegate = self scrubber.dataSource = self