mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-10-31 02:18:35 +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>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>0.13</string>
|
||||
<string>0.13.1</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
@@ -12,6 +12,12 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
||||
private var scrubber: NSScrubber!
|
||||
|
||||
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 runningAppsIdentifiers: [String] = []
|
||||
@@ -25,8 +31,6 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
||||
|
||||
private var applications: [DockItem] = []
|
||||
|
||||
private var timeAtPress: NSDate?
|
||||
|
||||
override init(identifier: NSTouchBarItem.Identifier) {
|
||||
super.init(identifier: identifier)
|
||||
|
||||
@@ -35,7 +39,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
||||
scrubber.dataSource = self
|
||||
scrubber.mode = .free // .fixed
|
||||
let layout = NSScrubberFlowLayout();
|
||||
layout.itemSize = NSSize(width: 44, height: 30)
|
||||
layout.itemSize = NSSize(width: 36, height: 32)
|
||||
layout.itemSpacing = 2
|
||||
scrubber.scrubberLayout = layout
|
||||
scrubber.selectionBackgroundStyle = .roundedBackground
|
||||
@@ -94,6 +98,7 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
||||
|
||||
if let icon = app.icon {
|
||||
item.image = icon
|
||||
item.image.size = NSSize(width: 26, height: 26)
|
||||
}
|
||||
|
||||
item.removeFromSuperview()
|
||||
@@ -105,59 +110,82 @@ class AppScrubberTouchBarItem: NSCustomTouchBarItem, NSScrubberDelegate, NSScrub
|
||||
} else {
|
||||
dotView.layer?.backgroundColor = NSColor.black.cgColor
|
||||
}
|
||||
dotView.layer?.cornerRadius = 2
|
||||
dotView.setFrameOrigin(NSPoint(x: 20, y: 0))
|
||||
dotView.frame.size = NSSize(width: 4, height: 4)
|
||||
dotView.layer?.cornerRadius = 1.5
|
||||
dotView.setFrameOrigin(NSPoint(x: 17, y: 1))
|
||||
dotView.frame.size = NSSize(width: 3, height: 3)
|
||||
item.addSubview(dotView)
|
||||
|
||||
return item
|
||||
}
|
||||
|
||||
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) {
|
||||
timeAtPress = nil
|
||||
stopTimer()
|
||||
}
|
||||
|
||||
|
||||
public func didFinishInteracting(with scrubber: NSScrubber) {
|
||||
let timePressed = NSDate().timeIntervalSince(timeAtPress! as Date)
|
||||
if (timePressed > 0.5 && scrubber.selectedIndex > 0) {
|
||||
self.longPress(with: scrubber)
|
||||
stopTimer()
|
||||
|
||||
if (ticks == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
hf.tap(strong: 6)
|
||||
if (self.ticks >= minTicks && scrubber.selectedIndex > 0) {
|
||||
self.longPress(selected: scrubber.selectedIndex)
|
||||
return
|
||||
}
|
||||
|
||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
||||
if bundleIdentifier!.contains("file://") {
|
||||
NSWorkspace.shared.openFile(bundleIdentifier!.replacingOccurrences(of: "file://", with: ""))
|
||||
} else {
|
||||
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
|
||||
// "When switching to an application, switch to a Space with open windows for the application"
|
||||
// in Mission control settings
|
||||
}
|
||||
|
||||
private func longPress(with scrubber: NSScrubber) {
|
||||
let timePressed = NSDate().timeIntervalSince(timeAtPress! as Date)
|
||||
private func longPress(selected: Int) {
|
||||
let bundleIdentifier = applications[selected].bundleIdentifier
|
||||
|
||||
let bundleIdentifier = applications[scrubber.selectedIndex].bundleIdentifier
|
||||
|
||||
if (timePressed > 2.0) {
|
||||
if let processIdentifier = applications[scrubber.selectedIndex].pid {
|
||||
hf.tap(strong: 6)
|
||||
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
||||
if (self.ticks > maxTicks) {
|
||||
if let processIdentifier = applications[selected].pid {
|
||||
if !(NSRunningApplication(processIdentifier: processIdentifier)?.terminate())! {
|
||||
NSRunningApplication(processIdentifier: processIdentifier)?.forceTerminate()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
hf.tap(strong: 6)
|
||||
if let index = self.persistentAppIdentifiers.index(of: bundleIdentifier!) {
|
||||
self.persistentAppIdentifiers.remove(at: index)
|
||||
updateRunningApplication()
|
||||
} else {
|
||||
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.synchronize()
|
||||
}
|
||||
self.ticks = 0
|
||||
updateRunningApplication()
|
||||
}
|
||||
|
||||
private func launchedApplications() -> [DockItem] {
|
||||
|
||||
@@ -130,6 +130,19 @@ class BatteryInfo: NSObject {
|
||||
|
||||
title += String(current) + "%" + timeRemaining
|
||||
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
|
||||
|
||||
class CurrencyBarItem: CustomButtonTouchBarItem {
|
||||
private let activity = NSBackgroundActivityScheduler(identifier: "com.toxblh.mtmr.currency.updatecheck")
|
||||
private let activity: NSBackgroundActivityScheduler
|
||||
private var prefix: String
|
||||
private var from: 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 () -> ()) {
|
||||
activity = NSBackgroundActivityScheduler(identifier: "\(identifier.rawValue).updatecheck")
|
||||
activity.interval = interval
|
||||
self.from = from
|
||||
self.to = to
|
||||
@@ -71,7 +72,6 @@ class CurrencyBarItem: CustomButtonTouchBarItem {
|
||||
if error == nil {
|
||||
do {
|
||||
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String : AnyObject]
|
||||
// print(json)
|
||||
var value: Float32!
|
||||
|
||||
if let data_array = json["data"] as? [String : AnyObject] {
|
||||
|
||||
@@ -10,7 +10,7 @@ import Cocoa
|
||||
import CoreLocation
|
||||
|
||||
class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||
private let activity = NSBackgroundActivityScheduler(identifier: "com.toxblh.mtmr.weather.updatecheck")
|
||||
private let activity: NSBackgroundActivityScheduler
|
||||
private var units: String
|
||||
private var api_key: String
|
||||
private var units_str = "°F"
|
||||
@@ -23,6 +23,7 @@ class WeatherBarItem: CustomButtonTouchBarItem, CLLocationManagerDelegate {
|
||||
private var manager:CLLocationManager!
|
||||
|
||||
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
|
||||
self.units = units
|
||||
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/)
|
||||
|
||||
Settings:
|
||||
- [ ] Intarface for plugins and export like presets
|
||||
- [ ] Interface for plugins and export like presets
|
||||
- [ ] Startup at login
|
||||
- [ ] Show on/off in Dock
|
||||
- [ ] 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",
|
||||
```
|
||||
|
||||
## Additional paramaters:
|
||||
## Additional parameters:
|
||||
|
||||
- `width` allow to restrict how much room a particular button will take
|
||||
```json
|
||||
|
||||
Reference in New Issue
Block a user