-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.ahk
117 lines (100 loc) · 3.51 KB
/
Application.ahk
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
class Application extends _Object
{
static _applicationName := "Stronghold Hotkeys"
, _iniPath := "Config.ini"
, _logger := LoggerFactory.GetLogger(Application)
__New()
{
this._settingsModel := ""
this._settingsController := ""
this._settingsGui := ""
this._hotkeyHandler := ""
this._updateChecker := ""
this._errorLogger := ""
this._exitLogger := ""
}
Initialize()
{
; Set up the logger
If (IsDebuggerAttatched())
{
LoggerFactory.SetMinLogLevel(_logLevel.Trace)
LoggerFactory.SetBufferSize(1)
}
Else
{
LoggerFactory.SetMinLogLevel(_logLevel.Warn)
LoggerFactory.SetBufferSize(1)
}
this._errorLogger := LoggerFactory.GetErrorLogger()
this._exitLogger := LoggerFactory.GetExitLogger()
Application._logger.Info("App is starting up...")
Application._logger.Info("Version: " Stronghold_Version())
If (IsDebuggerAttatched())
{
Application._logger.Info("App is running in dev mode.")
}
this._registerWindowGroups()
; Create the settings model from the config file (if it exists), otherwise create a default one
If (FileExist(Application._iniPath))
{
Application._logger.Trace("Applying the saved settings.")
readConfig := FileRead(Application._iniPath)
this._settingsModel := SettingsModel.FromIniString(readConfig)
}
Else
{
Application._logger.Trace("No saved settings. Use the default settings.")
this._settingsModel := SettingsModel.Default()
}
this._settingsController := new SettingsController(this._settingsModel, Application._iniPath)
this._hotkeyHandler := new StrongholdHotkeyHandler(this._settingsController, this._settingsModel)
this._updateChecker := new UpdatesChecker(this._settingsController, this._settingsModel)
; Set up the tray menu (has to be done before the gui to ensure the Stronghold icon in the window title bar)
TrayMenu.Instance.Init(this)
; Only show the gui when no config file exists (usually the first load), or if the app is in dev mode
If (!FileExist(Application._iniPath) || IsDebuggerAttatched())
{
this._settingsController.SaveToFile()
this._getOrCreateSettingsGui().Show()
}
Application._logger.Info("App startup finished.")
}
; Get a reference to a settings gui instance
SettingsGui[]
{
Get
{
Return this._getOrCreateSettingsGui()
}
}
; The central application exit point
ExitApp()
{
Application._logger.Info("App is shutting down...")
ExitApp
}
; Register the Stronghold window groups via the GroupAdd command
_registerWindowGroups()
{
static isRegistered := false
If (isRegistered)
{
Return
}
For each, group in EWindowGroups
{
GroupAdd(group, StrongholdManager.WindowTitles[group])
}
isRegistered := true
}
_getOrCreateSettingsGui()
{
If (this._settingsGui == "" || this._settingsGui.IsDestroyed)
{
title := Format(GetLanguage().Title, Stronghold_Version())
this._settingsGui := new SettingsGui(this._settingsController, this._settingsModel, title)
}
Return this._settingsGui
}
}