Skip to content

Commit

Permalink
Add Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Dec 23, 2021
1 parent 9e46745 commit b9fdf55
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 69 deletions.
29 changes: 25 additions & 4 deletions src/MicMute.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SetWorkingDir %A_ScriptDir%
#Include, %A_ScriptDir%
#Include, ResourcesManager.ahk
#Include, MicrophoneController.ahk
#Include, VersionChecker.ahk
#Include, Updater.ahk
#Include, %A_ScriptDir%\config
#Include, ProfileTemplate.ahk
#Include, Config.ahk
Expand All @@ -41,8 +41,10 @@ SetWorkingDir %A_ScriptDir%
#Include, %A_ScriptDir%\UI\config
#Include, HotkeyPanel.ahk
#Include, UI.ahk
#Include, UpdaterUI.ahk

Global config_obj
Global A_startupTime:= A_TickCount
, config_obj
, current_profile
, mic_controllers
, mute_sound
Expand All @@ -60,20 +62,31 @@ Global config_obj
, arg_noUI:=0
, arg_reload:= 0
, arg_logFile:="*"
, arg_isUpdater:=0
, arg_installPath:=""
, resources_obj:= new ResourcesManager()
, isFirstLaunch:=0
, A_Version:= A_IsCompiled? util_getFileSemVer(A_ScriptFullPath) : U_Version
, sound_player
, osd_wnd
, overlay_wnd
, A_log:=""
, A_startupTime:= A_TickCount
, updater_obj:= new Updater(A_ScriptDir)
, updater_UI:=""

; parse cli args
parseArgs()
tray_defaults()
util_log("MicMute v" . A_Version)
util_log(Format("[Main] Running as user {}, A_IsAdmin = {}", A_UserName, A_IsAdmin))
OnError(Func("util_log"))
if(arg_isUpdater){
util_log("[Main] Updater mode")
updater_UI:= new UpdaterUI()
return
}else{
Try FileDelete, %A_Temp%\MicMuteUpdater.exe
}
; create config gui window
if(!arg_noUI)
UI_create(Func("reloadMicMute"))
Expand All @@ -88,7 +101,7 @@ OnMessage(WM_SETTINGCHANGE, "updateSysTheme")
registerWindowHook()
; run the update checker once, 5 seconds after launching
if(A_IsCompiled && !arg_reload && config_obj.AllowUpdateChecker=1){
cfunc:= ObjBindMethod(VersionChecker, "CheckForUpdates")
cfunc:= ObjBindMethod(updater_obj, "CheckForUpdates")
SetTimer, % cfunc, -5000
}
A_startupTime:= A_TickCount - A_startupTime
Expand Down Expand Up @@ -371,6 +384,8 @@ parseArgs(){
case "profile": arg_profile:= val3
case "reload": arg_reload:= (val3=""? 1 : val3)
case "logFile": arg_logFile:= val3
case "updater": arg_isUpdater:= (val3=""? 1 : val3)
case "installPath": arg_installPath:= val3
}
}
}
Expand Down Expand Up @@ -408,4 +423,10 @@ configMsg(err){
editConfig()
IfMsgBox, Cancel
ExitApp, -2
}

runUpdater(){
FileCopy, %A_ScriptFullPath%, %A_Temp%\MicMuteUpdater.exe, 1
Run, "%A_Temp%\MicMuteUpdater.exe" "/updater=1" "/installPath=%A_ScriptDir%"
ExitApp, 1
}
4 changes: 3 additions & 1 deletion src/ResourcesManager.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ResourcesManager {
;@Ahk2Exe-AddResource %U_Res%\ptt_off.wav
;@Ahk2Exe-AddResource %U_Res%\ptt_on.wav
;@Ahk2Exe-AddResource *10 %U_UI%\html\UI.html
;@Ahk2Exe-AddResource *10 %U_UI%\html\Updater.html
;@Ahk2Exe-AddResource *10 %U_UI%\html\about.html
;@Ahk2Exe-AddResource %U_UI%\css\bulma.css
;@Ahk2Exe-AddResource %U_UI%\css\base.css
Expand All @@ -30,7 +31,8 @@ class ResourcesManager {
defaultIcon:= {file:"MicMute.ico",group:"-2000"}
pngIcon:= "MicMute.png"
htmlFile:= { UI: "UI.html"
, about: "about.html"}
, about: "about.html"
, Updater: "Updater.html"}
cssFile:= [{ name:"bulma",file: "bulma.css"}
,{ name:"base",file:"base.css"}
,{ name:"dark",file:"dark.css"}]
Expand Down
2 changes: 1 addition & 1 deletion src/UI/Tray.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tray_Reload(){
}

tray_checkForUpdates(){
VersionChecker.CheckForUpdates(1)
updater_obj.CheckForUpdates(1)
}

tray_noFunc(){
Expand Down
80 changes: 80 additions & 0 deletions src/UI/config/UpdaterUI.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
class UpdaterUI extends NeutronWindow{
static UI_STATES := ["pre-update", "during-update", "post-update"]

__New(){
base.__New()
this.load(resources_obj.htmlFile.Updater)
this.loadCss()
updater_obj:= new Updater(arg_installPath, ObjBindMethod(this, "onUpdateState"))
this.show()
}

loadCss(){
this.doc.getElementById("MicMute_icon").setAttribute("src", resources_obj.pngIcon)
for i, css in resources_obj.cssFile {
if(!this.doc.getElementById("css_" css.name))
this.doc.head.insertAdjacentHTML("beforeend",Format(template_link, css.name, css.file))
}
RegRead, isLightTheme, HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize, AppsUseLightTheme
if(isLightTheme)
this.doc.getElementById("css_dark").setAttribute("disabled","1")
}

show(){
this.setUIState("pre-update")
this.resetDetail()
this.appendDetail("Current version: " A_Version)
this.appendDetail("Latest version: " updater_obj.getLatestVersion())
this.appendDetail("Installation method: " updater_obj.installationMethod)
base.Gui("+LabelUpdaterUI_ +MinSize780x510 -Resize")
base.Show("Center w780 h510","MicMute Updater")
}

setUIState(currentState){
for i, state in this.UI_STATES {
for i, elem in this.Each(this.qsa("." state)) {
elem.classList.add("is-hidden")
}
}
for i, elem in this.Each(this.qsa("." currentState)) {
elem.classList.remove("is-hidden")
}
}

onUpdateState(str, updaterStatus:=0){
this.appendDetail(str)
this.doc.getElementById("current_status").innerText := str
if(updaterStatus)
this.setUIState("post-update")
}

onClickUpdate(){
this.setUIState("during-update")
this.resetDetail()
updater_obj.update()
}

onClickExit(restart:=0){
if(restart)
Run, % arg_installPath "\MicMute.exe" , % arg_installPath, UseErrorLevel
ExitApp, 0
}

resetDetail(){
this.doc.getElementById("details").innerHTML := ""
}

appendDetail(str){
detailBox := this.doc.getElementById("details")
detailBox.insertAdjacentHTML("beforeend", "<p>" str "</p>")
detailBox.scrollTop := detailBox.scrollHeight
}

Close(){
ExitApp, -2
}
}

UpdaterUI_Close(){
ExitApp, -2
}
8 changes: 7 additions & 1 deletion src/UI/config/css/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body {
scrollbar-shadow-color: #4E4E4E;
}

header {
.title-bar-header {
color: #d9d9d9 !important;
background: #272727 !important;
}
Expand Down Expand Up @@ -63,6 +63,7 @@ a:focus,
p,
body,
.card,
.box,
h1,
h2,
h3,
Expand Down Expand Up @@ -119,4 +120,9 @@ input[type="checkbox"]:checked+span {

#notification label{
color: #d9d9d9 !important;
}

.card-footer,
.card-footer *{
border-color: #555555 !important;
}
113 changes: 113 additions & 0 deletions src/UI/config/html/updater.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="../css/bulma.css">
<link rel="stylesheet" href="../css/base.css">
<!-- <link rel="stylesheet" href="../css/dark.css"> -->
<style>
header {
height: 30px;
}

body {
overflow: hidden;
font-family: 'Segoe UI Variable Display', 'Segoe UI';
}


#MicMute_icon {
width: 38px;
height: 38px;
border-radius: 23%;
box-shadow: 0 0.5em 1em -0.125em rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.02);
transition: box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

img#MicMute_icon:hover,
label:hover>img#MicMute_icon {
box-shadow: 0px 11px 15px -7px rgba(0, 0, 0, 0.055), 0px 0px 20px 0px rgba(255, 87, 45, 0.63), 0px 9px 46px 8px rgba(0, 0, 0, 0.055);
}

.container {
top: 20%;
left: 50%;
transform: translate(-50%, -15%);
max-width: 700px !important
}

#label {
font-size: 2rem;
font-weight: 600;
cursor: default;
margin-bottom: 5% !important;
}

.card-content {
height: 250px;
}

.card {
width: 800% !important;
}

#current_status {
cursor: default;
}

#details {
margin-top: 20px;
padding-top: 0;
height: 7.5em;
overflow-y: scroll;
box-sizing: content-box;
line-height: 2em;
}

#current_status {
color: #ff6920;
}

.progress {
width: 80%;
margin-left: auto;
margin-right: auto;
margin-top: 1.5rem;
}

.single-item {
border-right-width: 0 !important;
}
</style>
</head>

<body class="noselect" oncontextmenu="return false">
<header class="title-bar-header">
<span class="title-bar" onmousedown="neutron.DragTitleBar()"></span>
<span class="title-btn title-btn-close" onclick="neutron.Close()">r</span>
</header>
<div class="container">
<div id='label'>
<label>
<img id='MicMute_icon' src='../../../resources/MicMute.png' /> MicMute
</label>
</div>
<div class="card">
<div class="card-content">
<p id="heading" class="pre-update ">An update for MicMute is available, click on 'Update' to start updating</p>
<p id="status_heading" class="post-update during-update is-hidden">Current status: <span id="current_status"></span></p>
<div class="box" id="details">
</div>
</div>
<footer class="card-footer">
<progress class="progress is-small is-primary during-update is-hidden" max="100">100%</progress>
<a onclick="neutron.onClickUpdate()" class="card-footer-item pre-update is-hidden single-item">Update</a>
<a onclick="neutron.onClickExit(0)" class="card-footer-item post-update is-hidden">Exit</a>
<a onclick="neutron.onClickExit(1)" class="card-footer-item post-update is-hidden">Exit & restart MicMute</a>
</footer>
</div>
</div>
</body>

</html>
Loading

0 comments on commit b9fdf55

Please sign in to comment.