Skip to content

Commit

Permalink
Now it saves and restores state
Browse files Browse the repository at this point in the history
  • Loading branch information
teamcons committed Jun 20, 2024
1 parent e31b512 commit d745c99
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 16 deletions.
Binary file modified Assistant.exe
Binary file not shown.
27 changes: 19 additions & 8 deletions Assistant.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ else
# When executed at windows start, location is not in the script folder
Set-Location -Path $ScriptPath

# Read the file
$script:settings = Import-LocalizedData -FileName settings.psd1 -BaseDirectory $ScriptPath\parts

# Load and parse the JSON configuration file
$script:settings = Get-Content $ScriptPath\parts\state.json -Raw -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue | ConvertFrom-Json -ErrorAction:SilentlyContinue -WarningAction:SilentlyContinue

# legacy #$script:settings = Import-LocalizedData -FileName settings.psd1 -BaseDirectory $ScriptPath\parts


# Get localization
$script:text = Import-LocalizedData -FileName interface.psd1 -BaseDirectory $ScriptPath\localizations

# Load everything we need
Expand All @@ -54,31 +60,36 @@ Import-Module $ScriptPath\parts\UI.ps1


# Start the subprocesses
if ($settings.TopLeftOverview.Enabled)
if ($settings.TopLeftOverview.Enabled -eq "true")
{
Start-Process -FilePath $ScriptPath\parts\hotcorner_topleft.exe -ArgumentList $settings.TopLeftOverview.reactivity,$settings.TopLeftOverview.sensitivity
$Menu_Toggle_HotCorner_TopLeft.Checked = $true
}

if ($settings.WindowsButton.Enabled)
if ($settings.WindowsButton.Enabled -eq "true")
{
Start-Process -FilePath $ScriptPath\parts\hotcorner_winbutton.exe -ArgumentList $settings.WindowsButton.reactivity,$settings.WindowsButton.sensitivity
$Menu_Toggle_HotCorner_WinButton.Checked = $true
}


if ($settings.ShowDesktop.Enabled)
if ($settings.ShowDesktop.Enabled -eq "true")
{
Start-Process -FilePath $ScriptPath\parts\hotcorner_bottomright_showdesktop.exe -ArgumentList $settings.ShowDesktop.reactivity,$settings.ShowDesktop.sensitivity
$Menu_Toggle_HotCorner_ShowDesktop.Checked = $true
}

if ($settings.CloseActiveWindow.Enabled)
if ($settings.CloseActiveWindow.Enabled -eq "true")
{
Start-Process -FilePath $ScriptPath\parts\hotcorner_topright_close.exe -ArgumentList $settings.CloseActiveWindow.reactivity,$settings.CloseActiveWindow.sensitivity
$Menu_Toggle_HotCorner_Close.Checked = $true
}


if ($settings.KeepAwake.Enabled)
if ($settings.KeepAwake.Enabled -eq "true")
{
Start-Process -FilePath $ScriptPath\parts\keepawake.exe
Start-Process -FilePath $ScriptPath\parts\keepawake.exe
$Menu_Toggle_KeepAwake.Checked = $true
}


Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Had a look through various sources for having a tray icon. Thanks to all of thes
Clipboard history module by mutaguchi
https://gist.github.com/mutaguchi/019ad33e156637585a22a656d8fd3f46

Jason
https://gist.github.com/jhochwald/56cf0897fa6b82e65f12

OCR
https://github.com/daijro/PsOCRCapture
Expand Down
6 changes: 3 additions & 3 deletions parts/UI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $Submenu_clipboard.Add_Popup({Clipboard_generate_entries $Submenu_clipboard})

# Toggle between halt and continue
$Menu_Toggle_HotCorner_TopLeft = New-Object System.Windows.Forms.MenuItem
$Menu_Toggle_HotCorner_TopLeft.Checked = $true
$Menu_Toggle_HotCorner_TopLeft.Checked = $false
$Menu_Toggle_HotCorner_TopLeft.Text = $text.Hotcorners.Overview
$Menu_Toggle_HotCorner_TopLeft.Add_Click({
# If it was checked when clicked, stop it
Expand Down Expand Up @@ -198,7 +198,7 @@ $Submenu_hotcorner.MenuItems.Add($Menu_Toggle_HotCorner_Close)

# Toggle between halt and continue
$Menu_Toggle_KeepAwake = New-Object System.Windows.Forms.MenuItem
$Menu_Toggle_KeepAwake.Checked = $true
$Menu_Toggle_KeepAwake.Checked = $false
$Menu_Toggle_KeepAwake.Text = $text.TopUI.KeepAwake
$Menu_Toggle_KeepAwake.Add_Click({
# If it was checked when clicked, stop it
Expand All @@ -209,7 +209,7 @@ $Menu_Toggle_KeepAwake.Add_Click({
$Menu_Toggle_KeepAwake.Checked = $false
$Main_Tool_Icon.Icon = $icondark }
else {
Start-Process $ScriptPath\functionalities\keepawake.exe
Start-Process $ScriptPath\parts\keepawake.exe
$Menu_Toggle_KeepAwake.Checked = $true
$Main_Tool_Icon.Icon = $icon }
})
Expand Down
Binary file modified parts/hotcorner_topright_close.exe
Binary file not shown.
25 changes: 25 additions & 0 deletions parts/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"TopLeftOverview": {
"Enabled": "true",
"reactivity": "400",
"sensitivity": "30"
},
"WindowsButton": {
"Enabled": "false",
"reactivity": "500",
"sensitivity": "50"
},
"ShowDesktop": {
"Enabled": "false",
"reactivity": "500",
"sensitivity": "50"
},
"CloseActiveWindow": {
"Enabled": "false",
"reactivity": "700",
"sensitivity": "20"
},
"KeepAwake": {
"Enabled": "true"
}
}
46 changes: 41 additions & 5 deletions parts/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,49 @@ $quit = {
$Main_Tool_Icon.Visible = $false

# Stop everything that needs stopping
if ($Menu_Toggle_HotCorner_TopLeft.Checked) {Stop-Process -Name hotcorner_topleft}
if ($Menu_Toggle_HotCorner_WinButton.Checked) {Stop-Process -Name hotcorner_winbutton}
if ($Menu_Toggle_HotCorner_ShowDesktop.Checked) {Stop-Process -Name hotcorner_bottomright_showdesktop}
if ($Menu_Toggle_HotCorner_Close.Checked) {Stop-Process -Name hotcorner_topright_close}
if ($Menu_Toggle_HotCorner_TopLeft.Checked)
{
Stop-Process -Name hotcorner_topleft
$settings.TopLeftOverview.Enabled = "true"
}
else {$settings.TopLeftOverview.Enabled = "false"}


if ($Menu_Toggle_HotCorner_WinButton.Checked)
{
Stop-Process -Name hotcorner_winbutton
$settings.WindowsButton.Enabled = "true"
}
else {$settings.WindowsButton.Enabled = "false"}

if ($Menu_Toggle_HotCorner_ShowDesktop.Checked)
{
Stop-Process -Name hotcorner_bottomright_showdesktop
$settings.ShowDesktop.Enabled = "true"
}
else {$settings.ShowDesktop.Enabled = "false"}


if ($Menu_Toggle_HotCorner_Close.Checked)
{
Stop-Process -Name hotcorner_topright_close
$settings.CloseActiveWindow.Enabled = "true"
}
else {$settings.CloseActiveWindow.Enabled = "false"}


if ($Menu_Toggle_KeepAwake.Checked)
{
Stop-Process -Name keepawake
$settings.KeepAwake.Enabled = "true"
}
else
{$settings.KeepAwake.Enabled = "false"}


if ($Menu_Toggle_KeepAwake.Checked) {Stop-Process -Name keepawake}
Write-Output $settings | ConvertTo-Json | Out-File -Encoding "UTF8" $ScriptPath\parts\state.json



$Main_Tool_Icon.Icon.Dispose();
$Main_Tool_Icon.Dispose();
Expand Down

0 comments on commit d745c99

Please sign in to comment.