Skip to content

Commit

Permalink
Improve stability and codebase, and add bypass MinSize setting
Browse files Browse the repository at this point in the history
  • Loading branch information
GetGet99 committed May 22, 2024
1 parent 5cd0e69 commit 72f77d7
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 257 deletions.
32 changes: 4 additions & 28 deletions UnitedSets/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,30 @@
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using UnitedSets.Classes;
using UnitedSets.Helpers;
using UnitedSets.Mvvm.Services;
using UnitedSets.Services;
using UnitedSets.UI.AppWindows;
using Windows.Storage;
using WinRT;
using WinUIEx;

namespace UnitedSets;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
public static SettingsService SettingsService { get; } = SettingsService.Settings;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
Directory.CreateDirectory(USConfig.AppDataPath);
InitializeComponent();

cfg = new();
if (!cfg.LoadPreviousSessionData())
cfg.LoadInitialSettingsAndTheme();
// Ensure initialized
UnitedSetsApp app = UnitedSetsApp.Current;
#if DEBUG
RequestAttachDebugger();
#else

UnhandledException += OnUnhandledException;
TaskScheduler.UnobservedTaskException += OnUnobservedException;
AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
#endif
}
private PreservedTabDataService cfg;

async static void RequestAttachDebugger()
{
Expand All @@ -60,7 +36,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
{
//DebugRedir.Listen();
//if (Constants.IsFirstRun)
//LaunchNewOOBE();
// LaunchNewOOBE();
//else
LaunchNewMain();
}
Expand All @@ -74,7 +50,7 @@ void LaunchNewOOBE()

public void LaunchNewMain()
{
var window = new MainWindow(cfg);
var window = new MainWindow();
window.Activate();
}

Expand Down
11 changes: 9 additions & 2 deletions UnitedSets/UnitedSetsApp.cs → UnitedSets/App/UnitedSetsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics;
using System.Threading.Tasks;
using UnitedSets.Services;
using UnitedSets.Classes;
using UnitedSets.Mvvm.Services;

namespace UnitedSets;

partial class UnitedSetsApp : INotifyPropertyChanged
{
// singleton setup
private UnitedSetsApp() { }
private UnitedSetsApp() {
Settings = new();
Configuration = new();
}
public UnitedSetsAppSettings Settings { get; } = new();
public UnitedSetsAppConfiguration Configuration { get; } = new();
public static UnitedSetsApp Current { get; } = new();
readonly List<Window> _allWindows = [];

Expand All @@ -42,7 +50,6 @@ public void RegisterUnitedSetsWindow(MainWindow window)
{
return Tabs.ToArray().FirstOrDefault(tab => tab.Windows.Contains(window));
}

[DoesNotReturn]
public async Task Suicide()
{
Expand Down
28 changes: 28 additions & 0 deletions UnitedSets/App/UnitedSetsAppConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Threading.Tasks;
using UnitedSets.Classes;
using UnitedSets.Services;

namespace UnitedSets;

class UnitedSetsAppConfiguration
{
public UnitedSetsAppConfiguration()
{
PersistantService = new();
if (!PersistantService.LoadPreviousSessionData(out var cfg))
PersistantService.LoadInitialSettingsAndTheme(out cfg);
MainConfiguration = cfg;
}
public PreservedTabDataService PersistantService { get; }
public USConfig MainConfiguration { get; private set; } = null!;
public void SaveCurSettingsAsDefault() => PersistantService.ExportSettings(USConfig.DefaultConfigFile, true, true);//don't give user any choice as to what for now so will exclude current tabs
public async Task ResetSettingsToDefault()
{
await PersistantService.ResetSettings();
SaveCurSettingsAsDefault();
}
public void SaveCurrentSession()
{
PersistantService.ExportSettings(USConfig.SessionSaveConfigFile, true, ExcludeTabs: false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
using UnitedSets.Settings;
using Cube.UI.Icons;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Composition.SystemBackdrops;
Expand All @@ -17,15 +15,14 @@

namespace UnitedSets.Mvvm.Services;

public partial class SettingsService
public partial class UnitedSetsAppSettings
{
public static SettingsService Settings { get; } = new();
public USConfig cfg { get; set; } = null!;
private SettingsService()
private static USConfig Configuration => UnitedSetsApp.Current.Configuration.PersistantService.MainConfiguration;
public UnitedSetsAppSettings()
{
AllSettings = [
CloseWindowOnCloseTab = new(
() => cfg.CloseWindowOnCloseTab, x => cfg.CloseWindowOnCloseTab = x
() => Configuration.CloseWindowOnCloseTab, x => Configuration.CloseWindowOnCloseTab = x
)
{
Title = "Closing tab closes window",
Expand All @@ -41,15 +38,23 @@ private SettingsService()
// Icon = SymbolEx.PPSOneLandscape,
// RequiresRestart = true
//},
BypassMinimumSize = new(() => Configuration.BypassMinSize, x => Configuration.BypassMinSize = x) {
Title = "Bypass Minimum Size",
Description = $"Allows resizing the window down to {
Constants.BypassMinWidth}x{Constants.BypassMinHeight
} (Normal minimum size is {
Constants.MinWidth}x{Constants.MinHeight})",
Icon = SymbolEx.ResizeMouseSmall
},
BackdropMode = new(
() => cfg.Design!.Backdrop, x => cfg.Design!.Backdrop = x, Enums.GetValues<USBackdrop>()
() => Configuration.Design!.Backdrop, x => Configuration.Design!.Backdrop = x, Enums.GetValues<USBackdrop>()
) {
Title = "Window Background",
Description = "Select the Window Background (NOTE: Changing to Transparent requires restart)",
Icon = SymbolEx.Color
},
WindowTitlePrefix = new(
() => cfg.TitlePrefix ?? "", x => cfg.TitlePrefix = x
() => Configuration.TitlePrefix ?? "", x => Configuration.TitlePrefix = x
)
{
Title = "Window Title Prefix",
Expand All @@ -58,7 +63,7 @@ private SettingsService()
PlaceholderText = "None - Normal Title Mode"
},
Theme = new(
() => cfg.Design.Theme ?? ElementTheme.Default, x => cfg.Design.Theme = x,
() => Configuration.Design!.Theme ?? ElementTheme.Default, x => Configuration.Design!.Theme = x,
Enums.GetValues<ElementTheme>()
)
{
Expand All @@ -72,7 +77,8 @@ private SettingsService()
public IReadOnlyList<Setting> AllSettings { get; }

public OnOffSetting CloseWindowOnCloseTab { get; }
public OnOffSetting TransculentWindow { get; }
public OnOffSetting BypassMinimumSize { get; }
//public OnOffSetting TransculentWindow { get; }
public TextSetting WindowTitlePrefix { get; }
public SelectSetting<ElementTheme> Theme { get; }

Expand Down
5 changes: 4 additions & 1 deletion UnitedSets/Classes/PreservedDataClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ protected SavedInstanceData _CloneWithoutTabs() {
[AutoNotifyProperty]
public bool _CloseWindowOnCloseTab;

public event PropertyChangedEventHandler? PropertyChanged;
[AutoNotifyProperty]
public bool _BypassMinSize;

public event PropertyChangedEventHandler? PropertyChanged;

public SavedTabData[]? Tabs { get; set; }
public SavedTabData? DefaultTabData { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions UnitedSets/Classes/USConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class USConfig : SavedInstanceData {
public USConfig CloneWithoutTabs() {
return (USConfig)_CloneWithoutTabs();
}
public static bool FLAGS_THEME_CHOICE_ENABLED = true;// ughz https://github.com/microsoft/WindowsAppSDK/issues/3487 https://github.com/microsoft/microsoft-ui-xaml/issues/8249 although even setting it at the app level doesnt work
public static bool FLAGS_THEME_CHOICE_ENABLED { get; } = true;// ughz https://github.com/microsoft/WindowsAppSDK/issues/3487 https://github.com/microsoft/microsoft-ui-xaml/issues/8249 although even setting it at the app level doesnt work
public static string BaseProfileFolder => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UnitedSets");
public static string DefaultConfigFile => Path.Combine(BaseProfileFolder, "default.json");
public static string AppDataPath => Path.Combine(
Expand All @@ -35,11 +35,11 @@ public USConfig CloneWithoutTabs() {
WindowsOG.ApplicationModel.Package.Current.InstalledLocation.Path;
#endif

public static USConfig def_config { get; private set; }
public static USConfig DefaultConfiguration { get; private set; }
internal static void LoadDefaultConfig() {
if (!Directory.Exists(BaseProfileFolder))
Directory.CreateDirectory(BaseProfileFolder);
def_config = new() {
DefaultConfiguration = new() {
TitlePrefix = "", TaskbarIco = "Assets/UnitedSets.ico", Tabs = [], Design = new() {
BorderCorner = new(15, 5, 15, 5), BorderGradiant1 = "#9987C7FF", BorderGradiant2 = "#9900008B", BorderThickness = new(10),
MainMargin = new(8, 0, 8, 8), PrimaryBackgroundLightTheme = "#DDFFFFFF", PrimaryBackgroundDarkTheme = "#DD000000", PrimaryBackgroundNonTranslucent = "White",
Expand Down
3 changes: 3 additions & 0 deletions UnitedSets/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ static class Constants
public static readonly WindowMessages UnitedSetCommunicationChangeWindowOwnership
= WindowMessagesHelper.Register(nameof(UnitedSetCommunicationChangeWindowOwnership));

public const int MinWidth = 600, MinHeight = 500;
public const int BypassMinWidth = 100, BypassMinHeight = 100;

static readonly Lazy<bool> _IsFirstRun = new(delegate
{
var isFirstRun = false;
Expand Down
2 changes: 1 addition & 1 deletion UnitedSets/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"UnitedSets (Packaged)": {
"commandName": "MsixPackage",
"nativeDebugging": false
"nativeDebugging": true
},
"AddNotepad (Packaged)": {
"commandName": "MsixPackage",
Expand Down
Loading

0 comments on commit 72f77d7

Please sign in to comment.