1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 17:08:39 +00:00
This commit is contained in:
Toxblh 2019-05-22 18:26:24 +01:00
commit 64171d5c51
6 changed files with 53 additions and 16 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> <document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies> <dependencies>
<deployment identifier="macosx"/> <deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
</dependencies> </dependencies>
<scenes> <scenes>
<!--Application--> <!--Application-->
@ -619,7 +619,7 @@
<menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE"> <menuItem title="Show Sidebar" keyEquivalent="s" id="kIP-vf-haE">
<modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/> <modifierMask key="keyEquivalentModifierMask" control="YES" command="YES"/>
<connections> <connections>
<action selector="toggleSourceList:" target="Ady-hI-5gd" id="iwa-gc-5KM"/> <action selector="toggleSidebar:" target="Ady-hI-5gd" id="iwa-gc-5KM"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa"> <menuItem title="Enter Full Screen" keyEquivalent="f" id="4J7-dP-txa">

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.21</string> <string>0.21</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>207</string> <string>252</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>

View File

@ -197,9 +197,12 @@ class SupportedTypesHolder {
) )
}, },
"dock": { _ in "dock": { decoder in
( enum CodingKeys: String, CodingKey { case autoResize }
item: .dock(), 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, action: .none,
longAction: .none, longAction: .none,
parameters: [:] parameters: [:]
@ -327,7 +330,7 @@ enum ItemType: Decodable {
case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double) case appleScriptTitledButton(source: SourceProtocol, refreshInterval: Double)
case timeButton(formatTemplate: String, timeZone: String?) case timeButton(formatTemplate: String, timeZone: String?)
case battery() case battery()
case dock() 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)
@ -361,6 +364,7 @@ enum ItemType: Decodable {
case workTime case workTime
case restTime case restTime
case flip case flip
case autoResize
} }
enum ItemTypeRaw: String, Decodable { enum ItemTypeRaw: String, Decodable {
@ -405,7 +409,8 @@ enum ItemType: Decodable {
self = .battery() self = .battery()
case .dock: case .dock:
self = .dock() let autoResize = try container.decodeIfPresent(Bool.self, forKey: .autoResize) ?? false
self = .dock(autoResize: autoResize)
case .volume: case .volume:
self = .volume() self = .volume()

View File

@ -27,7 +27,7 @@ extension ItemType {
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(): 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"
@ -253,8 +253,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone) barItem = TimeTouchBarItem(identifier: identifier, formatTemplate: template, timeZone: timeZone)
case .battery(): case .battery():
barItem = BatteryBarItem(identifier: identifier) barItem = BatteryBarItem(identifier: identifier)
case .dock: case let .dock(autoResize: autoResize):
barItem = AppScrubberTouchBarItem(identifier: identifier) barItem = AppScrubberTouchBarItem(identifier: identifier, autoResize: autoResize)
case .volume: case .volume:
if case let .image(source)? = item.additionalParameters[.image] { if case let .image(source)? = item.additionalParameters[.image] {
barItem = VolumeViewController(identifier: identifier, image: source.image) barItem = VolumeViewController(identifier: identifier, image: source.image)

View File

@ -17,6 +17,8 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
private let minTicks: Int = 5 private let minTicks: Int = 5
private let maxTicks: Int = 20 private let maxTicks: Int = 20
private var lastSelected: Int = 0 private var lastSelected: Int = 0
private var autoResize: Bool = false
private var widthConstraint: NSLayoutConstraint?
private var persistentAppIdentifiers: [String] = [] private var persistentAppIdentifiers: [String] = []
private var runningAppsIdentifiers: [String] = [] private var runningAppsIdentifiers: [String] = []
@ -27,17 +29,25 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
} }
private var applications: [DockItem] = [] private var applications: [DockItem] = []
convenience override init(identifier: NSTouchBarItem.Identifier) {
self.init(identifier: identifier, autoResize: false)
}
static var iconWidth = 36
static var spacingWidth = 2
override init(identifier: NSTouchBarItem.Identifier) { init(identifier: NSTouchBarItem.Identifier, autoResize: Bool) {
super.init(identifier: identifier) super.init(identifier: identifier)
self.autoResize = autoResize
scrubber = NSScrubber() scrubber = NSScrubber()
scrubber.delegate = self scrubber.delegate = self
scrubber.dataSource = self scrubber.dataSource = self
scrubber.mode = .free // .fixed scrubber.mode = .free // .fixed
let layout = NSScrubberFlowLayout() let layout = NSScrubberFlowLayout()
layout.itemSize = NSSize(width: 36, height: 32) layout.itemSize = NSSize(width: AppScrubberTouchBarItem.iconWidth, height: 32)
layout.itemSpacing = 2 layout.itemSpacing = CGFloat(AppScrubberTouchBarItem.spacingWidth)
scrubber.scrubberLayout = layout scrubber.scrubberLayout = layout
scrubber.selectionBackgroundStyle = .roundedBackground scrubber.selectionBackgroundStyle = .roundedBackground
scrubber.showsAdditionalContentIndicators = true scrubber.showsAdditionalContentIndicators = true
@ -79,9 +89,22 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
applications = newApplications applications = newApplications
applications += getDockPersistentAppsList() applications += getDockPersistentAppsList()
scrubber.reloadData() scrubber.reloadData()
updateSize()
scrubber.selectedIndex = index ?? 0 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.widthConstraint = self.scrubber.widthAnchor.constraint(equalToConstant: CGFloat(width))
self.widthConstraint!.isActive = true
}
}
public func numberOfItems(for _: NSScrubber) -> Int { public func numberOfItems(for _: NSScrubber) -> Int {
return applications.count return applications.count

View File

@ -200,6 +200,15 @@ To close a group, use the button:
}, },
``` ```
#### `dock`
> Dock plugin
```js
{
"type": "dock",
"autoResize": true
},
```
## Actions: ## Actions:
- `hidKey` - `hidKey`
> https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers > https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers