mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-11-01 11:08:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b8ef1cd96 | ||
|
|
e65c57dbaa | ||
|
|
babc8451e0 | ||
|
|
7698ea1c8e | ||
|
|
aa95d1a1bd | ||
|
|
3fe6c22068 | ||
|
|
5ab19ee27b | ||
|
|
ae4b0aa870 | ||
|
|
1e2043ebda | ||
|
|
409b8d8b46 | ||
|
|
8bccbf3834 |
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.13</string>
|
<string>0.13.1</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>1</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
|
|
||||||
private let hf: HapticFeedback = HapticFeedback()
|
private let hf: HapticFeedback = HapticFeedback()
|
||||||
|
|
||||||
|
private var timer: Timer!
|
||||||
|
private var ticks: Int = 0
|
||||||
|
private let minTicks: Int = 5
|
||||||
|
private let maxTicks: Int = 20
|
||||||
|
private var lastSelected: Int = 0
|
||||||
|
|
||||||
private var persistentAppIdentifiers: [String] = []
|
private var persistentAppIdentifiers: [String] = []
|
||||||
private var runningAppsIdentifiers: [String] = []
|
private var runningAppsIdentifiers: [String] = []
|
||||||
|
|
||||||
@@ -25,8 +31,6 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
|
|
||||||
private var applications: [DockItem] = []
|
private var applications: [DockItem] = []
|
||||||
|
|
||||||
private var timeAtPress: NSDate?
|
|
||||||
|
|
||||||
override init(identifier: NSTouchBarItem.Identifier) {
|
override init(identifier: NSTouchBarItem.Identifier) {
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
|
||||||
@@ -35,7 +39,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
scrubber.dataSource = self
|
scrubber.dataSource = self
|
||||||
scrubber.mode = .free // .fixed
|
scrubber.mode = .free // .fixed
|
||||||
let layout = NSScrubberFlowLayout();
|
let layout = NSScrubberFlowLayout();
|
||||||
layout.itemSize = NSSize(width: 44, height: 30)
|
layout.itemSize = NSSize(width: 36, height: 32)
|
||||||
layout.itemSpacing = 2
|
layout.itemSpacing = 2
|
||||||
scrubber.scrubberLayout = layout
|
scrubber.scrubberLayout = layout
|
||||||
scrubber.selectionBackgroundStyle = .roundedBackground
|
scrubber.selectionBackgroundStyle = .roundedBackground
|
||||||
@@ -94,6 +98,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
|
|
||||||
if let icon = app.icon {
|
if let icon = app.icon {
|
||||||
item.image = icon
|
item.image = icon
|
||||||
|
item.image.size = NSSize(width: 26, height: 26)
|
||||||
}
|
}
|
||||||
|
|
||||||
item.removeFromSuperview()
|
item.removeFromSuperview()
|
||||||
@@ -105,59 +110,82 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
} else {
|
} else {
|
||||||
dotView.layer?.backgroundColor = NSColor.black.cgColor
|
dotView.layer?.backgroundColor = NSColor.black.cgColor
|
||||||
}
|
}
|
||||||
dotView.layer?.cornerRadius = 2
|
dotView.layer?.cornerRadius = 1.5
|
||||||
dotView.setFrameOrigin(NSPoint(x: 20, y: 0))
|
dotView.setFrameOrigin(NSPoint(x: 17, y: 1))
|
||||||
dotView.frame.size = NSSize(width: 4, height: 4)
|
dotView.frame.size = NSSize(width: 3, height: 3)
|
||||||
item.addSubview(dotView)
|
item.addSubview(dotView)
|
||||||
|
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
public func didBeginInteracting(with scrubber: NSScrubber) {
|
public func didBeginInteracting(with scrubber: NSScrubber) {
|
||||||
timeAtPress = NSDate()
|
stopTimer()
|
||||||
|
self.ticks = 0
|
||||||
|
self.timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(checkTimer), userInfo: nil, repeats: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func checkTimer() {
|
||||||
|
self.ticks += 1
|
||||||
|
|
||||||
|
if (self.ticks == minTicks) {
|
||||||
|
hf.tap(strong: 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.ticks > maxTicks) {
|
||||||
|
stopTimer()
|
||||||
|
hf.tap(strong: 6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopTimer() {
|
||||||
|
self.timer?.invalidate()
|
||||||
|
self.timer = nil
|
||||||
|
self.lastSelected = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
public func didCancelInteracting(with scrubber: NSScrubber) {
|
public func didCancelInteracting(with scrubber: NSScrubber) {
|
||||||
timeAtPress = nil
|
stopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public func didFinishInteracting(with scrubber: NSScrubber) {
|
public func didFinishInteracting(with scrubber: NSScrubber) {
|
||||||
let timePressed = NSDate().timeIntervalSince(timeAtPress! as Date)
|
stopTimer()
|
||||||
if (timePressed > 0.5 && scrubber.selectedIndex > 0) {
|
|
||||||
self.longPress(with: scrubber)
|
if (ticks == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hf.tap(strong: 6)
|
if (self.ticks >= minTicks && scrubber.selectedIndex > 0) {
|
||||||
|
self.longPress(selected: scrubber.selectedIndex)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
||||||
if bundleIdentifier!.contains("file://") {
|
if bundleIdentifier!.contains("file://") {
|
||||||
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
||||||
} else {
|
} else {
|
||||||
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
NSWorkspace.shared.launchApplication(withBundleIdentifier: bundleIdentifier!, options: [.default], additionalEventParamDescriptor: nil, launchIdentifier: nil)
|
||||||
|
hf.tap(strong: 6)
|
||||||
}
|
}
|
||||||
|
updateRunningApplication()
|
||||||
|
|
||||||
// NB: if you can't open app which on another space, try to check mark
|
// NB: if you can't open app which on another space, try to check mark
|
||||||
// "When switching to an application, switch to a Space with open windows for the application"
|
// "When switching to an application, switch to a Space with open windows for the application"
|
||||||
// in Mission control settings
|
// in Mission control settings
|
||||||
}
|
}
|
||||||
|
|
||||||
private func longPress(with scrubber: NSScrubber) {
|
private func longPress(selected: Int) {
|
||||||
let timePressed = NSDate().timeIntervalSince(timeAtPress! as Date)
|
let bundleIdentifier = applications[selected].bundleIdentifier
|
||||||
|
|
||||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
if (self.ticks > maxTicks) {
|
||||||
|
if let processIdentifier = applications[selected].pid {
|
||||||
if (timePressed > 2.0) {
|
if !(NSRunningApplication(processIdentifier: processIdentifier)?.terminate())! {
|
||||||
if let processIdentifier = applications[scrubber.selectedIndex].pid {
|
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
||||||
hf.tap(strong: 6)
|
}
|
||||||
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hf.tap(strong: 6)
|
hf.tap(strong: 6)
|
||||||
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
|
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
|
||||||
self.persistentAppIdentifiers.remove(at: index)
|
self.persistentAppIdentifiers.remove(at: index)
|
||||||
updateRunningApplication()
|
|
||||||
} else {
|
} else {
|
||||||
self.persistentAppIdentifiers.append(bundleIdentifier!)
|
self.persistentAppIdentifiers.append(bundleIdentifier!)
|
||||||
}
|
}
|
||||||
@@ -165,6 +193,8 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
|||||||
UserDefaults.standard.set(self.persistentAppIdentifiers, forKey: "com.toxblh.mtmr.dock.persistent")
|
UserDefaults.standard.set(self.persistentAppIdentifiers, forKey: "com.toxblh.mtmr.dock.persistent")
|
||||||
UserDefaults.standard.synchronize()
|
UserDefaults.standard.synchronize()
|
||||||
}
|
}
|
||||||
|
self.ticks = 0
|
||||||
|
updateRunningApplication()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func launchedApplications() -> [DockItem] {
|
private func launchedApplications() -> [DockItem] {
|
||||||
|
|||||||
@@ -130,6 +130,19 @@ class BatteryInfo: NSObject {
|
|||||||
|
|
||||||
title += String(current) + "%" + timeRemaining
|
title += String(current) + "%" + timeRemaining
|
||||||
button?.title = title
|
button?.title = title
|
||||||
|
|
||||||
|
if current < 10 && ACPower != "AC Power" {
|
||||||
|
let pstyle = NSMutableParagraphStyle()
|
||||||
|
pstyle.alignment = .center
|
||||||
|
|
||||||
|
button?.attributedTitle = NSMutableAttributedString(
|
||||||
|
string: title,
|
||||||
|
attributes: [
|
||||||
|
NSAttributedStringKey.foregroundColor: NSColor.red,
|
||||||
|
NSAttributedStringKey.paragraphStyle: pstyle,
|
||||||
|
NSAttributedStringKey.font: NSFont.systemFont(ofSize: 16)
|
||||||
|
])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Cocoa
|
|||||||
import CoreLocation
|
import CoreLocation
|
||||||
|
|
||||||
class CurrencyBarItem: CustomButtonTouchBarItem {
|
class CurrencyBarItem: CustomButtonTouchBarItem {
|
||||||
private let activity = NSBackgroundActivityScheduler(identifier: "com.toxblh.mtmr.currency.updatecheck")
|
private let activity: NSBackgroundActivityScheduler
|
||||||
private var prefix: String
|
private var prefix: String
|
||||||
private var from: String
|
private var from: String
|
||||||
private var to: String
|
private var to: String
|
||||||
@@ -37,6 +37,7 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
]
|
]
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, onTap: @escaping () -> (), onLongTap: @escaping () -> ()) {
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, from: String, to: String, onTap: @escaping () -> (), onLongTap: @escaping () -> ()) {
|
||||||
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||||
activity.interval = interval
|
activity.interval = interval
|
||||||
self.from = from
|
self.from = from
|
||||||
self.to = to
|
self.to = to
|
||||||
@@ -71,7 +72,6 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
|||||||
if error == nil {
|
if error == nil {
|
||||||
do {
|
do {
|
||||||
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
|
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
|
||||||
// print(json)
|
|
||||||
var value: Float32!
|
var value: Float32!
|
||||||
|
|
||||||
if let data_array = json["data"] as? [String : AnyObject] {
|
if let data_array = json["data"] as? [String : AnyObject] {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Cocoa
|
|||||||
import CoreLocation
|
import CoreLocation
|
||||||
|
|
||||||
class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||||
private let activity = NSBackgroundActivityScheduler(identifier: "com.toxblh.mtmr.weather.updatecheck")
|
private let activity: NSBackgroundActivityScheduler
|
||||||
private var units: String
|
private var units: String
|
||||||
private var api_key: String
|
private var api_key: String
|
||||||
private var units_str = "°F"
|
private var units_str = "°F"
|
||||||
@@ -23,6 +23,7 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
|||||||
private var manager:CLLocationManager!
|
private var manager:CLLocationManager!
|
||||||
|
|
||||||
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, units: String, api_key: String, icon_type: String? = "text", onTap: @escaping () -> (), onLongTap: @escaping () -> ()) {
|
init(identifier: NSTouchBarItem.Identifier, interval: TimeInterval, units: String, api_key: String, icon_type: String? = "text", onTap: @escaping () -> (), onLongTap: @escaping () -> ()) {
|
||||||
|
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||||
activity.interval = interval
|
activity.interval = interval
|
||||||
self.units = units
|
self.units = units
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ My the idea is to create the program like a platform for plugins for customizati
|
|||||||
- [ ] System for autoupdate (maybe https://sparkle-project.org/)
|
- [ ] System for autoupdate (maybe https://sparkle-project.org/)
|
||||||
|
|
||||||
Settings:
|
Settings:
|
||||||
- [ ] Intarface for plugins and export like presets
|
- [ ] Interface for plugins and export like presets
|
||||||
- [ ] Startup at login
|
- [ ] Startup at login
|
||||||
- [ ] Show on/off in Dock
|
- [ ] Show on/off in Dock
|
||||||
- [ ] Show on/off in StatusBar
|
- [ ] Show on/off in StatusBar
|
||||||
@@ -167,7 +167,7 @@ File for customize your preset for MTMR: `open ~/Library/Application\ Support/MT
|
|||||||
"url": "https://google.com",
|
"url": "https://google.com",
|
||||||
```
|
```
|
||||||
|
|
||||||
## Additional paramaters:
|
## Additional parameters:
|
||||||
|
|
||||||
- `width` allow to restrict how much room a particular button will take
|
- `width` allow to restrict how much room a particular button will take
|
||||||
```json
|
```json
|
||||||
|
|||||||
Reference in New Issue
Block a user