From 329d3e494e49747da6703352e96fbd7db2a5bd0a Mon Sep 17 00:00:00 2001
From: "Wesley Pyburn (TechNobo)" <10319195+TcNobo@users.noreply.github.com>
Date: Sat, 26 Jun 2021 12:41:11 +0200
Subject: [PATCH] Bugfix
- Fixed the 'jsRuntime null' error when starting the program. This was an issue with trying to show a message when changing a setting, when the window wasn't even created yet, as well as other minor issues.
- Removed low memory minimize -- The optimizations (destroying and recreating the browser when closing/opening seems to be done automatically... or has changed somewhat to use less ram anyways. My addition to it seems unnesecary)
---
TcNo-Acc-Switcher-Client/App.xaml.cs | 15 +++++++--
TcNo-Acc-Switcher-Client/MainWindow.xaml.cs | 31 +------------------
TcNo-Acc-Switcher-Globals/Globals.cs | 2 +-
TcNo-Acc-Switcher-Server/Data/AppData.cs | 10 +++---
TcNo-Acc-Switcher-Server/Data/AppSettings.cs | 26 ++++++----------
TcNo-Acc-Switcher-Server/Pages/Index.razor | 10 +++---
TcNo-Acc-Switcher-Server/Resources/en-US.yml | 1 -
.../Shared/SharedSettings.razor | 3 +-
8 files changed, 35 insertions(+), 63 deletions(-)
diff --git a/TcNo-Acc-Switcher-Client/App.xaml.cs b/TcNo-Acc-Switcher-Client/App.xaml.cs
index 534595644..413cdb722 100644
--- a/TcNo-Acc-Switcher-Client/App.xaml.cs
+++ b/TcNo-Acc-Switcher-Client/App.xaml.cs
@@ -198,12 +198,23 @@ protected override async void OnStartup(StartupEventArgs e)
///
private static void IsRunningAlready()
{
+
+ AppSettings.Instance.LoadFromFile();
try
{
+ // Check if program is running, if not: return.
if (Mutex.WaitOne(TimeSpan.Zero, true)) return;
- // Otherwise: It has probably just closed. Wait a few and try again
- Thread.Sleep(2000); // 2 seconds before just making sure -- Might be an admin restart
+ // The program is running at this point.
+ // If set to minimize to tray, try open it.
+ if (AppSettings.Instance.TrayMinimizeNotExit)
+ {
+ if (Globals.BringToFront())
+ Environment.Exit(1056); // 1056 An instance of the service is already running.
+ }
+
+ // Otherwise: It has probably just closed. Wait a few and try again
+ Thread.Sleep(2000); // 2 seconds before just making sure -- Might be an admin restart
if (Mutex.WaitOne(TimeSpan.Zero, true)) return;
// Try to show from tray, as user may not know it's hidden there.
diff --git a/TcNo-Acc-Switcher-Client/MainWindow.xaml.cs b/TcNo-Acc-Switcher-Client/MainWindow.xaml.cs
index 238c6d480..a933e9a08 100644
--- a/TcNo-Acc-Switcher-Client/MainWindow.xaml.cs
+++ b/TcNo-Acc-Switcher-Client/MainWindow.xaml.cs
@@ -91,9 +91,7 @@ public MainWindow()
if (Directory.Exists(Globals.OriginalWwwroot)) GeneralFuncs.RecursiveDelete(new DirectoryInfo(Globals.OriginalWwwroot), false);
Directory.Move(Path.Join(Globals.AppDataFolder, "wwwroot"), Globals.OriginalWwwroot);
}
-
-
- AppSettings.LoadFromFile();
+
FindOpenPort();
_address = "--urls=http://localhost:" + AppSettings.ServerPort + "/";
@@ -230,8 +228,6 @@ private void WindowStateChange(object sender, EventArgs e)
{
Globals.DebugWriteLine(@"[Func:(Client)MainWindow.xaml.cs.WindowStateChange]");
- if (AppSettings.TrayMinimizeLessMem) new Thread(CheckVisibility).Start();
-
var state = WindowState switch
{
WindowState.Maximized => "add",
@@ -241,31 +237,6 @@ private void WindowStateChange(object sender, EventArgs e)
MView2.ExecuteScriptAsync("document.body.classList." + state + "('maximised')");
}
- private void CheckVisibility()
- {
- Thread.Sleep(100);
- // While this could handle WindowState == WindowState.Minimised/Normal etc, it's only going to work off the hidden part.
- // As currently this is only going to create/dispose the WebView for better performance when minimising to tray.
- Dispatcher.Invoke(() =>
- {
- // Check if hidden or not:
- var windowLong = Globals.GetWindow(new WindowInteropHelper(this).Handle);
- if (windowLong == (windowLong & ~Globals.WsExAppWindow)) // Hidden
- {
- MainBackground.Children.Remove(MView2);
- MView2.Dispose();
- GC.WaitForPendingFinalizers();
- }
- else // Not hidden
- {
- MView2 = new WebView2();
- MView2.Initialized += MView2_OnInitialised;
- MainBackground.Children.Add(MView2);
- MView2.BeginInit();
- }
- });
- }
-
///
/// Saves window size when closing.
///
diff --git a/TcNo-Acc-Switcher-Globals/Globals.cs b/TcNo-Acc-Switcher-Globals/Globals.cs
index 9ac902329..e612d06b1 100644
--- a/TcNo-Acc-Switcher-Globals/Globals.cs
+++ b/TcNo-Acc-Switcher-Globals/Globals.cs
@@ -23,7 +23,7 @@ public class Globals
#pragma warning disable CA2211 // Non-constant fields should not be visible - This is necessary due to it being a launch parameter.
public static bool VerboseMode;
#pragma warning restore CA2211 // Non-constant fields should not be visible
- public static readonly string Version = "2021-06-23_01";
+ public static readonly string Version = "2021-06-26_00";
public static readonly string[] PlatformList = {"Steam", "Origin", "Ubisoft", "BattleNet", "Epic", "Riot"};
#region LOGGER
diff --git a/TcNo-Acc-Switcher-Server/Data/AppData.cs b/TcNo-Acc-Switcher-Server/Data/AppData.cs
index 305e8edba..69dc07d2d 100644
--- a/TcNo-Acc-Switcher-Server/Data/AppData.cs
+++ b/TcNo-Acc-Switcher-Server/Data/AppData.cs
@@ -81,22 +81,22 @@ public string CurrentStatus
#region JS_INTEROP
public static bool InvokeVoidAsync(string func)
{
- return InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func));
+ return ActiveIJsRuntime is not null && InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func));
}
public static bool InvokeVoidAsync(string func, string arg)
{
- return InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg));
+ return ActiveIJsRuntime is not null && InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg));
}
public static bool InvokeVoidAsync(string func, object arg)
{
- return InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg));
- }
+ return ActiveIJsRuntime is not null && InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg));
+ }
public static bool InvokeVoidAsync(string func, string arg, string arg2)
{
- return InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg, arg2));
+ return ActiveIJsRuntime is not null && InvokeVoidAsync(async () => await ActiveIJsRuntime.InvokeVoidAsync(func, arg, arg2));
}
private static bool InvokeVoidAsync(Action func)
diff --git a/TcNo-Acc-Switcher-Server/Data/AppSettings.cs b/TcNo-Acc-Switcher-Server/Data/AppSettings.cs
index 0c1d6a9de..78114beaa 100644
--- a/TcNo-Acc-Switcher-Server/Data/AppSettings.cs
+++ b/TcNo-Acc-Switcher-Server/Data/AppSettings.cs
@@ -75,23 +75,7 @@ public static AppSettings Instance
private bool _trayMinimizeNotExit;
[JsonProperty("TrayMinimizeNotExit", Order = 6)]
- public bool TrayMinimizeNotExit
- {
- get => _instance._trayMinimizeNotExit;
- set
- {
- if (value)
- {
- _ = GeneralInvocableFuncs.ShowToast("info", "On clicking the Exit button: I'll be on the Windows Tray! (Right of Start Bar)", duration: 15000, renderTo: "toastarea");
- _ = GeneralInvocableFuncs.ShowToast("info", "Hint: Ctrl+Click the 'X' to close me completely, or via the Tray > 'Exit'", duration: 15000, renderTo: "toastarea");
- }
- _instance._trayMinimizeNotExit = value;
-
- }
- }
-
- private bool _trayMinimizeLessMem;
- [JsonProperty("TrayMinimizeLessMem", Order = 7)] public bool TrayMinimizeLessMem { get => _instance._trayMinimizeLessMem; set => _instance._trayMinimizeLessMem = value; }
+ public bool TrayMinimizeNotExit { get => _instance._trayMinimizeNotExit; set => _instance._trayMinimizeNotExit = value; }
private bool _desktopShortcut;
@@ -611,6 +595,14 @@ public void DesktopShortcut_Toggle()
s.ToggleShortcut(!DesktopShortcut);
}
+ public void TrayMinimizeNotExit_Toggle()
+ {
+ Globals.DebugWriteLine(@"[Func:Data\Settings\Steam.DesktopShortcut_Toggle]");
+ if (!TrayMinimizeNotExit) return;
+ _ = GeneralInvocableFuncs.ShowToast("info", "On clicking the Exit button: I'll be on the Windows Tray! (Right of Start Bar)", duration: 15000, renderTo: "toastarea");
+ _ = GeneralInvocableFuncs.ShowToast("info", "Hint: Ctrl+Click the 'X' to close me completely, or via the Tray > 'Exit'", duration: 15000, renderTo: "toastarea");
+ }
+
///
/// Check for existence of protocol key in registry (tcno:\\)
///
diff --git a/TcNo-Acc-Switcher-Server/Pages/Index.razor b/TcNo-Acc-Switcher-Server/Pages/Index.razor
index 326749960..6022112d2 100644
--- a/TcNo-Acc-Switcher-Server/Pages/Index.razor
+++ b/TcNo-Acc-Switcher-Server/Pages/Index.razor
@@ -77,16 +77,16 @@
// This is run before everything is painted on, so that it can get the correct values for the CSS Block.
protected override void OnParametersSet()
{
- if (!GeneralFuncs.WindowSettingsValid())
- {
- // Do something here if necessary.
- // For now this is just being used to load settings.
- }
}
protected override void OnAfterRender(bool firstRender)
{
AppData.Instance.WindowTitle = "TcNo Account Switcher";
+ if (!GeneralFuncs.WindowSettingsValid())
+ {
+ // Do something here if necessary.
+ // For now this is just being used to load settings.
+ }
if (firstRender)
{
GeneralFuncs.HandleQueries();
diff --git a/TcNo-Acc-Switcher-Server/Resources/en-US.yml b/TcNo-Acc-Switcher-Server/Resources/en-US.yml
index 460fcb7da..a5d2eb4ff 100644
--- a/TcNo-Acc-Switcher-Server/Resources/en-US.yml
+++ b/TcNo-Acc-Switcher-Server/Resources/en-US.yml
@@ -36,7 +36,6 @@ Settings_ClearAccounts: Clear Accounts
Settings_RestoreForgotten: Restore forgotten account
Settings_StreamerMode: Enable streamer mode
Settings_ExitToTray: Exit minimises to tray
-Settings_TrayLowMem: Use less RAM while in tray
Settings_DesktopShortcut: Desktop shortcut
Settings_StartMenu_ProgramTray: Program & Tray
Settings_StartMenu_Platform: Platform
diff --git a/TcNo-Acc-Switcher-Server/Shared/SharedSettings.razor b/TcNo-Acc-Switcher-Server/Shared/SharedSettings.razor
index 4001e4d6a..bef1efe06 100644
--- a/TcNo-Acc-Switcher-Server/Shared/SharedSettings.razor
+++ b/TcNo-Acc-Switcher-Server/Shared/SharedSettings.razor
@@ -26,8 +26,7 @@