Skip to content

Commit

Permalink
Removed mutex wait time since its no longer required..
Browse files Browse the repository at this point in the history
- .. faster ui startup and commandline argument processing.
- Updated webview params.
  • Loading branch information
rocksdanister committed May 6, 2024
1 parent 5c1492a commit 48a9363
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
21 changes: 9 additions & 12 deletions src/Lively/Lively.UI.WinUI/Views/Pages/AppUpdateView.xaml.cs
Expand Up @@ -9,9 +9,6 @@
using Microsoft.Web.WebView2.Core;
using System;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Lively.UI.WinUI.Views.Pages
{
public sealed partial class AppUpdateView : Page
Expand All @@ -26,26 +23,26 @@ public AppUpdateView()

// Error when setting in xaml
WebView.DefaultBackgroundColor = ((SolidColorBrush)App.Current.Resources["ApplicationPageBackgroundThemeBrush"]).Color;
// Set website theme to reflect app setting
// Set website to reflect app interface
var pageTheme = App.Services.GetRequiredService<IUserSettingsClient>().Settings.ApplicationTheme switch
{
AppTheme.Auto => string.Empty, // Website handles theme change based on WebView change.
AppTheme.Light => "&theme=light",
AppTheme.Dark => "&theme=dark",
_ => string.Empty,
AppTheme.Auto => "auto", // Website handles theme change based on WebView change.
AppTheme.Light => "light",
AppTheme.Dark => "dark",
_ => "auto",
};
// Set website accent color
var accentColorDark1 = ((Windows.UI.Color)App.Current.Resources["SystemAccentColorDark1"]).ToHex().Substring(1);
var accentColorLight1 = ((Windows.UI.Color)App.Current.Resources["SystemAccentColorLight1"]).ToHex().Substring(1);
var param = $"?source=app&theme={pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}";

var url = viewModel.IsBetaBuild ?
$"https://www.rocksdanister.com/lively-webpage/changelog/?source=app{pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}" :
$"https://www.rocksdanister.com/lively/changelog/?source=app{pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}";
$"https://www.rocksdanister.com/lively-webpage/changelog/{param}" :
$"https://www.rocksdanister.com/lively/changelog/{param}";
WebView.Source = LinkUtil.SanitizeUrl(url);
}

// ref: https://github.com/MicrosoftEdge/WebView2Samples
private async void WebView_CoreWebView2Initialized(WebView2 sender, CoreWebView2InitializedEventArgs args)
private void WebView_CoreWebView2Initialized(WebView2 sender, CoreWebView2InitializedEventArgs args)
{
if (args.Exception != null)
{
Expand Down
Expand Up @@ -12,9 +12,6 @@
using Microsoft.Web.WebView2.Core;
using System;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Lively.UI.WinUI.Views.Pages
{
public sealed partial class PatreonSupportersView : Page
Expand All @@ -29,21 +26,21 @@ public PatreonSupportersView()

// Error when setting in xaml
WebView.DefaultBackgroundColor = ((SolidColorBrush)App.Current.Resources["ApplicationPageBackgroundThemeBrush"]).Color;
// Set website theme to reflect app setting
// Set website to reflect app interface
var pageTheme = App.Services.GetRequiredService<IUserSettingsClient>().Settings.ApplicationTheme switch
{
AppTheme.Auto => string.Empty, // Website handles theme change based on WebView change.
AppTheme.Light => "theme=light",
AppTheme.Dark => "theme=dark",
_ => string.Empty,
AppTheme.Auto => "auto", // Website handles theme change based on WebView change.
AppTheme.Light => "light",
AppTheme.Dark => "dark",
_ => "auto",
};
// Set website accent color
var accentColorDark1 = ((Windows.UI.Color)App.Current.Resources["SystemAccentColorDark1"]).ToHex().Substring(1);
var accentColorLight1 = ((Windows.UI.Color)App.Current.Resources["SystemAccentColorLight1"]).ToHex().Substring(1);
var param = $"?theme={pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}";

var url = viewModel.IsBetaBuild ?
$"https://www.rocksdanister.com/lively-webpage/supporters/?{pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}" :
$"https://www.rocksdanister.com/lively/supporters/?{pageTheme}&colorLight={accentColorLight1}&colorDark={accentColorDark1}";
$"https://www.rocksdanister.com/lively-webpage/supporters/{param}" :
$"https://www.rocksdanister.com/lively/supporters/{param}";
WebView.Source = LinkUtil.SanitizeUrl(url);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Lively/Lively/App.xaml.cs
Expand Up @@ -67,16 +67,19 @@ public App()
{
try
{
//wait a few seconds in case application instance is just shutting down..
if (!mutex.WaitOne(TimeSpan.FromSeconds(1), false))
// Wait a few seconds in case application instance is just shutting down..
// Note: This wait is longer required since Core is never restarted after 2.0 rewrite.
if (!mutex.WaitOne(0, false))
{
try
{
//skipping first element (application path.)
// If another instance is running, communicate with it and then exit.
// Commandline args, first element is application path.
var args = Environment.GetCommandLineArgs().Skip(1).ToArray();
var client = new CommandsService.CommandsServiceClient(new NamedPipeChannel(".", Constants.SingleInstance.GrpcPipeServerName));
var request = new AutomationCommandRequest();
request.Args.AddRange(args.Length != 0 ? args : new string[] { "--showApp", "true" });
// If no argument assume user opened via icon and show interface.
request.Args.AddRange(args.Length != 0 ? args : ["--showApp", "true"]);
_ = client.AutomationCommandAsync(request);
}
catch (Exception e)
Expand Down

0 comments on commit 48a9363

Please sign in to comment.