diff --git a/src/MicMute.ahk b/src/MicMute.ahk index 1345da9..91a54fc 100644 --- a/src/MicMute.ahk +++ b/src/MicMute.ahk @@ -71,7 +71,7 @@ Global A_startupTime:= A_TickCount , osd_wnd , overlay_wnd , A_log:="" -, updater_obj:= new Updater(A_ScriptDir) +, updater_obj:= new Updater(A_ScriptDir, Func("util_log")) , updater_UI:="" ; parse cli args @@ -99,10 +99,10 @@ OnExit(Func("exitMicMute")) OnMessage(WM_SETTINGCHANGE, "updateSysTheme") ; listen for window changes registerWindowHook() -; run the update checker once, 5 seconds after launching +; run the update checker once, 10 seconds after launching if(A_IsCompiled && !arg_reload && config_obj.AllowUpdateChecker=1){ cfunc:= ObjBindMethod(updater_obj, "CheckForUpdates") - SetTimer, % cfunc, -5000 + SetTimer, % cfunc, -10000 } A_startupTime:= A_TickCount - A_startupTime util_log("[Main] MicMute startup took " A_startupTime "ms") @@ -147,13 +147,11 @@ initilizeMicMute(default_profile:=""){ ;initilize tray tray_init() if(config_obj.AllowUpdateChecker==-1){ - MsgBox, 35, MicMute, Allow MicMute to connect to the internet and check for updates on startup? + MsgBox, 36, MicMute, Allow MicMute to connect to the internet and check for updates on startup? IfMsgBox, Yes config_obj.AllowUpdateChecker:= 1 IfMsgBox, No config_obj.AllowUpdateChecker:= 0 - IfMsgBox, Cancel - config_obj.AllowUpdateChecker:= -1 } ;on first launch -> immediately call editConfig() if(isFirstLaunch){ @@ -426,6 +424,9 @@ configMsg(err){ } runUpdater(){ + if(!A_IsCompiled) + return + util_log("[Main] Restarting MicMute in updater mode") FileCopy, %A_ScriptFullPath%, %A_Temp%\MicMuteUpdater.exe, 1 Run, "%A_Temp%\MicMuteUpdater.exe" "/updater=1" "/installPath=%A_ScriptDir%" ExitApp, 1 diff --git a/src/UI/Tray.ahk b/src/UI/Tray.ahk index caa2ffe..40a5dce 100644 --- a/src/UI/Tray.ahk +++ b/src/UI/Tray.ahk @@ -122,7 +122,7 @@ tray_Reload(){ } tray_checkForUpdates(){ - updater_obj.CheckForUpdates(1) + UI_showAbout("",1) } tray_noFunc(){ diff --git a/src/UI/config/UI.ahk b/src/UI/config/UI.ahk index bf68c80..77a46e1 100644 --- a/src/UI/config/UI.ahk +++ b/src/UI/config/UI.ahk @@ -778,10 +778,12 @@ UI_createAbout(){ about_obj.Gui("-Resize") } -UI_showAbout(neutron:=""){ +UI_showAbout(neutron:="", isCheckingForUpdates:=0){ util_log("[UI] Showing 'about' window") tray_defaults() - about_obj.show(Format("Center w{:i} h{:i}",500*UI_scale,300*UI_scale),"About MicMute") + if(isCheckingForUpdates) + UI_checkForUpdates(neutron) + about_obj.show(Format("Center w{:i} h{:i}", 500*UI_scale, 300*UI_scale), "About MicMute") about_obj.doc.focus() } @@ -791,12 +793,34 @@ UI_exitAbout(neutron){ UI_createAbout() } +UI_checkForUpdates(neutron:=""){ + refreshButton:= about_obj.doc.getElementById("refresh_button") + refreshButton.classList.add("is-loading") + latestVersion:= updater_obj.getLatestVersion() + if(latestVersion){ + about_obj.doc.getElementById("latest_version").innerText:= latestVersion + refreshButton.classList.add("push-right") + if(latestVersion > A_Version){ + about_obj.doc.getElementById("update_button").classList.remove("is-hidden") + } + } + refreshButton.classList.remove("is-loading") + refreshButton.blur() +} + +UI_launchUpdater(neutron:=""){ + MsgBox, 65, MicMute, % "This will restart MicMute in updater mode" + IfMsgBox, OK + runUpdater() + about_obj.doc.getElementById("update_button").blur() +} + UI_launchURL(neutron:="", url:=""){ Run, %url%, %A_Desktop% } -UI_launchReleasePage(neutron:=""){ - url:= "https://github.com/SaifAqqad/AHK_MicMute/releases/tag/" . A_Version +UI_launchReleasePage(neutron:="", version:=""){ + url:= "https://github.com/SaifAqqad/AHK_MicMute/releases/tag/" . (version? version : A_Version) Run, %url%, %A_Desktop% } diff --git a/src/UI/config/UpdaterUI.ahk b/src/UI/config/UpdaterUI.ahk index 7703211..ce3c5ba 100644 --- a/src/UI/config/UpdaterUI.ahk +++ b/src/UI/config/UpdaterUI.ahk @@ -22,7 +22,7 @@ class UpdaterUI extends NeutronWindow{ show(){ this.setUIState("pre-update") this.resetDetail() - this.appendDetail("Current version: " A_Version "") + this.appendDetail("Installed version: " A_Version "") this.appendDetail("Latest version: " updater_obj.getLatestVersion() "") this.appendDetail("Installation method: " updater_obj.installationMethod "") base.Gui("+LabelUpdaterUI_ +MinSize780x510 -Resize") diff --git a/src/UI/config/css/dark.css b/src/UI/config/css/dark.css index db830e9..5bedffe 100644 --- a/src/UI/config/css/dark.css +++ b/src/UI/config/css/dark.css @@ -9,7 +9,8 @@ body { scrollbar-shadow-color: #4E4E4E; } -.title-bar-header { +.title-bar-header , +.modal-card-head{ color: #d9d9d9 !important; background: #272727 !important; } diff --git a/src/UI/config/html/about.html b/src/UI/config/html/about.html index 7ef6177..a4a615a 100644 --- a/src/UI/config/html/about.html +++ b/src/UI/config/html/about.html @@ -1,92 +1,145 @@ - - - - - - -
- - r -
-
-
- -
-
-
Version: + + + + + + +
+ + r +
+
+
+ +
+ +
+
Installed version: +
+
Latest version: + +
+

+ +

+

+ +

+
+
+
Author: Saif Aqqad
-
Author: Saif Aqqad
-
-
-
-
MicMute's code is public domain and is licensed under The - Unlicense.
-
- MicMute uses several libraries, each with their own license. +
+
MicMute's code is public domain and is licensed under The + Unlicense. +
+
+ MicMute uses several libraries, each with their own license. +
-
- + \ No newline at end of file diff --git a/src/Updater.ahk b/src/Updater.ahk index 21622d4..92078a9 100644 --- a/src/Updater.ahk +++ b/src/Updater.ahk @@ -1,7 +1,7 @@ class Updater { latestVersionInfo:= { "scoop": { "url": "https://github.com/lukesampson/scoop-extras/raw/master/bucket/micmute.json" , "prop": "version" } - , "github": { "url": "https://api.github.com/repos/SaifAqqad/exampleRepo/releases/latest" + , "github": { "url": "https://api.github.com/repos/SaifAqqad/AHK_MicMute/releases/latest" , "prop": "tag_name" }} __New(installDir, loggerFunc:="", skipHashCheck:=0){ @@ -14,7 +14,7 @@ class Updater { update(){ if(InStr(this.installDir, A_ScriptDir)) return -2 - if(!DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x43, "Int", 0)){ ; no internet connection + if(!this.isInternetConnected()){ this.logError("No internet connection") return -5 } @@ -42,10 +42,10 @@ class Updater { } if(FileExist(this.installDir . "latest_MicMute.sha256") && !this.skipHashCheck){ this.loggerFunc.call("Checking hash of MicMute.exe") - FileRead, latest_hash, % this.installDir . "latest_MicMute.sha256" + FileRead, actualHash, % this.installDir . "latest_MicMute.sha256" downloadedHash:= this.getFileHash(this.installDir . "latest_MicMute.exe") - if(latest_hash != downloadedHash){ - this.logError("Hash mismatch.`nExpected: " latest_hash " Got: " downloadedHash) + if(actualHash != downloadedHash){ + this.logError("Hash mismatch.`nExpected: " actualHash " Got: " downloadedHash) this.cleanUp() return -1 } @@ -75,40 +75,16 @@ class Updater { this.loggerFunc.call("Error: " err, -1) } - CheckForUpdates(isTray:=0){ - static isRetry:= 0 - util_log("[Updater] Checking for updates...") - Try { - if(!DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x43, "Int", 0)){ ; no internet - util_log("[Updater] No internet connection") - if(!isTray && !isRetry){ ; retry after 1min if auto checking for updates - util_log("[Updater] Retrying in 1 minute...") - cfunc:= ObjBindMethod(Updater, "CheckForUpdates") - SetTimer, % cfunc, -60000 - isRetry:= 1 - return - } - Throw, Exception("No internet connection") - } - latestVer := this.getLatestVersion() - }catch err{ - util_log("[Updater] An error occured: " err.Message) - if(isTray){ - MsgBox, 16, MicMute, An error occured while fetching the latest version - } + CheckForUpdates(isBackground:=1){ + if(!this.isInternetConnected()){ + this.loggerFunc.call("No internet connection") return - } - util_log("[Updater] latest version: " latestVer) - if(latestVer && latestVer != A_Version){ - txt:= "A new version of MicMute is available`n" - MsgBox, 68, MicMute, %txt%Do you want to download the update from GitHub? - IfMsgBox, OK - return - IfMsgBox, No - return - runUpdater() - }else if(isTray){ - MsgBox, 64, MicMute, You have the latest version installed + } + latestVersion:= this.getLatestVersion() + if(latestVersion && latestVersion != A_Version){ + if(isBackground) + TrayTip, MicMute, % "An Update for MicMute is available, click 'Check for updates' in the tray menu to update" + return latestVersion } } @@ -146,6 +122,10 @@ class Updater { Try FileDelete, % this.installDir . "latest_MicMute.sha256" } + isInternetConnected(){ + return DllCall("Wininet.dll\InternetGetConnectedState", "Str", 0x43, "Int", 0) + } + downloadToFile(url, name){ UrlDownloadToFile, % url, % this.installDir . "\" . name }