mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 00:58:37 +00:00
Merge pull request #230 from ReDetection/settings-swift-5.1
Multitouch settings & swift 5.1
This commit is contained in:
commit
b155cac2b0
@ -18,6 +18,7 @@
|
||||
36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */; };
|
||||
36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */; };
|
||||
36C2ECE0207CB1B0003CDA33 /* defaultPreset.json in Resources */ = {isa = PBXBuildFile; fileRef = 36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */; };
|
||||
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FEF871235A1CFC00A0ABCE /* AppSettings.swift */; };
|
||||
4CC9FEDC22FDEA65001512EB /* AMR_ANSIEscapeHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */; };
|
||||
4CDC6E5022FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */; };
|
||||
4CFF5E5C22E623DD00BFB1EE /* YandexWeatherBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CFF5E5B22E623DD00BFB1EE /* YandexWeatherBarItem.swift */; };
|
||||
@ -94,6 +95,7 @@
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsParsing.swift; sourceTree = "<group>"; };
|
||||
36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseConfigTests.swift; sourceTree = "<group>"; };
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = defaultPreset.json; sourceTree = "<group>"; };
|
||||
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettings.swift; sourceTree = "<group>"; };
|
||||
4CC9FEDA22FDEA65001512EB /* AMR_ANSIEscapeHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AMR_ANSIEscapeHelper.h; sourceTree = "<group>"; };
|
||||
4CC9FEDB22FDEA65001512EB /* AMR_ANSIEscapeHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AMR_ANSIEscapeHelper.m; sourceTree = "<group>"; };
|
||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellScriptTouchBarItem.swift; sourceTree = "<group>"; };
|
||||
@ -225,6 +227,7 @@
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */,
|
||||
B082B252205C7D8000BC04DC /* AppDelegate.swift */,
|
||||
B0A7E9A9205D6AA400EEF070 /* KeyPress.swift */,
|
||||
36FEF871235A1CFC00A0ABCE /* AppSettings.swift */,
|
||||
B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */,
|
||||
36C2ECD8207B74B4003CDA33 /* AppleScriptTouchBarItem.swift */,
|
||||
4CDC6E4F22FCA93F0069ADD4 /* ShellScriptTouchBarItem.swift */,
|
||||
@ -474,6 +477,7 @@
|
||||
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
||||
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */,
|
||||
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */,
|
||||
36FEF872235A1CFC00A0ABCE /* AppSettings.swift in Sources */,
|
||||
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */,
|
||||
36A778BE20A6C27100B38714 /* GeneralExtensions.swift in Sources */,
|
||||
60669B4320AD8FA80074E817 /* GroupBarItem.swift in Sources */,
|
||||
|
||||
@ -42,13 +42,12 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
func applicationWillTerminate(_: Notification) {}
|
||||
|
||||
func HapticFeedbackUpdate() {
|
||||
HapticFeedback.shared = TouchBarController.shared.hapticFeedbackState ? HapticFeedback() : nil
|
||||
HapticFeedback.shared = AppSettings.hapticFeedbackState ? HapticFeedback() : nil
|
||||
}
|
||||
|
||||
@objc func updateIsBlockedApp() {
|
||||
if let frontmostAppId = TouchBarController.shared.frontmostApplicationIdentifier {
|
||||
let blacklistAppIdentifiers = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") ?? []
|
||||
isBlockedApp = blacklistAppIdentifiers.firstIndex(of: frontmostAppId) != nil
|
||||
isBlockedApp = AppSettings.blacklistedAppIds.firstIndex(of: frontmostAppId) != nil
|
||||
} else {
|
||||
isBlockedApp = false
|
||||
}
|
||||
@ -64,10 +63,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
task.launch()
|
||||
}
|
||||
|
||||
@objc func toggleControlStrip(_: Any?) {
|
||||
TouchBarController.shared.showControlStripState = !TouchBarController.shared.showControlStripState
|
||||
@objc func toggleControlStrip(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.showControlStripState = item.state == .off
|
||||
TouchBarController.shared.resetControlStrip()
|
||||
createMenu()
|
||||
}
|
||||
|
||||
@objc func toggleBlackListedApp(_: Any?) {
|
||||
@ -77,19 +76,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
} else {
|
||||
TouchBarController.shared.blacklistAppIdentifiers.append(appIdentifier)
|
||||
}
|
||||
|
||||
UserDefaults.standard.set(TouchBarController.shared.blacklistAppIdentifiers, forKey: "com.toxblh.mtmr.blackListedApps")
|
||||
UserDefaults.standard.synchronize()
|
||||
|
||||
|
||||
AppSettings.blacklistedAppIds = TouchBarController.shared.blacklistAppIdentifiers
|
||||
TouchBarController.shared.updateActiveApp()
|
||||
updateIsBlockedApp()
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleHapticFeedback(_: Any?) {
|
||||
TouchBarController.shared.hapticFeedbackState = !TouchBarController.shared.hapticFeedbackState
|
||||
@objc func toggleHapticFeedback(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.hapticFeedbackState = item.state == .on
|
||||
HapticFeedbackUpdate()
|
||||
createMenu()
|
||||
}
|
||||
|
||||
@objc func toggleMultitouch(_ item: NSMenuItem) {
|
||||
item.state = item.state == .on ? .off : .on
|
||||
AppSettings.multitouchGestures = item.state == .on
|
||||
TouchBarController.shared.scrollArea?.gesturesEnabled = item.state == .on
|
||||
}
|
||||
|
||||
@objc func openPreset(_: Any?) {
|
||||
@ -124,10 +127,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
toggleBlackList.state = isBlockedApp ? .on : .off
|
||||
|
||||
let hideControlStrip = NSMenuItem(title: "Hide Control Strip", action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
||||
hideControlStrip.state = TouchBarController.shared.showControlStripState ? .off : .on
|
||||
hideControlStrip.state = AppSettings.showControlStripState ? .off : .on
|
||||
|
||||
let hapticFeedback = NSMenuItem(title: "Haptic Feedback", action: #selector(toggleHapticFeedback(_:)), keyEquivalent: "H")
|
||||
hapticFeedback.state = TouchBarController.shared.hapticFeedbackState ? .on : .off
|
||||
hapticFeedback.state = AppSettings.hapticFeedbackState ? .on : .off
|
||||
|
||||
let multitouchGestures = NSMenuItem(title: "Volume/Brightness gestures", action: #selector(toggleMultitouch(_:)), keyEquivalent: "")
|
||||
multitouchGestures.state = AppSettings.multitouchGestures ? .on : .off
|
||||
|
||||
let settingSeparator = NSMenuItem(title: "Settings", action: nil, keyEquivalent: "")
|
||||
settingSeparator.isEnabled = false
|
||||
@ -142,6 +148,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
menu.addItem(hideControlStrip)
|
||||
menu.addItem(toggleBlackList)
|
||||
menu.addItem(startAtLogin)
|
||||
menu.addItem(multitouchGestures)
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||
statusItem.menu = menu
|
||||
|
||||
30
MTMR/AppSettings.swift
Normal file
30
MTMR/AppSettings.swift
Normal file
@ -0,0 +1,30 @@
|
||||
import Foundation
|
||||
|
||||
struct AppSettings {
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.showControlStrip", defaultValue: false)
|
||||
static var showControlStripState: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.hapticFeedback", defaultValue: true)
|
||||
static var hapticFeedbackState: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.settings.multitouchGestures", defaultValue: true)
|
||||
static var multitouchGestures: Bool
|
||||
|
||||
@UserDefault(key: "com.toxblh.mtmr.blackListedApps", defaultValue: [])
|
||||
static var blacklistedAppIds: [String]
|
||||
}
|
||||
|
||||
@propertyWrapper
|
||||
struct UserDefault<T> {
|
||||
let key: String
|
||||
let defaultValue: T
|
||||
var wrappedValue: T {
|
||||
get {
|
||||
return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: key)
|
||||
UserDefaults.standard.synchronize()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,8 @@ import Foundation
|
||||
class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||
var twofingersPrev: CGFloat = 0.0
|
||||
var threefingersPrev: CGFloat = 0.0
|
||||
var twofingers: NSPanGestureRecognizer!
|
||||
var threefingers: NSPanGestureRecognizer!
|
||||
|
||||
init(identifier: NSTouchBarItem.Identifier, items: [NSTouchBarItem]) {
|
||||
super.init(identifier: identifier)
|
||||
@ -14,16 +16,23 @@ class ScrollViewItem: NSCustomTouchBarItem, NSGestureRecognizerDelegate {
|
||||
scrollView.documentView = stackView
|
||||
view = scrollView
|
||||
|
||||
let twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||
twofingers = NSPanGestureRecognizer(target: self, action: #selector(twofingersHandler(_:)))
|
||||
twofingers.allowedTouchTypes = .direct
|
||||
twofingers.numberOfTouchesRequired = 2
|
||||
view.addGestureRecognizer(twofingers)
|
||||
|
||||
let threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||
threefingers = NSPanGestureRecognizer(target: self, action: #selector(threefingersHandler(_:)))
|
||||
threefingers.allowedTouchTypes = .direct
|
||||
threefingers.numberOfTouchesRequired = 3
|
||||
view.addGestureRecognizer(threefingers)
|
||||
}
|
||||
|
||||
var gesturesEnabled = true {
|
||||
didSet {
|
||||
twofingers.isEnabled = gesturesEnabled
|
||||
threefingers.isEnabled = gesturesEnabled
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder _: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
|
||||
@ -78,27 +78,9 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
var centerIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||
var centerItems: [NSTouchBarItem] = []
|
||||
var rightIdentifiers: [NSTouchBarItem.Identifier] = []
|
||||
var scrollArea: NSCustomTouchBarItem?
|
||||
var scrollArea: ScrollViewItem?
|
||||
var centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||
|
||||
var showControlStripState: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.showControlStrip")
|
||||
}
|
||||
}
|
||||
|
||||
var hapticFeedbackState: Bool {
|
||||
get {
|
||||
return UserDefaults.standard.bool(forKey: "com.toxblh.mtmr.settings.hapticFeedback")
|
||||
}
|
||||
set {
|
||||
UserDefaults.standard.set(newValue, forKey: "com.toxblh.mtmr.settings.hapticFeedback")
|
||||
}
|
||||
}
|
||||
|
||||
var blacklistAppIdentifiers: [String] = []
|
||||
var frontmostApplicationIdentifier: String? {
|
||||
return NSWorkspace.shared.frontmostApplication?.bundleIdentifier
|
||||
@ -115,10 +97,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}), longAction: .none, parameters: [.width: .width(30), .image: .image(source: (NSImage(named: NSImage.stopProgressFreestandingTemplateName))!)])
|
||||
}
|
||||
|
||||
if let blackListed = UserDefaults.standard.stringArray(forKey: "com.toxblh.mtmr.blackListedApps") {
|
||||
blacklistAppIdentifiers = blackListed
|
||||
}
|
||||
|
||||
blacklistAppIdentifiers = AppSettings.blacklistedAppIds
|
||||
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didLaunchApplicationNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didTerminateApplicationNotification, object: nil)
|
||||
NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(activeApplicationChanged), name: NSWorkspace.didActivateApplicationNotification, object: nil)
|
||||
@ -147,6 +127,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
|
||||
centerScrollArea = NSTouchBarItem.Identifier("com.toxblh.mtmr.scrollArea.".appending(UUID().uuidString))
|
||||
scrollArea = ScrollViewItem(identifier: centerScrollArea, items: centerItems)
|
||||
scrollArea?.gesturesEnabled = AppSettings.multitouchGestures
|
||||
|
||||
touchBar.delegate = self
|
||||
touchBar.defaultItemIdentifiers = []
|
||||
@ -223,7 +204,7 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
||||
}
|
||||
|
||||
@objc private func presentTouchBar() {
|
||||
if showControlStripState {
|
||||
if AppSettings.showControlStripState {
|
||||
updateControlStripPresence()
|
||||
presentSystemModal(touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||
} else {
|
||||
|
||||
@ -52,7 +52,7 @@ class GroupBarItem: NSPopoverTouchBarItem, NSTouchBarDelegate {
|
||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = []
|
||||
TouchBarController.shared.touchBar.defaultItemIdentifiers = leftIdentifiers + [centerScrollArea] + rightIdentifiers
|
||||
|
||||
if TouchBarController.shared.showControlStripState {
|
||||
if AppSettings.showControlStripState {
|
||||
presentSystemModal(TouchBarController.shared.touchBar, systemTrayItemIdentifier: .controlStripItem)
|
||||
} else {
|
||||
presentSystemModal(TouchBarController.shared.touchBar, placement: 1, systemTrayItemIdentifier: .controlStripItem)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user