Skip to content

Commit eb7d7d4

Browse files
committed
Add settings to enable/disable folder monitoring and background compression
1 parent d9341cc commit eb7d7d4

File tree

5 files changed

+83
-15
lines changed

5 files changed

+83
-15
lines changed

CompactGUI.Watcher/IdleDetector.vb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Public Class IdleDetector
1212

1313
Public Shared Paused As Boolean = False
1414

15+
Public Shared Property IsEnabled As Boolean = True
16+
1517
Shared Sub New()
1618
_idletimer = New PeriodicTimer(TimeSpan.FromSeconds(2))
1719
End Sub
@@ -32,10 +34,10 @@ Public Class IdleDetector
3234
Try
3335
While Await IdleDetector._idletimer.WaitForNextTickAsync(_cts.Token) AndAlso Not _cts.Token.IsCancellationRequested
3436

35-
If GetIdleTime() > 300 AndAlso Not Paused Then
37+
If GetIdleTime() > 300 AndAlso Not Paused AndAlso IsEnabled Then
3638
RaiseEvent IsIdle(Nothing, EventArgs.Empty)
3739

38-
ElseIf Not Paused Then
40+
ElseIf Not Paused AndAlso IsEnabled Then
3941
RaiseEvent IsNotIdle(Nothing, EventArgs.Empty)
4042
End If
4143

CompactGUI.Watcher/Watcher.vb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Public Class Watcher : Inherits ObservableObject
1616
<PropertyChanged.AlsoNotifyFor(NameOf(TotalSaved))>
1717
Public Property LastAnalysed As DateTime
1818

19+
Public Shared Property IsWatchingEnabled As Boolean = True
20+
Public Shared Property IsBackgroundCompactingEnabled As Boolean = True
1921

2022
Private ReadOnly _DataFolder As New IO.DirectoryInfo(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "IridiumIO", "CompactGUI"))
2123
Private ReadOnly Property WatcherJSONFile As IO.FileInfo = New IO.FileInfo(IO.Path.Combine(_DataFolder.FullName, "watcher.json"))
@@ -204,13 +206,16 @@ Public Class Watcher : Inherits ObservableObject
204206

205207

206208
Private Async Sub OnSystemIdle()
209+
210+
If Not IsWatchingEnabled Then Return
211+
207212
Dim recentThresholdDate As DateTime = DateTime.Now.AddSeconds(-LAST_SYSTEM_MODIFIED_TIME_THRESHOLD)
208213
If FolderMonitors.Any(Function(x) x.LastChangedDate > recentThresholdDate) Then Return
209214

210-
If Not _parseWatchersSemaphore.CurrentCount = 0 Then
215+
If Not _parseWatchersSemaphore.CurrentCount = 0 AndAlso IsWatchingEnabled Then
211216
Await ParseWatchers()
212217
End If
213-
If Not _parseWatchersSemaphore.CurrentCount = 0 Then
218+
If Not _parseWatchersSemaphore.CurrentCount = 0 AndAlso IsBackgroundCompactingEnabled Then
214219
Await BackgroundCompact()
215220
End If
216221
End Sub

CompactGUI/Components/Settings/Settings_main.xaml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
d:Background="White"
99
Title="Settings_main">
1010

11-
<StackPanel>
11+
<StackPanel >
1212
<Label Content="Filetype Management" FontWeight="SemiBold"/>
1313

14-
<StackPanel Margin="10,20,0,10">
15-
<Grid Margin="0,0,0,10">
14+
<StackPanel Margin="10,10,0,7">
15+
<Grid Margin="0,0,0,7">
1616
<TextBlock FontSize="14" VerticalAlignment="Center">manage local skipped filetypes</TextBlock>
17-
<Button x:Name="uiEditSkipListBTN" IsEnabled="True" HorizontalAlignment="Right" Width="100" Margin="0,0,25,0" Height="36" BorderThickness="0" Click="uiEditSkipListBTN_Click" Content="edit"></Button>
17+
<Button x:Name="uiEditSkipListBTN" IsEnabled="True" HorizontalAlignment="Right" Width="100" Margin="0,0,25,0" Height="32" BorderThickness="0" Click="uiEditSkipListBTN_Click" Content="edit"></Button>
1818
</Grid>
1919

2020
<Grid>
@@ -27,7 +27,7 @@
2727
</ui:FlyoutBase.AttachedFlyout>
2828
</TextBlock>
2929

30-
<ComboBox x:Name="comboBoxSkipUserResultsAggression" IsEnabled="False" SelectedIndex="0" HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Left" Width="100" Height="36" Margin="0,0,25,0" Background="Transparent" Foreground="#98A9B9" BorderBrush="#98A9B9" BorderThickness="1">
30+
<ComboBox x:Name="comboBoxSkipUserResultsAggression" IsEnabled="False" SelectedIndex="0" HorizontalAlignment="Right" VerticalAlignment="Center" HorizontalContentAlignment="Left" Width="100" Height="32" Margin="0,0,25,0" Background="Transparent" Foreground="#98A9B9" BorderBrush="#98A9B9" BorderThickness="1">
3131
<ComboBoxItem>
3232
<TextBlock Text="low" FontSize="14" FontWeight="SemiBold" Foreground="#98A9B9" />
3333
</ComboBoxItem>
@@ -43,20 +43,34 @@
4343

4444
</StackPanel>
4545

46-
<Separator Margin="0,10,0,20"/>
46+
<Separator Margin="0,10,0,10"/>
4747
<Label Content="System Integration" FontWeight="SemiBold"/>
48-
<StackPanel Margin="10,20,0,10">
49-
<CheckBox x:Name="uiIsContextEnabled" Margin="0,0,0,10" >add to right-click context menu</CheckBox>
48+
<StackPanel Margin="10,10,0,7">
49+
<CheckBox x:Name="uiIsContextEnabled" >add to right-click context menu</CheckBox>
5050
<CheckBox x:Name="uiIsStartMenuEnabled" IsEnabled="False" Visibility="Collapsed">add to start menu</CheckBox>
5151
<CheckBox x:Name="uiShowNotifications" IsEnabled="True" Checked="uiShowNotifications_Checked" Unchecked="uiShowNotifications_Unchecked">show notification on completion</CheckBox>
5252

5353
</StackPanel>
54-
<Separator Margin="0,10,0,20"/>
54+
<Separator Margin="0,10,0,10"/>
55+
56+
<Label Content="Background Watcher Settings" FontWeight="SemiBold"/>
57+
<StackPanel Margin="10,10,0,7">
58+
<CheckBox x:Name="uiEnableBackgroundWatcher" Checked="uiEnableBackgroundWatcher_Checked" Unchecked="uiEnableBackgroundWatcher_Unchecked">monitor compressed folders for changes</CheckBox>
59+
<CheckBox x:Name="uiEnableBackgroundAutoCompression" Margin="30,0,0,0" Checked="uiEnableBackgroundAutoCompression_Checked" Unchecked="uiEnableBackgroundAutoCompression_Unchecked">periodically check and keep folders compressed</CheckBox>
60+
61+
</StackPanel>
62+
<Separator Margin="0,10,0,10"/>
63+
64+
65+
66+
67+
68+
5569
<Label Content="UI Scaling" FontWeight="SemiBold"/>
5670

57-
<Slider Margin="15,20,15,20" x:Name="uiScalingFactor" Orientation="Horizontal" Value="1" Minimum="0.5" Maximum="1.5" IsSnapToTickEnabled="True" TickFrequency="0.125" TickPlacement="BottomRight" PreviewMouseUp="uiScalingFactor_PreviewMouseUp" PreviewKeyUp="uiScalingFactor_PreviewKeyUp" LargeChange="0.125" SmallChange="0.125" />
71+
<Slider Margin="15,10,15,20" x:Name="uiScalingFactor" Orientation="Horizontal" Value="1" Minimum="0.5" Maximum="1.5" IsSnapToTickEnabled="True" TickFrequency="0.125" TickPlacement="BottomRight" PreviewMouseUp="uiScalingFactor_PreviewMouseUp" PreviewKeyUp="uiScalingFactor_PreviewKeyUp" LargeChange="0.125" SmallChange="0.125" />
5872

59-
<Separator Margin="0,0,0,45"/>
73+
<Separator Margin="0,0,0,30"/>
6074
<Grid HorizontalAlignment="Center">
6175
<Grid.ColumnDefinitions>
6276
<ColumnDefinition Width="*"/>

CompactGUI/Components/Settings/Settings_main.xaml.vb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Class Settings_main
1313
uiIsContextEnabled.IsChecked = SettingsHandler.AppSettings.IsContextIntegrated
1414
uiIsStartMenuEnabled.IsChecked = SettingsHandler.AppSettings.IsStartMenuEnabled
1515
uiShowNotifications.IsChecked = SettingsHandler.AppSettings.ShowNotifications
16+
uiEnableBackgroundWatcher.IsChecked = SettingsHandler.AppSettings.EnableBackgroundWatcher
17+
uiEnableBackgroundAutoCompression.IsChecked = SettingsHandler.AppSettings.EnableBackgroundAutoCompression
1618
comboBoxSkipUserResultsAggression.SelectedIndex = SettingsHandler.AppSettings.SkipUserFileTypesLevel
1719
uiScalingFactor.Value = SettingsHandler.AppSettings.WindowScalingFactor
1820
SetEnv()
@@ -92,4 +94,26 @@ Class Settings_main
9294
Process.Start(New ProcessStartInfo("https://github.com/IridiumIO/CompactGUI") With {.UseShellExecute = True})
9395

9496
End Sub
97+
98+
Private Sub uiEnableBackgroundWatcher_Checked(sender As Object, e As RoutedEventArgs)
99+
SettingsHandler.AppSettings.EnableBackgroundWatcher = True
100+
SettingsHandler.AppSettings.Save()
101+
End Sub
102+
103+
Private Sub uiEnableBackgroundWatcher_Unchecked(sender As Object, e As RoutedEventArgs)
104+
uiEnableBackgroundAutoCompression.IsChecked = False
105+
SettingsHandler.AppSettings.EnableBackgroundWatcher = False
106+
SettingsHandler.AppSettings.Save()
107+
End Sub
108+
109+
Private Sub uiEnableBackgroundAutoCompression_Checked(sender As Object, e As RoutedEventArgs)
110+
uiEnableBackgroundWatcher.IsChecked = True
111+
SettingsHandler.AppSettings.EnableBackgroundAutoCompression = True
112+
SettingsHandler.AppSettings.Save()
113+
End Sub
114+
115+
Private Sub uiEnableBackgroundAutoCompression_Unchecked(sender As Object, e As RoutedEventArgs)
116+
SettingsHandler.AppSettings.EnableBackgroundAutoCompression = False
117+
SettingsHandler.AppSettings.Save()
118+
End Sub
95119
End Class

CompactGUI/Models/SetttingsHandler.vb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ Public Class Settings : Inherits ObservableObject
9696
Public Property IsStartMenuEnabled As Boolean = False
9797
Public Property SkipUserFileTypesLevel As Integer = 0
9898
Public Property ShowNotifications As Boolean = False
99+
100+
Private _EnableBackgroundWatcher As Boolean = True
101+
Public Property EnableBackgroundWatcher As Boolean
102+
Get
103+
Return _EnableBackgroundWatcher
104+
End Get
105+
Set(value As Boolean)
106+
_EnableBackgroundWatcher = value
107+
Watcher.Watcher.IsWatchingEnabled = value
108+
End Set
109+
End Property
110+
111+
Private _EnableBackgroundAutoCompression As Boolean = True
112+
Public Property EnableBackgroundAutoCompression As Boolean
113+
Get
114+
Return _EnableBackgroundAutoCompression
115+
End Get
116+
Set(value As Boolean)
117+
_EnableBackgroundAutoCompression = value
118+
Watcher.Watcher.IsBackgroundCompactingEnabled = value
119+
End Set
120+
End Property
121+
99122
Private _WindowScalingFactor = 1
100123
Public Property WindowScalingFactor As Double
101124
Get

0 commit comments

Comments
 (0)