Deferred settings application system + new shortcut settings

this system took way too much effort to think of for some reason idk why
This commit is contained in:
pizzaboxer 2024-08-13 00:03:39 +01:00
parent f3110f4b48
commit 7e95fb4d8f
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
13 changed files with 354 additions and 33 deletions

View File

@ -5,6 +5,7 @@ using System.Windows.Threading;
using Microsoft.Win32;
using Bloxstrap.Resources;
using Bloxstrap.Models.SettingTasks;
namespace Bloxstrap
{
@ -32,6 +33,8 @@ namespace Bloxstrap
public static readonly Logger Logger = new();
public static readonly Dictionary<string, ISettingTask> PendingSettingTasks = new();
public static readonly JsonManager<Settings> Settings = new();
public static readonly JsonManager<State> State = new();

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Models.SettingTasks
{
public class BaseTask : ISettingTask
{
private bool _originalState;
private bool _newState;
public string Name { get; set; } = "";
public bool OriginalState
{
get
{
return _originalState;
}
set
{
_originalState = value;
_newState = value;
}
}
public bool NewState
{
get
{
return _newState;
}
set
{
App.PendingSettingTasks[Name] = this;
_newState = value;
}
}
public virtual void Execute() => throw new NotImplementedException();
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Models.SettingTasks
{
public interface ISettingTask
{
public bool OriginalState { get; set; }
public bool NewState { get; set; }
public void Execute();
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap.Models.SettingTasks
{
public class ShortcutTask : BaseTask, ISettingTask
{
public string ExeFlags { get; set; } = "";
public string ShortcutPath { get; set; }
public ShortcutTask(string shortcutPath)
{
ShortcutPath = shortcutPath;
OriginalState = File.Exists(ShortcutPath);
}
public override void Execute()
{
if (NewState == OriginalState)
return;
if (NewState)
Shortcut.Create(Paths.Application, ExeFlags, ShortcutPath);
else
File.Delete(ShortcutPath);
OriginalState = NewState;
}
}
}

View File

@ -512,6 +512,33 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Shortcuts.
/// </summary>
public static string Common_Shortcuts {
get {
return ResourceManager.GetString("Common.Shortcuts", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Desktop icon.
/// </summary>
public static string Common_Shortcuts_Desktop {
get {
return ResourceManager.GetString("Common.Shortcuts.Desktop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Start Menu icon.
/// </summary>
public static string Common_Shortcuts_StartMenu {
get {
return ResourceManager.GetString("Common.Shortcuts.StartMenu", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to System default.
/// </summary>
@ -685,7 +712,7 @@ namespace Bloxstrap.Resources {
}
/// <summary>
/// Looks up a localized string similar to Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through Bloxstrap Settings..
/// Looks up a localized string similar to Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through the settings..
/// </summary>
public static string Dialog_CannotCreateShortcuts {
get {
@ -1274,29 +1301,11 @@ namespace Bloxstrap.Resources {
}
/// <summary>
/// Looks up a localized string similar to Create Desktop shortcuts.
/// Looks up a localized string similar to These are general shortcuts that bring up a multi-choice launch menu. Shortcuts for specific functions can be created later in the settings..
/// </summary>
public static string Installer_Install_Shortcuts_Desktop {
public static string Installer_Install_Shortcuts_Description {
get {
return ResourceManager.GetString("Installer.Install.Shortcuts.Desktop", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Create Start Menu shortcuts.
/// </summary>
public static string Installer_Install_Shortcuts_StartMenu {
get {
return ResourceManager.GetString("Installer.Install.Shortcuts.StartMenu", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Shortcuts.
/// </summary>
public static string Installer_Install_Shortcuts_Title {
get {
return ResourceManager.GetString("Installer.Install.Shortcuts.Title", resourceCulture);
return ResourceManager.GetString("Installer.Install.Shortcuts.Description", resourceCulture);
}
}
@ -2850,6 +2859,51 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Configure how Bloxstrap can be readily launched..
/// </summary>
public static string Menu_Shortcuts_Description {
get {
return ResourceManager.GetString("Menu.Shortcuts.Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Create shortcuts for quick access to specific functions. These will all be placed on the Desktop..
/// </summary>
public static string Menu_Shortcuts_Function_Description {
get {
return ResourceManager.GetString("Menu.Shortcuts.Function.Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Function.
/// </summary>
public static string Menu_Shortcuts_Function_Title {
get {
return ResourceManager.GetString("Menu.Shortcuts.Function.Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to These are the shortcuts that bring up the multi-choice launch menu..
/// </summary>
public static string Menu_Shortcuts_General_Description {
get {
return ResourceManager.GetString("Menu.Shortcuts.General.Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to General.
/// </summary>
public static string Menu_Shortcuts_General_Title {
get {
return ResourceManager.GetString("Menu.Shortcuts.General.Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Bloxstrap Settings.
/// </summary>

View File

@ -1025,14 +1025,14 @@ This installation process will be quick and simple, and you will be able to conf
<data name="Installer.Install.Location.DataFound" xml:space="preserve">
<value>Existing data found. Your mods and settings will be restored.</value>
</data>
<data name="Installer.Install.Shortcuts.Title" xml:space="preserve">
<data name="Common.Shortcuts" xml:space="preserve">
<value>Shortcuts</value>
</data>
<data name="Installer.Install.Shortcuts.Desktop" xml:space="preserve">
<value>Create Desktop shortcuts</value>
<data name="Common.Shortcuts.Desktop" xml:space="preserve">
<value>Desktop icon</value>
</data>
<data name="Installer.Install.Shortcuts.StartMenu" xml:space="preserve">
<value>Create Start Menu shortcuts</value>
<data name="Common.Shortcuts.StartMenu" xml:space="preserve">
<value>Start Menu icon</value>
</data>
<data name="Installer.Completion.Text" xml:space="preserve">
<value>Bloxstrap has successfully been installed.
@ -1095,11 +1095,29 @@ Bloxstrap was installed at "{1}".</value>
<value>You currently do not have the WebView2 runtime installed. Some Roblox features will not work properly without it, such as the desktop app. Would you like to download it now?</value>
</data>
<data name="Dialog.CannotCreateShortcuts" xml:space="preserve">
<value>Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through Bloxstrap Settings.</value>
<value>Bloxstrap was unable to create shortcuts for the Desktop and Start menu. Try creating them later through the settings.</value>
</data>
<data name="Dialog.Exception.Info.2.Alt" xml:space="preserve">
<value>Check the [Bloxstrap Wiki]({0}) first to see if this problem has already been addressed with a fix.
If not, then please report this exception to the maintainers of this fork. Do NOT report this to Bloxstrap's GitHub issues, as this is an unoffical build.</value>
</data>
<data name="Installer.Install.Shortcuts.Description" xml:space="preserve">
<value>These are general shortcuts that bring up a multi-choice launch menu. Shortcuts for specific functions can be created later in the settings.</value>
</data>
<data name="Menu.Shortcuts.Description" xml:space="preserve">
<value>Configure how Bloxstrap can be readily launched.</value>
</data>
<data name="Menu.Shortcuts.General.Title" xml:space="preserve">
<value>General</value>
</data>
<data name="Menu.Shortcuts.General.Description" xml:space="preserve">
<value>These are the shortcuts that bring up the multi-choice launch menu.</value>
</data>
<data name="Menu.Shortcuts.Function.Title" xml:space="preserve">
<value>Function</value>
</data>
<data name="Menu.Shortcuts.Function.Description" xml:space="preserve">
<value>Create shortcuts for quick access to specific functions. These will all be placed on the Desktop.</value>
</data>
</root>

View File

@ -35,7 +35,7 @@
</ui:Card>
<TextBlock Margin="0,8,0,0" FontSize="14" Text="{x:Static resources:Strings.Installer_Install_Location_DataFound}" Visibility="{Binding DataFoundMessageVisibility, Mode=OneWay}" TextWrapping="Wrap" />
<TextBlock FontSize="14" Text="{Binding ErrorMessage, Mode=OneWay}" Foreground="{DynamicResource SystemFillColorCriticalBrush}" TextWrapping="Wrap" Margin="0,4,0,0">
<TextBlock Margin="0,8,0,0" FontSize="14" Text="{Binding ErrorMessage, Mode=OneWay}" Foreground="{DynamicResource SystemFillColorCriticalBrush}" TextWrapping="Wrap">
<TextBlock.Style>
<Style>
<Style.Triggers>
@ -47,15 +47,16 @@
</TextBlock.Style>
</TextBlock>
<TextBlock FontSize="20" FontWeight="SemiBold" Text="{x:Static resources:Strings.Installer_Install_Shortcuts_Title}" TextWrapping="Wrap" Margin="0,16,0,0" />
<TextBlock FontSize="20" FontWeight="SemiBold" Text="{x:Static resources:Strings.Common_Shortcuts}" TextWrapping="Wrap" Margin="0,16,0,0" />
<TextBlock FontSize="14" Text="{x:Static resources:Strings.Installer_Install_Shortcuts_Description}" TextWrapping="Wrap" />
<controls:OptionControl
Header="{x:Static resources:Strings.Installer_Install_Shortcuts_Desktop}">
Header="{x:Static resources:Strings.Common_Shortcuts_Desktop}">
<ui:ToggleSwitch IsChecked="{Binding CreateDesktopShortcuts, Mode=TwoWay}" />
</controls:OptionControl>
<controls:OptionControl
Header="{x:Static resources:Strings.Installer_Install_Shortcuts_StartMenu}">
Header="{x:Static resources:Strings.Common_Shortcuts_StartMenu}">
<ui:ToggleSwitch IsChecked="{Binding CreateStartMenuShortcuts, Mode=TwoWay}" />
</controls:OptionControl>
</StackPanel>

View File

@ -55,6 +55,7 @@
<ui:NavigationItem Content="{x:Static resources:Strings.Menu_FastFlags_Title}" PageType="{x:Type pages:FastFlagsPage}" Icon="Flag24" Tag="fastflags" />
<ui:NavigationItem Content="{x:Static resources:Strings.Menu_Appearance_Title}" PageType="{x:Type pages:AppearancePage}" Icon="PaintBrush24" Tag="appearance" />
<ui:NavigationItem Content="{x:Static resources:Strings.Menu_Behaviour_Title}" PageType="{x:Type pages:BehaviourPage}" Icon="Settings24" Tag="behaviour" />
<ui:NavigationItem Content="{x:Static resources:Strings.Common_Shortcuts}" PageType="{x:Type pages:ShortcutsPage}" Icon="Apps28" Tag="shortcuts" />
<ui:NavigationItem Content="{x:Static resources:Strings.Menu_FastFlagEditor_Title}" PageType="{x:Type pages:FastFlagEditorPage}" Tag="fastflageditor" Visibility="Collapsed" />
<ui:NavigationItem Content="" PageType="{x:Type pages:FastFlagEditorWarningPage}" Tag="fastflageditorwarning" Visibility="Collapsed" x:Name="EditorWarningNavItem" />

View File

@ -51,9 +51,9 @@
</StackPanel>
<TextBlock Text="{x:Static resources:Strings.Common_Presets}" FontSize="20" FontWeight="Medium" Margin="0,16,0,0" />
<controls:MarkdownTextBlock MarkdownText="{Binding Source={x:Static resources:Strings.Menu_FastFlags_Presets_D3DExclusiveFullscreenInfo}, Converter={StaticResource StringFormatConverter}, ConverterParameter='https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#exclusive-fullscreen'}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<TextBlock Text="{x:Static resources:Strings.Menu_FastFlags_Presets_Categories_Rendering}" FontSize="16" FontWeight="Medium" Margin="0,16,0,0" />
<controls:MarkdownTextBlock MarkdownText="{Binding Source={x:Static resources:Strings.Menu_FastFlags_Presets_D3DExclusiveFullscreenInfo}, Converter={StaticResource StringFormatConverter}, ConverterParameter='https://github.com/pizzaboxer/bloxstrap/wiki/A-guide-to-FastFlags#exclusive-fullscreen'}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<controls:OptionControl
Header="{x:Static resources:Strings.Menu_FastFlags_Presets_MSAA_Title}">

View File

@ -0,0 +1,55 @@
<ui:UiPage x:Class="Bloxstrap.UI.Elements.Settings.Pages.ShortcutsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.Settings.Pages"
xmlns:controls="clr-namespace:Bloxstrap.UI.Elements.Controls"
xmlns:models="clr-namespace:Bloxstrap.UI.ViewModels.Settings"
xmlns:resources="clr-namespace:Bloxstrap.Resources"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
Title="ShortcutsPage"
Scrollable="True">
<StackPanel Margin="0,0,14,14">
<TextBlock Margin="0,0,0,16" Text="{x:Static resources:Strings.Menu_Shortcuts_Description}" FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_General_Title}" FontSize="20" FontWeight="Medium" />
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_General_Description}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:OptionControl Grid.Column="0" Margin="0,0,4,0" Header="{x:Static resources:Strings.Common_Shortcuts_Desktop}">
<ui:ToggleSwitch IsChecked="{Binding DesktopIcon, Mode=TwoWay}" />
</controls:OptionControl>
<controls:OptionControl Grid.Column="1" Margin="4,0,0,0" Header="{x:Static resources:Strings.Common_Shortcuts_StartMenu}">
<ui:ToggleSwitch IsChecked="{Binding StartMenuIcon, Mode=TwoWay}" />
</controls:OptionControl>
</Grid>
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_Function_Title}" FontSize="20" FontWeight="Medium" Margin="0,16,0,0" />
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_Function_Description}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:OptionControl Grid.Column="0" Margin="0,0,4,0" Header="{x:Static resources:Strings.LaunchMenu_LaunchRoblox}">
<ui:ToggleSwitch IsChecked="{Binding PlayerIcon, Mode=TwoWay}" />
</controls:OptionControl>
<controls:OptionControl Grid.Column="1" Margin="4,0,0,0" Header="{x:Static resources:Strings.Menu_Title}">
<ui:ToggleSwitch IsChecked="{Binding SettingsIcon, Mode=TwoWay}" />
</controls:OptionControl>
</Grid>
</StackPanel>
</ui:UiPage>

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Bloxstrap.UI.ViewModels.Settings;
namespace Bloxstrap.UI.Elements.Settings.Pages
{
/// <summary>
/// Interaction logic for ShortcutsPage.xaml
/// </summary>
public partial class ShortcutsPage
{
public ShortcutsPage()
{
DataContext = new ShortcutsViewModel();
InitializeComponent();
}
}
}

View File

@ -16,6 +16,11 @@ namespace Bloxstrap.UI.ViewModels.Settings
App.State.Save();
App.FastFlags.Save();
foreach (var task in App.PendingSettingTasks)
task.Value.Execute();
App.PendingSettingTasks.Clear();
RequestSaveNoticeEvent?.Invoke(this, new EventArgs());
}
}

View File

@ -0,0 +1,54 @@
using Bloxstrap.Models.SettingTasks;
using Bloxstrap.Resources;
namespace Bloxstrap.UI.ViewModels.Settings
{
public class ShortcutsViewModel : NotifyPropertyChangedViewModel
{
private ShortcutTask _desktopIconTask = new(Path.Combine(Paths.Desktop, "Bloxstrap.lnk"))
{
Name = "DesktopIcon"
};
private ShortcutTask _startMenuIconTask = new(Path.Combine(Paths.WindowsStartMenu, "Bloxstrap.lnk"))
{
Name = "StartMenuIcon"
};
private ShortcutTask _playerIconTask = new(Path.Combine(Paths.Desktop, $"{Strings.LaunchMenu_LaunchRoblox}.lnk"))
{
Name = "RobloxPlayerIcon",
ExeFlags = "-player"
};
private ShortcutTask _settingsIconTask = new(Path.Combine(Paths.Desktop, $"{Strings.Menu_Title}.lnk"))
{
Name = "SettingsIcon",
ExeFlags = "-settings"
};
public bool DesktopIcon
{
get => _desktopIconTask.NewState;
set => _desktopIconTask.NewState = value;
}
public bool StartMenuIcon
{
get => _startMenuIconTask.NewState;
set => _startMenuIconTask.NewState = value;
}
public bool PlayerIcon
{
get => _playerIconTask.NewState;
set => _playerIconTask.NewState = value;
}
public bool SettingsIcon
{
get => _settingsIconTask.NewState;
set => _settingsIconTask.NewState = value;
}
}
}