-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ChatPrisma.Services.AutoStart; | ||
|
||
public interface IAutoStartService | ||
{ | ||
Task<bool> IsInAutoStart(); | ||
Task SetAutoStart(bool enabled); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/ChatPrisma/Services/AutoStart/RegistryAutoStartService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using ChatPrisma.Options; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.Win32; | ||
|
||
namespace ChatPrisma.Services.AutoStart; | ||
|
||
public class RegistryAutoStartService(IOptions<ApplicationOptions> applicationOptions) : IAutoStartService | ||
{ | ||
public async Task<bool> IsInAutoStart() | ||
{ | ||
await Task.CompletedTask; | ||
|
||
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", writable: false); | ||
var result = key?.GetValue(applicationOptions.Value.ApplicationName) is not null; | ||
|
||
// If auto-start is enabled, ensure that we have the correct application path in the registry | ||
// We do that by just enabling auto-start again | ||
if (result is true) | ||
{ | ||
await this.SetAutoStart(true); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public async Task SetAutoStart(bool enabled) | ||
{ | ||
await Task.CompletedTask; | ||
|
||
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", writable: true) ?? | ||
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); | ||
|
||
if (enabled) | ||
{ | ||
key.SetValue(applicationOptions.Value.ApplicationName, $"\"{Environment.ProcessPath}\""); | ||
} | ||
else | ||
{ | ||
key.DeleteValue(applicationOptions.Value.ApplicationName, throwOnMissingValue: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace ChatPrisma.Services.Dialogs; | ||
namespace ChatPrisma.Services.Dialogs; | ||
|
||
public interface IDialogService | ||
{ | ||
bool? ShowDialog(object viewModel); | ||
} | ||
Task<bool?> ShowDialog(object viewModel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ChatPrisma.Services.Dialogs; | ||
|
||
public interface IInitialize | ||
{ | ||
Task InitializeAsync(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
<UserControl x:Class="ChatPrisma.Views.Settings.SettingsView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:local="clr-namespace:ChatPrisma.Views.Settings" | ||
xmlns:wpf="clr-namespace:FluentIcons.WPF;assembly=FluentIcons.WPF" | ||
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:themes="clr-namespace:ChatPrisma.Themes" | ||
|
||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:ChatPrisma.Views.Settings" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" d:DesignWidth="300" | ||
d:DataContext="{d:DesignInstance local:SettingsViewModel}"> | ||
<Grid> | ||
<TextBox Text="{Binding Test}" /> | ||
</Grid> | ||
|
||
d:DataContext="{d:DesignInstance local:SettingsViewModel}" | ||
|
||
themes:Attached.WindowTitle="Einstellungen" | ||
|
||
Width="300"> | ||
<UserControl.Resources> | ||
<dxmvvm:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" /> | ||
<dxmvvm:BooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" Inverse="True" /> | ||
</UserControl.Resources> | ||
|
||
<StackPanel> | ||
<GroupBox Header="Autostart"> | ||
<Grid> | ||
<StackPanel Visibility="{Binding IsAutoStartActive, Converter={StaticResource BooleanToVisibilityConverter}}" | ||
Orientation="Horizontal"> | ||
<TextBlock Text="Autostart ist aktiviert" /> | ||
<wpf:SymbolIcon Symbol="Checkmark" Foreground="Green" /> | ||
<Button Content="Deaktivieren" Command="{Binding DisableAutoStartCommand}" /> | ||
</StackPanel> | ||
<StackPanel Visibility="{Binding IsAutoStartActive, Converter={StaticResource InverseBooleanToVisibilityConverter}}" | ||
Orientation="Horizontal"> | ||
<TextBlock Text="Autostart ist deaktiviert" /> | ||
<wpf:SymbolIcon Symbol="ClockDismiss" Foreground="Red" /> | ||
<Button Content="Aktivieren" Command="{Binding EnableAutoStartCommand}" /> | ||
</StackPanel> | ||
</Grid> | ||
</GroupBox> | ||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
using ChatPrisma.Services.AutoStart; | ||
using ChatPrisma.Services.Dialogs; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
namespace ChatPrisma.Views.Settings; | ||
|
||
public partial class SettingsViewModel : ObservableObject | ||
public partial class SettingsViewModel(IAutoStartService autoStartService) : ObservableObject, IInitialize | ||
{ | ||
[ObservableProperty] | ||
private bool _isAutoStartActive; | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
this.IsAutoStartActive = await autoStartService.IsInAutoStart(); | ||
} | ||
|
||
[RelayCommand] | ||
private async Task EnableAutoStart() | ||
{ | ||
await autoStartService.SetAutoStart(true); | ||
this.IsAutoStartActive = true; | ||
} | ||
|
||
[RelayCommand] | ||
private async Task DisableAutoStart() | ||
{ | ||
await autoStartService.SetAutoStart(false); | ||
this.IsAutoStartActive = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters