Skip to content

Commit

Permalink
v2.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
torum committed Jan 7, 2023
1 parent 03fa78f commit 6751050
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 33 deletions.
40 changes: 20 additions & 20 deletions BitWallpaper/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.UI.Xaml.Controls;
using BitWallpaper.ViewModels;
using System.Threading;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Markup;
using System.Threading.Tasks;
using Microsoft.Windows.AppNotifications;
Expand All @@ -35,6 +36,9 @@ public partial class App : Application
//private static SynchronizationContext _theSynchronizationContext = SynchronizationContext.Current;
//public SynchronizationContext TheSynchronizationContext { get => _theSynchronizationContext; }

public bool IsSaveErrorLog = true;
public string LogFilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + System.IO.Path.DirectorySeparatorChar + "BitWallpaper_errors.txt";
private readonly StringBuilder Errortxt = new();

private readonly BitWallpaper.Helpers.NotificationManager notificationManager;

Expand All @@ -44,8 +48,17 @@ public App()
{
InitializeComponent();

// For testing.
//Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
//Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "ja-JP";

// TODO: change theme in the setting.
this.RequestedTheme = ApplicationTheme.Dark;

// Notification
notificationManager = new BitWallpaper.Helpers.NotificationManager();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);

}
catch (XamlParseException parseException)
{
Expand All @@ -62,7 +75,7 @@ public App()

AppendErrorLog($"Exception at App()", ex.Message);
SaveErrorLog();
//throw;
throw;
}

// This does not fire...because of winui3 bugs. should be fixed in v1.3 WinAppSDK
Expand All @@ -72,26 +85,20 @@ public App()
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

// Notification
notificationManager = new BitWallpaper.Helpers.NotificationManager();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);


// For testing.
//Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US";
//Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "ja-JP";
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
/*
* https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/applifecycle
// If this is the first instance launched, then register it as the "main" instance.
// If this isn't the first instance launched, then "main" will already be registered,
// so retrieve it.
var mainInstance = Microsoft.Windows.AppLifecycle.AppInstance.FindOrRegisterForKey("main");
var mainInstance = Microsoft.Windows.AppLifecycle.AppInstance.FindOrRegisterForKey("BitWallPaperMain");
// If the instance that's executing the OnLaunched handler right now
// isn't the "main" instance.
Expand All @@ -109,7 +116,7 @@ protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventA
// Otherwise, register for activation redirection
Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().Activated += App_Activated;
}

*/
//
_window = new MainWindow();
_viewModel = new MainViewModel();
Expand Down Expand Up @@ -207,7 +214,7 @@ private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTask
AppendErrorLog("TaskScheduler_UnobservedTaskException", exception.Message);
SaveErrorLog();

//e.SetObserved();
e.SetObserved();
}

private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
Expand All @@ -228,13 +235,6 @@ private void CurrentDomain_UnhandledException(object sender, System.UnhandledExc
}
}

#if DEBUG
public bool IsSaveErrorLog = true;
#else
public bool IsSaveErrorLog = false;
#endif
public string LogFilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + System.IO.Path.DirectorySeparatorChar + "BitWallpaper_errors.txt";
private readonly StringBuilder Errortxt = new ();

public void AppendErrorLog(string kindTxt, string errorTxt)
{
Expand Down
19 changes: 13 additions & 6 deletions BitWallpaper/BitWallpaper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,28 @@
<UseWinUI>true</UseWinUI>
<ApplicationIcon>App_Icon.ico</ApplicationIcon>
<!--
<WindowsPackageType>None</WindowsPackageType>
-->

<WindowsPackageType>None</WindowsPackageType>
<EnableMsixTooling>true</EnableMsixTooling>
<!--
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
-->
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>

<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
-->



<GenerateAppInstallerFile>False</GenerateAppInstallerFile>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>True</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>True</GenerateTestArtifacts>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<PackageIcon>App_Icon.png</PackageIcon>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
</PropertyGroup>


Expand Down Expand Up @@ -79,7 +86,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
<PackageReference Include="WinUIEx" Version="2.0.0" />
<PackageReference Include="WinUIEx" Version="2.1.0" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
19 changes: 18 additions & 1 deletion BitWallpaper/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public partial class MainViewModel : ViewModelBase
{
#region == Application general ==

public string VersionText { get => "v2.0.2.0"; }
public string VersionText { get => "v2.0.3.0"; }

#endregion

Expand Down Expand Up @@ -428,6 +428,23 @@ public bool IsChartTooltipVisible
}
}

private bool _isDebugSaveLog = true;
public bool IsDebugSaveLog
{
get
{
return _isDebugSaveLog;
}
set
{
if (_isDebugSaveLog == value)
return;

_isDebugSaveLog = value;
NotifyPropertyChanged(nameof(IsDebugSaveLog));
}
}

#endregion

// HTTP Clients
Expand Down
33 changes: 27 additions & 6 deletions BitWallpaper/Views/MainShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public MainShell(MainViewModel mainVM)

#region == Load settings ==

double height = (App.Current as App).MainWindow.GetAppWindow().Size.Height;
double width = (App.Current as App).MainWindow.GetAppWindow().Size.Width;
double height = 640; //(App.Current as App).MainWindow.GetAppWindow().Size.Height;
double width = 480;//(App.Current as App).MainWindow.GetAppWindow().Size.Width;
bool navigationViewControl_IsPaneOpen = false;

if (System.IO.File.Exists(_appConfigFilePath))
Expand Down Expand Up @@ -157,6 +157,19 @@ public MainShell(MainViewModel mainVM)
MainVM.IsChartTooltipVisible = false;
}
}

xvalue = opts.Attribute("IsDebugSaveLog");
if (xvalue != null)
{
if (!string.IsNullOrEmpty(xvalue.Value))
{
if (xvalue.Value == "True")
MainVM.IsDebugSaveLog = true;
else

MainVM.IsDebugSaveLog = false;
}
}
}

// Pairs
Expand Down Expand Up @@ -278,6 +291,8 @@ public MainShell(MainViewModel mainVM)
}
}

(App.Current as App).IsSaveErrorLog = MainVM.IsDebugSaveLog;

#endregion

try
Expand Down Expand Up @@ -307,10 +322,11 @@ public MainShell(MainViewModel mainVM)
//
MainVM.NavigationViewControl_IsPaneOpen = navigationViewControl_IsPaneOpen;

// Be carefull!
(App.Current as App).MainWindow.CenterOnScreen(width, height);


if (((width > 100) && (height > 100)) && ((width < 2000) && (height < 2000)))
{
// Be carefull!
(App.Current as App).MainWindow.CenterOnScreen(width, height);
}
}

private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
Expand Down Expand Up @@ -439,10 +455,15 @@ private void MainWindow_Closed(object sender, WindowEventArgs args)

// Options
XmlElement xOpts = doc.CreateElement(string.Empty, "Opts", string.Empty);

attrs = doc.CreateAttribute("IsChartTooltipVisible");
attrs.Value = MainVM.IsChartTooltipVisible.ToString();
xOpts.SetAttributeNode(attrs);

attrs = doc.CreateAttribute("IsDebugSaveLog");
attrs.Value = MainVM.IsDebugSaveLog.ToString();
xOpts.SetAttributeNode(attrs);

root.AppendChild(xOpts);

// Each pairs
Expand Down
7 changes: 7 additions & 0 deletions BitWallpaper/Views/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
<ToggleSwitch Margin="0" VerticalAlignment="Center" IsOn="{x:Bind ViewModel.IsChartTooltipVisible, Mode=TwoWay}" />
</StackPanel>


<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Text="Save error log on desktop if unexpected error occured" Margin="12,36,12,12" />

<StackPanel Orientation="Horizontal" Margin="24,12,0,0">
<ToggleSwitch Margin="0" VerticalAlignment="Center" IsOn="{x:Bind ViewModel.IsDebugSaveLog, Mode=TwoWay}" />
</StackPanel>

<StackPanel Margin="42"></StackPanel>

</StackPanel>
Expand Down

0 comments on commit 6751050

Please sign in to comment.