From 3bde1fe4b1224e74163de5f62aac53ce14cd7659 Mon Sep 17 00:00:00 2001 From: willsunnn Date: Thu, 9 May 2019 22:04:10 -0700 Subject: [PATCH 1/6] 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 From a81d6fc595c8f9ea8aede6f2a42698b4c7008156 Mon Sep 17 00:00:00 2001 From: willsunnn Date: Thu, 9 May 2019 22:20:45 -0700 Subject: [PATCH 2/6] Made the dock resize when Apps are removed --- MTMR/Info.plist | 2 +- MTMR/Widgets/AppScrubberTouchBarItem.swift | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/MTMR/Info.plist b/MTMR/Info.plist index 71da62c..86379f7 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.20.3 CFBundleVersion - 220 + 223 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index e9fb8ac..7b28da4 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -32,6 +32,9 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub convenience override init(identifier: NSTouchBarItem.Identifier) { self.init(identifier: identifier, autoResize: false) } + + static var iconWidth = 36 + static var spacingWidth = 2 init(identifier: NSTouchBarItem.Identifier, autoResize: Bool) { super.init(identifier: identifier) @@ -42,8 +45,8 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub scrubber.dataSource = self scrubber.mode = .free // .fixed let layout = NSScrubberFlowLayout() - layout.itemSize = NSSize(width: 36, height: 32) - layout.itemSpacing = 2 + layout.itemSize = NSSize(width: AppScrubberTouchBarItem.iconWidth, height: 32) + layout.itemSpacing = CGFloat(AppScrubberTouchBarItem.spacingWidth) scrubber.scrubberLayout = layout scrubber.selectionBackgroundStyle = .roundedBackground scrubber.showsAdditionalContentIndicators = true @@ -84,10 +87,18 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub applications = newApplications applications += getDockPersistentAppsList() + updateSize() scrubber.reloadData() scrubber.selectedIndex = index ?? 0 } + + func updateSize() { + if self.autoResize { + let width = (AppScrubberTouchBarItem.iconWidth + AppScrubberTouchBarItem.spacingWidth) * self.applications.count - AppScrubberTouchBarItem.spacingWidth + self.setWidth(value: CGFloat(width)) + } + } public func numberOfItems(for _: NSScrubber) -> Int { return applications.count From 324c3f711e1614c2b772f1ee1da4068512af042a Mon Sep 17 00:00:00 2001 From: willsunnn Date: Thu, 9 May 2019 22:39:47 -0700 Subject: [PATCH 3/6] Fixed a bug where the dock would not change size after the first time due to conflicting constraints --- MTMR/Info.plist | 2 +- MTMR/Widgets/AppScrubberTouchBarItem.swift | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/MTMR/Info.plist b/MTMR/Info.plist index 86379f7..950d24c 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.20.3 CFBundleVersion - 223 + 226 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/MTMR/Widgets/AppScrubberTouchBarItem.swift b/MTMR/Widgets/AppScrubberTouchBarItem.swift index 7b28da4..7c5cd39 100644 --- a/MTMR/Widgets/AppScrubberTouchBarItem.swift +++ b/MTMR/Widgets/AppScrubberTouchBarItem.swift @@ -18,6 +18,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub private let maxTicks: Int = 20 private var lastSelected: Int = 0 private var autoResize: Bool = false + private var widthConstraint: NSLayoutConstraint? private var persistentAppIdentifiers: [String] = [] private var runningAppsIdentifiers: [String] = [] @@ -87,16 +88,21 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub applications = newApplications applications += getDockPersistentAppsList() - updateSize() scrubber.reloadData() + updateSize() scrubber.selectedIndex = index ?? 0 } func updateSize() { if self.autoResize { + if let constraint: NSLayoutConstraint = self.widthConstraint { + constraint.isActive = false + self.scrubber.removeConstraint(constraint) + } let width = (AppScrubberTouchBarItem.iconWidth + AppScrubberTouchBarItem.spacingWidth) * self.applications.count - AppScrubberTouchBarItem.spacingWidth - self.setWidth(value: CGFloat(width)) + self.widthConstraint = self.scrubber.widthAnchor.constraint(equalToConstant: CGFloat(width)) + self.widthConstraint!.isActive = true } } From 2e5db4ffa0d8a5c66223c6742d03208fb9bb09b3 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Wed, 15 May 2019 16:55:44 +0100 Subject: [PATCH 4/6] revert project settings --- MTMR.xcodeproj/project.pbxproj | 4 ++-- MTMR/Info.plist | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MTMR.xcodeproj/project.pbxproj b/MTMR.xcodeproj/project.pbxproj index 5ea5b1e..4251a02 100644 --- a/MTMR.xcodeproj/project.pbxproj +++ b/MTMR.xcodeproj/project.pbxproj @@ -283,6 +283,7 @@ 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */, 607EEA4C2087A8DA009DA5F0 /* CurrencyBarItem.swift */, B081732B213739FE005D4908 /* DnDBarItem.swift */, + 60669B4220AD8FA80074E817 /* GroupBarItem.swift */, 60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */, 60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */, B0846A742220C968000288A7 /* NetworkBarItem.swift */, @@ -292,7 +293,6 @@ 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 = P5KK92AA97; + DEVELOPMENT_TEAM = D6D8BR2QNB; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(SYSTEM_LIBRARY_DIR)/PrivateFrameworks", diff --git a/MTMR/Info.plist b/MTMR/Info.plist index 950d24c..dccd38a 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 0.20.3 CFBundleVersion - 226 + 250 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion From 57b51291359fe19b1326eb0d325be42e677b1022 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Wed, 15 May 2019 16:57:40 +0100 Subject: [PATCH 5/6] info.plist --- MTMR/Info.plist | 4 ---- 1 file changed, 4 deletions(-) diff --git a/MTMR/Info.plist b/MTMR/Info.plist index a27c2b9..ddd4823 100644 --- a/MTMR/Info.plist +++ b/MTMR/Info.plist @@ -19,11 +19,7 @@ CFBundleShortVersionString 0.20.1 CFBundleVersion -<<<<<<< HEAD 250 -======= - 185 ->>>>>>> origin/master LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion From ae469bb92a37fe731125cd37d065b71e7b5e2cd7 Mon Sep 17 00:00:00 2001 From: Toxblh Date: Wed, 15 May 2019 17:01:06 +0100 Subject: [PATCH 6/6] add Readme info --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 43341e8..6188b72 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,15 @@ To close a group, use the button: }, ``` +#### `dock` +> Dock plugin +```js +{ + "type": "dock", + "autoResize": true +}, +``` + ## Actions: - `hidKey` > https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers