Repository navigation
Expand file tree
/
Copy pathAppDelegate.swift
More file actions
69 lines (55 loc) · 1.96 KB
/
Copy pathAppDelegate.swift
File metadata and controls
69 lines (55 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// AppDelegate.swift
// vanillaClone
//
// Created by Thanh Nguyen on 1/24/19.
// Copyright © 2019 Dwarves Foundation. All rights reserved.
//
import AppKit
import HotKey
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate{
var statusBarController = StatusBarController()
var hotKey: HotKey? {
didSet {
guard let hotKey = hotKey else { return }
hotKey.keyDownHandler = { [weak self] in
self?.statusBarController.expandCollapseIfNeeded()
}
}
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
setupAutoStartApp()
registerDefaultValues()
setupHotKey()
openPreferencesIfNeeded()
detectLTRLang()
}
func openPreferencesIfNeeded() {
if Preferences.isShowPreference {
Util.showPrefWindow()
}
}
func setupAutoStartApp() {
Util.setUpAutoStart(isAutoStart: Preferences.isAutoStart)
}
func registerDefaultValues() {
UserDefaults.standard.register(defaults: [
UserDefaults.Key.isAutoStart: false,
UserDefaults.Key.isShowPreference: true,
UserDefaults.Key.isAutoHide: true,
UserDefaults.Key.numberOfSecondForAutoHide: 10.0,
UserDefaults.Key.areSeparatorsHidden: false,
UserDefaults.Key.alwaysHiddenSectionEnabled: false
])
}
func setupHotKey() {
guard let globalKey = Preferences.globalKey else {return}
hotKey = HotKey(keyCombo: KeyCombo(carbonKeyCode: globalKey.keyCode, carbonModifiers: globalKey.carbonFlags))
}
func detectLTRLang() {
// Languages like Arabic uses right to left (RTL) writing direction,
// so some behavier of the app needs to be changed in these cases
Constant.isUsingLTRLanguage = (NSApplication.shared.userInterfaceLayoutDirection == .leftToRight)
}
}