5
5
6
6
; -- Globals
7
7
global APP_VERSION := " 0.1.0"
8
+ global APP_VERSION_NAME := " v" . APP_VERSION
8
9
global APP_NAME := " Polygon"
9
- global APP_URL := " https://github.com/thesobercoder/polygon"
10
- global APP_FEEDBACK_URL := " https://github.com/thesobercoder/polygon/issues/new"
10
+ global APP_REPO_OWNER := " thesobercoder"
11
+ global APP_REPO_NAME := " polygon"
12
+ global APP_URL := " https://github.com/" . APP_REPO_OWNER . " /" . APP_REPO_NAME
13
+ global APP_FEEDBACK_URL := APP_URL . " /issues/new"
14
+ global APP_UPDATE_URL := APP_URL . " /releases/latest"
11
15
global APP_INI_FILE := " polygon.ini"
12
16
global APP_INI_SECTION_SHORTCUT := " Shortcut"
13
17
global APP_INI_SECTION_TOAST := " Toast"
@@ -35,16 +39,49 @@ global APP_SHORTCUT_BOTTOMRIGHT := IniRead(APP_INI_FILE, APP_INI_SECTION_SHORTCU
35
39
; --Tooltip
36
40
A_IconTip := APP_NAME
37
41
42
+ ; -- Register global error logging
43
+ OnError(LogError)
44
+
45
+ ; -- On startup check for version update
46
+ CheckForUpdate()
47
+
38
48
; -- Context Menu
39
49
tray := A_TrayMenu
40
50
tray.Delete ()
41
51
tray.Add(" Help" , ShowHelp)
42
52
tray.Add(" Version" , ShowVersion)
53
+ tray.Add(" Check for Updates" , CheckForUpdate)
43
54
tray.Add(" Feedback" , SubmitFeedback)
44
55
tray.Add(" Restart" , Restart)
45
56
tray.Add(" Exit" , Terminate)
46
57
tray.Default := " Version"
47
58
59
+ LogError(exception, mode)
60
+ {
61
+ ; Get the user's application data folder
62
+ PolygonDataFolder := A_AppData . " \Polygon"
63
+ PolygonLogPath := PolygonDataFolder . " \errorlog.txt"
64
+
65
+ ; Create the folder if it doesn't exist
66
+ if (! DirExist(PolygonDataFolder))
67
+ {
68
+ DirCreate(PolygonDataFolder)
69
+ }
70
+
71
+ ; Display a message to the user
72
+ result := MsgBox ('Polygon encountered an error. The error has been logged in the " errorlog.txt" file. Open folder location?', APP_NAME, " YesNo Iconx" )
73
+ if (result := " Yes" )
74
+ {
75
+ Run (PolygonDataFolder)
76
+ }
77
+
78
+ ; Append the error message to the log file
79
+ FileAppend (" Error on line " . exception.Line . " : " . exception.Message . " `n" , PolygonLogPath)
80
+
81
+ return true
82
+ }
83
+
84
+
48
85
Toast(Message, r, l, t, b)
49
86
{
50
87
; -- Return if toast is not enabled
@@ -95,6 +132,74 @@ Toast(Message, r, l, t, b)
95
132
}
96
133
}
97
134
135
+ ParseVersionString(version)
136
+ {
137
+ regex := " v(\d+)\.(\d+)\.(\d+)"
138
+ if (RegExMatch (version, regex, & parsedVersion))
139
+ {
140
+ if (parsedVersion.Count > 0 )
141
+ {
142
+ ; -- Extract the version here
143
+ major := parsedVersion[1 ]
144
+ minor := parsedVersion[2 ]
145
+ patch := parsedVersion[3 ]
146
+
147
+ return Number(major) * 10000 + Number(minor) * 100 + Number(patch)
148
+ }
149
+ }
150
+ return 0
151
+ }
152
+
153
+ CheckForUpdate(args* )
154
+ {
155
+ version := GetLatestGitHubRelease(APP_REPO_OWNER, APP_REPO_NAME)
156
+
157
+ ; Check if the request was successful
158
+ if (version)
159
+ {
160
+ newVersion := ParseVersionString(version)
161
+ currentVersion := ParseVersionString(APP_VERSION_NAME)
162
+
163
+ ; -- Check if the latest version is greater
164
+ if (newVersion > currentVersion)
165
+ {
166
+ result := MsgBox (" A new version " . newVersion . " is available. Do you want to update?" , APP_NAME, " YesNo Iconi" )
167
+ if (result == " Yes" )
168
+ {
169
+ Run (APP_UPDATE_URL)
170
+ return
171
+ }
172
+ }
173
+ }
174
+
175
+ if (args && args.Length > 0 && args[1 ] == " Check for Updates" )
176
+ {
177
+ MsgBox (" You already have the latest version." , APP_NAME, " Iconi" )
178
+ }
179
+ }
180
+
181
+ GetLatestGitHubRelease(owner , repo)
182
+ {
183
+ req := ComObject(" Msxml2.XMLHTTP" )
184
+ req.open(" GET" , " https://api.github.com/repos/" . owner . " /" . repo . " /releases/latest" , false )
185
+ req.send ()
186
+ if req.status ! = 200
187
+ {
188
+ MsgBox (" Error checking for update. Please try after some time." , APP_NAME, " Iconx" )
189
+ return
190
+ }
191
+
192
+ res := JSONParse(req.responseText)
193
+ return res.tag_name
194
+
195
+ JSONParse(str)
196
+ {
197
+ htmlfile := ComObject(" htmlfile" )
198
+ htmlfile.write ('<meta http- equiv=" X-UA-Compatible" content=" IE=edge" >')
199
+ return htmlfile.parentWindow.JSON.parse(str)
200
+ }
201
+ }
202
+
98
203
SubmitFeedback(* )
99
204
{
100
205
Run (APP_FEEDBACK_URL)
@@ -117,7 +222,7 @@ Terminate(*)
117
222
118
223
ShowVersion(* )
119
224
{
120
- MsgBox (" Version " . APP_VERSION, APP_NAME, " iconi " )
225
+ MsgBox (" Version " . APP_VERSION, APP_NAME, " Iconi " )
121
226
}
122
227
123
228
; -- Map Hotkeys
0 commit comments