forked from wakatime/macos-wakatime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wakatime#88 from wakatime/feature/13-older-macos-v…
…ersion-support Support older macos versions
- Loading branch information
Showing
16 changed files
with
463 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Cocoa | ||
|
||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
struct Constants { | ||
static let mainAppBundleID = "macos-wakatime.WakaTime" | ||
} | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
let runningApps = NSWorkspace.shared.runningApplications | ||
let isRunning = runningApps.contains { | ||
$0.bundleIdentifier == Constants.mainAppBundleID | ||
} | ||
|
||
if !isRunning { | ||
var path = Bundle.main.bundlePath as NSString | ||
for _ in 1...4 { | ||
path = path.deletingLastPathComponent as NSString | ||
} | ||
let fileURL = URL(fileURLWithPath: path as String) | ||
print("Opening", fileURL.absoluteString) | ||
NSWorkspace.shared.openApplication( | ||
at: fileURL, | ||
configuration: NSWorkspace.OpenConfiguration() | ||
) { _, error in | ||
if let error { | ||
print(error.localizedDescription) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>LSBackgroundOnly</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Cocoa | ||
|
||
let delegate = AppDelegate() | ||
let application = NSApplication.shared | ||
application.delegate = delegate | ||
application.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import Cocoa | ||
|
||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
var window: NSWindow! | ||
var statusBarItem: NSStatusItem! | ||
var settingsWindowController = SettingsWindowController() | ||
var monitoredAppsWindowController = MonitoredAppsWindowController() | ||
var wakaTime: WakaTime? | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
wakaTime = WakaTime() | ||
|
||
// Handle deep links | ||
let eventManager = NSAppleEventManager.shared() | ||
eventManager.setEventHandler( | ||
self, | ||
andSelector: #selector(handleGetURL(_:withReplyEvent:)), | ||
forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL) | ||
) | ||
|
||
let statusBar = NSStatusBar.system | ||
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.variableLength) | ||
statusBarItem.button?.image = NSImage(named: NSImage.Name("WakaTime")) | ||
|
||
let menu = NSMenu() | ||
|
||
menu.addItem(withTitle: "Dashboard", action: #selector(AppDelegate.dashboardClicked(_:)), keyEquivalent: "") | ||
menu.addItem(withTitle: "Settings", action: #selector(AppDelegate.settingsClicked(_:)), keyEquivalent: "") | ||
menu.addItem(withTitle: "Monitored Apps", action: #selector(AppDelegate.monitoredAppsClicked(_:)), keyEquivalent: "") | ||
menu.addItem(NSMenuItem.separator()) | ||
menu.addItem(withTitle: "Quit", action: #selector(AppDelegate.quitClicked(_:)), keyEquivalent: "") | ||
|
||
statusBarItem.menu = menu | ||
} | ||
|
||
@objc func handleGetURL(_ event: NSAppleEventDescriptor, withReplyEvent replyEvent: NSAppleEventDescriptor) { | ||
// Handle deep links | ||
guard let urlString = event.paramDescriptor(forKeyword: keyDirectObject)?.stringValue, | ||
let url = URL(string: urlString), | ||
url.scheme == "wakatime" | ||
else { return } | ||
|
||
if url.host == "settings" { | ||
showSettings() | ||
} | ||
} | ||
|
||
@objc func dashboardClicked(_ sender: AnyObject) { | ||
if let url = URL(string: "https://wakatime.com/") { | ||
NSWorkspace.shared.open(url) | ||
} | ||
} | ||
|
||
@objc func settingsClicked(_ sender: AnyObject) { | ||
showSettings() | ||
} | ||
|
||
@objc func monitoredAppsClicked(_ sender: AnyObject) { | ||
showMonitoredApps() | ||
} | ||
|
||
@objc func quitClicked(_ sender: AnyObject) { | ||
NSApplication.shared.terminate(self) | ||
} | ||
|
||
private func showSettings() { | ||
NSApp.activate(ignoringOtherApps: true) | ||
settingsWindowController.showWindow(self) | ||
} | ||
|
||
private func showMonitoredApps() { | ||
NSApp.activate(ignoringOtherApps: true) | ||
monitoredAppsWindowController.showWindow(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// WKTextField.swift | ||
// WakaTime | ||
// | ||
// Created by Tobias Lensing on 07.06.23. | ||
// | ||
|
||
import AppKit | ||
|
||
class WKTextField: NSTextField { | ||
override func performKeyEquivalent(with event: NSEvent) -> Bool { | ||
if event.type == NSEvent.EventType.keyDown { | ||
let modifierFlags = event.modifierFlags.rawValue & NSEvent.ModifierFlags.deviceIndependentFlagsMask.rawValue | ||
if modifierFlags == NSEvent.ModifierFlags.command.rawValue { | ||
switch event.charactersIgnoringModifiers?.first { | ||
case "x": | ||
if NSApp.sendAction(#selector(NSText.cut(_:)), to: nil, from: self) { return true } | ||
case "c": | ||
if NSApp.sendAction(#selector(NSText.copy(_:)), to: nil, from: self) { return true } | ||
case "v": | ||
if NSApp.sendAction(#selector(NSText.paste(_:)), to: nil, from: self) { return true } | ||
case "a": | ||
if NSApp.sendAction(#selector(NSText.selectAll(_:)), to: nil, from: self) { return true } | ||
case "z": | ||
if NSApp.sendAction(Selector(("undo:")), to: nil, from: self) { return true } | ||
default: | ||
break | ||
} | ||
} else if modifierFlags == NSEvent.ModifierFlags.command.rawValue | NSEvent.ModifierFlags.shift.rawValue { | ||
if NSApp.sendAction(Selector(("redo:")), to: nil, from: self) { return true } | ||
} | ||
} | ||
return super.performKeyEquivalent(with: event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.