Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

name: build
env:
DWAppVersion: v1.7.1r
DWAppVersion: v1.7.2r
permissions:
contents: write

Expand Down
2 changes: 1 addition & 1 deletion DynamicWin/Main/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class DynamicWinMain : System.Windows.Application
public static MMDevice? defaultDevice;
public static MMDevice? defaultMicrophone;

public static string Version => "v1.7.1r";
public static string Version => "v1.7.2r";
public static Channel ReleaseStream => Channel.Release;
public static Architecture ProcessArchitecture => RuntimeInformation.ProcessArchitecture;

Expand Down
69 changes: 41 additions & 28 deletions DynamicWin/Main/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,46 @@ public static HomeMenu.BigMenuMode DefaultBigMenuMode
set => defaultBigMenuMode = value;
}

private static void ApplyDefaultSettings()
{
smallWidgetsLeft = new List<string>();
smallWidgetsRight = new List<string>();
smallWidgetsMiddle = new List<string>();
bigWidgets = new List<string>();

smallWidgetsRight.Add("DynamicWin.UI.Widgets.Small.RegisterSmallVisualiserWidget");
smallWidgetsLeft.Add("DynamicWin.UI.Widgets.Small.RegisterMediaThumbnailWidget");
bigWidgets.Add("DynamicWin.UI.Widgets.Big.RegisterWeatherWidget");
bigWidgets.Add("DynamicWin.UI.Widgets.Big.RegisterTimerWidget");

IslandMode = IslandObject.IslandMode.Island;
AllowBlur = true;
AllowAnimation = true;
AntiAliasing = true;
ToggleHighRefreshRate = false;
LimitRefreshRateWhenIdle = true;
ToggleIslandShadow = true;
ToggleHomeMenuShadow = false;
RunOnStartup = false;
ReleaseStream = 0;
AllowAutomaticUpdates = true;
AlwaysTopmost = true;
ReduceWorkingArea = true;
Theme = 0;
ScreenIndex = 0;
DefaultBigMenuMode = HomeMenu.BigMenuMode.Widgets;

SaveManager.Add("settings", 1);
}

public static void ResetToDefaults()
{
SaveManager.SaveData = new Dictionary<string, object>();
ApplyDefaultSettings();
AfterSettingsLoaded();
Save();
}

public static void InitializeSettings()
{
try
Expand Down Expand Up @@ -176,34 +216,7 @@ public static void InitializeSettings()
}
else
{
smallWidgetsLeft = new List<string>();
smallWidgetsRight = new List<string>();
smallWidgetsMiddle = new List<string>();
bigWidgets = new List<string>();

smallWidgetsRight.Add("DynamicWin.UI.Widgets.Small.RegisterSmallVisualiserWidget");
smallWidgetsLeft.Add("DynamicWin.UI.Widgets.Small.RegisterMediaThumbnailWidget");
bigWidgets.Add("DynamicWin.UI.Widgets.Big.RegisterWeatherWidget");
bigWidgets.Add("DynamicWin.UI.Widgets.Big.RegisterTimerWidget");

IslandMode = IslandObject.IslandMode.Island;
AllowBlur = true;
AllowAnimation = true;
AntiAliasing = true;
ToggleHighRefreshRate = false;
LimitRefreshRateWhenIdle = true;
ToggleIslandShadow = true;
ToggleHomeMenuShadow = false;
ReleaseStream = 0;

// default automatic updates enabled
AllowAutomaticUpdates = true;
AlwaysTopmost = true;
ReduceWorkingArea = true;

Theme = 0;

SaveManager.SaveData.Add("settings", 1);
ApplyDefaultSettings();
}

// This must be run after loading all settings
Expand Down
85 changes: 83 additions & 2 deletions DynamicWin/UI/Menu/Menus/SettingsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using DynamicWin.UI.Widgets;
using DynamicWin.Utils;
using SkiaSharp;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Input;
Expand Down Expand Up @@ -60,6 +61,11 @@ public class SettingsMenu : BaseMenu
private float lastContentSignature = float.NaN;
private float lastIslandWidth = float.NaN;
private float lastIslandHeight = float.NaN;
private DWTextButton resetConfigBtn = null!;
private Col resetConfigNormalColor = null!;
private Col resetConfigHoverColor = null!;
private Col resetConfigClickColor = null!;
private int resetConfigIndexCount = 0;

public SettingsMenu()
{
Expand All @@ -77,6 +83,7 @@ public override List<UIObject> InitializeMenu(IslandObject island)
ySmoothScroll = 0f;
cachedScrollLimit = 0f;
lastContentSignature = float.NaN;
resetConfigIndexCount = 0;

var objects = base.InitializeMenu(island);
var customOptions = LoadCustomOptions();
Expand All @@ -96,8 +103,8 @@ public override List<UIObject> InitializeMenu(IslandObject island)
: IslandObject.IslandMode.Notch;
};

AddBodyText(objects, island, "Renders the interface to its minimum height and width possible, also improves performance.");
AddBodyText(objects, island, "Disabling this setting may prevent the interface from being placed correctly at the top.");
AddBodyText(objects, island, "Renders the interface to its minimum height and width possible if toggled off.");
AddBodyText(objects, island, "Toggling off this setting may prevent the interface from being placed correctly at the top.");

alwaysTopmost = AddCheckbox(objects, island, "Keep interface always topmost", Settings.AlwaysTopmost);
AddBodyText(objects, island, "Prevents the interface from overlapping on top of other windows.");
Expand Down Expand Up @@ -158,6 +165,7 @@ public override List<UIObject> InitializeMenu(IslandObject island)
AddCustomOptions(objects, island, customOptions);

AddReleaseStream(objects, island);
AddConfigurationOptions(objects, island);
AddVersionInfo(objects, island);

objects.Add(new SettingsRenderDemand(island, NeedsRealtimeLayout));
Expand Down Expand Up @@ -432,6 +440,37 @@ private void AddReleaseStream(List<UIObject> objects, IslandObject island)
AddContent(objects, checkForUpdateBtn);
}

private void AddConfigurationOptions(List<UIObject> objects, IslandObject island)
{
AddSectionTitle(objects, island, "Configuration");

var openConfigDirectoryBtn = new DWTextButton(
island,
"Open config directory",
new Vec2(ContentLeft, 0),
new Vec2(IslandSize().X - 360, 32),
OpenConfigDirectory,
UIAlignment.TopLeft);
openConfigDirectoryBtn.Anchor.X = 0;

resetConfigBtn = new DWTextButton(
island,
"Reset config to defaults",
new Vec2(ContentLeft, 0),
new Vec2(IslandSize().X - 360, 32),
ResetConfig,
UIAlignment.TopLeft
);

resetConfigBtn.Anchor.X = 0;
resetConfigNormalColor = resetConfigBtn.normalColor;
resetConfigHoverColor = resetConfigBtn.hoverColor;
resetConfigClickColor = resetConfigBtn.clickColor;

AddContent(objects, openConfigDirectoryBtn);
AddContent(objects, resetConfigBtn);
}

private void AddVersionInfo(List<UIObject> objects, IslandObject island)
{
AddText(objects, island, $"Application version: {DynamicWinMain.Version} ({DynamicWinMain.ReleaseStream.ToFriendlyString()})", 15, Res.SFProBold, Theme.TextMain);
Expand Down Expand Up @@ -495,6 +534,48 @@ private void CheckForUpdate()
});
}

private void OpenConfigDirectory()
{
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string path = Path.Combine(appData, "DynamicWin");

if (Directory.Exists(path))
{
Process.Start(new ProcessStartInfo
{
FileName = path,
UseShellExecute = true
});
}
}

private void ResetConfig()
{
resetConfigIndexCount += 1;

switch (resetConfigIndexCount)
{
case 1:
resetConfigBtn.normalColor = Theme.Error.Override(a: 0.45f);
resetConfigBtn.hoverColor = Theme.Error.Override(a: 0.6f);
resetConfigBtn.clickColor = Theme.Error.Override(a: 0.8f);
resetConfigBtn.Color = resetConfigBtn.normalColor;
resetConfigBtn.Text.SilentSetText("Are you sure");
break;
case 2:
string path = Path.Combine(SaveManager.SavePath, "Settings.json");

if (File.Exists(path))
File.Delete(path);

Settings.ResetToDefaults();
DynamicWinMain.UpdateStartup();
Res.HomeMenu = new HomeMenu();
MenuManager.OpenMenu(Res.HomeMenu);
break;
}
}

private SettingsCheckbox AddCheckbox(
List<UIObject> objects,
IslandObject island,
Expand Down
5 changes: 1 addition & 4 deletions DynamicWin/Utils/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void LoadData()
var json = File.ReadAllText(fullPath);
cachedJsonSave = json;

data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
data = JsonConvert.DeserializeObject<Dictionary<string, object>>(json) ?? new Dictionary<string, object>();
}

public static void SaveAll()
Expand All @@ -47,9 +47,6 @@ public static void SaveAll()
var fullPath = Path.Combine(SavePath, fileName);
var json = JsonConvert.SerializeObject(data, Formatting.Indented);

if (!File.Exists(fullPath))
File.Create(fullPath);

File.WriteAllText(fullPath, json);
}

Expand Down
Loading