Skip to content

Commit

Permalink
Deferred settings application system + new shortcut settings
Browse files Browse the repository at this point in the history
this system took way too much effort to think of for some reason idk why
  • Loading branch information
pizzaboxer committed Aug 12, 2024
1 parent f3110f4 commit 7e95fb4
Show file tree
Hide file tree
Showing 13 changed files with 354 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Bloxstrap/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Win32;

using Bloxstrap.Resources;
using Bloxstrap.Models.SettingTasks;

namespace Bloxstrap
{
Expand Down Expand Up @@ -32,6 +33,8 @@ public partial class App : Application

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();
Expand Down
47 changes: 47 additions & 0 deletions Bloxstrap/Models/SettingTasks/BaseTask.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
17 changes: 17 additions & 0 deletions Bloxstrap/Models/SettingTasks/ISettingTask.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
35 changes: 35 additions & 0 deletions Bloxstrap/Models/SettingTasks/ShortcutTask.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
98 changes: 76 additions & 22 deletions Bloxstrap/Resources/Strings.Designer.cs

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

30 changes: 24 additions & 6 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>
9 changes: 5 additions & 4 deletions Bloxstrap/UI/Elements/Installer/Pages/InstallPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions Bloxstrap/UI/Elements/Settings/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion Bloxstrap/UI/Elements/Settings/Pages/FastFlagsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
Loading

0 comments on commit 7e95fb4

Please sign in to comment.