forked from quoid/userscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
50 lines (42 loc) · 1.9 KB
/
Copy pathAppDelegate.swift
File metadata and controls
50 lines (42 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private var window: NSWindow!
private var windowForego = false
private var windowLoaded = false
func application(_ application: NSApplication, open urls: [URL]) {
// if open panel is already open, stop processing the URL scheme
if NSApplication.shared.keyWindow?.accessibilityIdentifier() == "open-panel" { return }
for url in urls {
if url.host == "changesavelocation" {
// avoid opening the panel repeatedly and playing unnecessary warning sounds
if NSApplication.shared.keyWindow?.identifier?.rawValue == "changeSaveLocation" { continue }
if windowLoaded {
let viewController = window.contentViewController as? ViewController
viewController?.changeSaveLocation(nil)
} else {
windowForego = true
schemeChangeSaveLocation()
}
}
}
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
if windowForego { return }
let storyboard = NSStoryboard(name: "View", bundle: Bundle.main)
let windowController = storyboard.instantiateInitialController() as! NSWindowController
// let viewController = windowController.contentViewController as! ViewController
window = windowController.window
window.setIsVisible(true)
windowLoaded = true
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
return true
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
}