From c74bc60209913687946d943f118c63d456566cc3 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 24 Feb 2025 22:02:58 +0100 Subject: [PATCH] Add login/logout button to plugin manger to sync subscriptions --- src/DesktopMagic/AutoStart.ps1 | 42 +++++ .../DataContexts/PluginEntryDataContext.cs | 3 + .../DataContexts/PluginManagerDataContext.cs | 14 ++ src/DesktopMagic/Plugins/PluginManager.xaml | 8 +- .../Plugins/PluginManager.xaml.cs | 153 ++++++++++++++++-- .../Resources/Strings/StringResources.de.xaml | 4 + .../Resources/Strings/StringResources.en.xaml | 4 + .../Settings/DesktopMagicSettings.cs | 2 + 8 files changed, 219 insertions(+), 11 deletions(-) create mode 100644 src/DesktopMagic/AutoStart.ps1 diff --git a/src/DesktopMagic/AutoStart.ps1 b/src/DesktopMagic/AutoStart.ps1 new file mode 100644 index 0000000..f007105 --- /dev/null +++ b/src/DesktopMagic/AutoStart.ps1 @@ -0,0 +1,42 @@ +param( + [string]$AppPath, + [switch]$Enable, + [switch]$Disable +) + +# Validate input +if ([string]::IsNullOrWhiteSpace($AppPath) -or !(Test-Path $AppPath)) { + exit 5 # Invalid app path +} + +$AppName = [System.IO.Path]::GetFileNameWithoutExtension($AppPath) +$StartupPath = [Environment]::GetFolderPath('Startup') +$ShortcutPath = Join-Path $StartupPath "$AppName.lnk" + +try { + if ($Enable) { + if (Test-Path $ShortcutPath) { + exit 2 # Already enabled + } + + $WshShell = New-Object -ComObject WScript.Shell + $Shortcut = $WshShell.CreateShortcut($ShortcutPath) + $Shortcut.TargetPath = $AppPath + $Shortcut.Save() + exit 0 # Success + } + elseif ($Disable) { + if (!(Test-Path $ShortcutPath)) { + exit 3 # Already disabled + } + + Remove-Item $ShortcutPath -Force + exit 0 # Success + } + else { + exit 1 # Invalid parameters + } +} +catch { + exit 4 # Unexpected error +} \ No newline at end of file diff --git a/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs b/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs index 500f301..ce5e5df 100644 --- a/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs +++ b/src/DesktopMagic/DataContexts/PluginEntryDataContext.cs @@ -33,6 +33,9 @@ internal class PluginEntryDataContext(PluginMetadata pluginMetadata, ICommand co public uint Id => pluginMetadata.Id; + public string? Path => path; + + public bool IsLocalPlugin => string.IsNullOrWhiteSpace(pluginMetadata.ProfileUri?.ToString()); public ICommand Command => command; public ButtonData InstallUninstallButtonData => new(mode == Mode.Install ? PackIconKind.Download : PackIconKind.Remove, GetInstallUninstallButtonText(), true, Command); diff --git a/src/DesktopMagic/DataContexts/PluginManagerDataContext.cs b/src/DesktopMagic/DataContexts/PluginManagerDataContext.cs index ac1cdfb..b1ca54f 100644 --- a/src/DesktopMagic/DataContexts/PluginManagerDataContext.cs +++ b/src/DesktopMagic/DataContexts/PluginManagerDataContext.cs @@ -12,6 +12,7 @@ internal class PluginManagerDataContext : INotifyPropertyChanged private string installedPluginsSearchText = string.Empty; private bool isLoading = true; private bool isSearching; + private bool isAuthenticated = false; public ObservableCollection AllPlugins { get; } = []; public ObservableCollection InstalledPlugins { get; } = []; @@ -58,6 +59,19 @@ internal class PluginManagerDataContext : INotifyPropertyChanged } } + public bool IsAuthenticated + { + get => isAuthenticated; + set + { + isAuthenticated = value; + OnPropertyChanged(); + OnPropertyChanged(nameof(LoginButtonText)); + } + } + + public string LoginButtonText => isAuthenticated ? (string)App.LanguageDictionary["logout"] : (string)App.LanguageDictionary["login"]; + protected void OnPropertyChanged([CallerMemberName] string? name = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); diff --git a/src/DesktopMagic/Plugins/PluginManager.xaml b/src/DesktopMagic/Plugins/PluginManager.xaml index baba24a..8031cac 100644 --- a/src/DesktopMagic/Plugins/PluginManager.xaml +++ b/src/DesktopMagic/Plugins/PluginManager.xaml @@ -98,7 +98,13 @@ - +