Skip to content

Commit

Permalink
Added Startup options and a bit of refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
moorer2k committed Oct 25, 2024
1 parent 0be0789 commit 02956a4
Show file tree
Hide file tree
Showing 19 changed files with 425 additions and 281 deletions.
15 changes: 15 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="SpotiKey.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<userSettings>
<SpotiKey.My.MySettings>
<setting name="AutoRegister" serializeAs="String">
<value>False</value>
</setting>
<setting name="AutoMinimize" serializeAs="String">
<value>False</value>
</setting>
</SpotiKey.My.MySettings>
</userSettings>
</configuration>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
106 changes: 73 additions & 33 deletions FormMain.Designer.vb → Forms/FormMain.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions FormMain.resx → Forms/FormMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="NotifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<value>309, 17</value>
</metadata>
<metadata name="ContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>152, 17</value>
<value>425, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="NotifyIcon1.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
61 changes: 52 additions & 9 deletions FormMain.vb → Forms/FormMain.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Imports NHotkey
Imports NHotkey.WindowsForms
Imports SpotiKey.Modules
Imports SpotiKey.Utils

Public Class FormMain

Expand All @@ -9,10 +11,8 @@ Public Class FormMain
Select Case ButtonRegister.Text
Case "Register"
CheckSetSpotify()
RegisterHotkeysFromFile($"{Application.StartupPath}\Hotkeys.txt")
HotkeyManager.Current.IsEnabled = True
ButtonRegister.Text = "Unregister"
Case "Unregister"
Case "Unregister" -
HotkeyManager.Current.IsEnabled = False
ButtonRegister.Text = "Register"
End Select
Expand Down Expand Up @@ -40,7 +40,7 @@ Public Class FormMain
Dim key = HotkeyParser.ParseKey(keyName)

HotkeyManager.Current.AddOrReplace(action, key Or modifiers, AddressOf HotkeyPressed)
Console.WriteLine($"Successfully registered hotkey: {action}")
LabelStatus.Text = "Status: Registered hotkeys!"
Catch ex As Exception
Console.WriteLine($"Error registering hotkey {action}: {ex.Message}")
End Try
Expand Down Expand Up @@ -69,7 +69,8 @@ Public Class FormMain
Private Sub CheckSetSpotify()
_spotifyHwnd = SpotifyHelper.GetSpotify()
If _spotifyHwnd <> IntPtr.Zero Then
LabelStatus.Text = "Status: Ready!"
RegisterHotkeysFromFile($"{Application.StartupPath}\Hotkeys.txt")
HotkeyManager.Current.IsEnabled = True
Else
LabelStatus.Text = "Status: Failure!"
End If
Expand All @@ -81,10 +82,7 @@ Public Class FormMain
End Sub

Private Sub FormMain_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide() ' Hide the form
NotifyIcon1.Visible = True ' Show the NotifyIcon in the system tray
End If
HideWindow(True)
End Sub

Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Expand All @@ -95,6 +93,21 @@ Public Class FormMain
ShowWindow()
End Sub

Private Sub HideWindow(resized As Boolean)

If resized Then
If Me.WindowState = FormWindowState.Minimized Then
Me.Hide() ' Hide the form
NotifyIcon1.Visible = True ' Show the NotifyIcon in the system tray
End If
Else
Me.WindowState = FormWindowState.Minimized
Me.Hide() ' Hide the form
NotifyIcon1.Visible = True ' Show the NotifyIcon in the system tray
End If

End Sub

Private Sub ShowWindow()
Me.Show() ' Show the form
Me.WindowState = FormWindowState.Normal ' Restore the window to normal state
Expand All @@ -113,4 +126,34 @@ Public Class FormMain
NotifyIcon1.Visible = False
NotifyIcon1.Dispose()
End Sub

Private Sub FormMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load

LoadSettings()

If My.Settings.AutoRegister Then
ButtonRegister.Enabled = False
CheckSetSpotify()
End If
If My.Settings.AutoMinimize Then
HideWindow(False)
End If

End Sub

Private Sub LoadSettings()
CheckAutoMin.Checked = My.Settings.AutoMinimize
CheckAutoReg.Checked = My.Settings.AutoRegister
End Sub

Private Sub CheckAutoReg_CheckedChanged(sender As Object, e As EventArgs) Handles CheckAutoReg.CheckedChanged
My.Settings.AutoRegister = CheckAutoReg.Checked
My.Settings.Save()
End Sub

Private Sub CheckAutoMin_CheckedChanged(sender As Object, e As EventArgs) Handles CheckAutoMin.CheckedChanged
My.Settings.AutoMinimize = CheckAutoMin.Checked
My.Settings.Save()
End Sub

End Class
43 changes: 0 additions & 43 deletions HotkeyParser.vb

This file was deleted.

Loading

0 comments on commit 02956a4

Please sign in to comment.