Skip to content

Commit

Permalink
v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
torum committed Jan 1, 2023
1 parent d14844f commit c69424c
Show file tree
Hide file tree
Showing 15 changed files with 1,188 additions and 508 deletions.
57 changes: 0 additions & 57 deletions BitWallpaper.sln

This file was deleted.

5 changes: 1 addition & 4 deletions BitWallpaper/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,12 @@
<!-- Other app resources here -->
<!--
<CornerRadius x:Key="NavigationViewContentGridCornerRadius">0,0,0,0</CornerRadius>
-->
<!--
-->

<x:Double x:Key="PivotHeaderItemFontSize">18</x:Double>

<x:Double x:Key="CustumTextOpacity">0.7</x:Double>



<SolidColorBrush x:Key="PriceUpColorBrush" Color="#8BC34A"/>
<SolidColorBrush x:Key="PriceDownColorBrush" Color="#EF5350"/>

Expand Down
49 changes: 43 additions & 6 deletions BitWallpaper/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Threading;
using Microsoft.UI.Xaml.Markup;
using System.Threading.Tasks;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;

namespace BitWallpaper
{
Expand All @@ -33,10 +35,9 @@ public partial class App : Application
//private static SynchronizationContext _theSynchronizationContext = SynchronizationContext.Current;
//public SynchronizationContext TheSynchronizationContext { get => _theSynchronizationContext; }

/// <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>

private readonly BitWallpaper.Helpers.NotificationManager notificationManager;

public App()
{
try
Expand Down Expand Up @@ -70,7 +71,11 @@ 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";
Expand Down Expand Up @@ -121,9 +126,38 @@ protected override async void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventA
//manager.Backdrop = new WinUIEx.AcrylicSystemBackdrop();
manager.Backdrop = new WinUIEx.MicaSystemBackdrop();

//
notificationManager.Init();

_window.Activate();


_viewModel.ShowBalloon += (sender, arg) => { ShowBalloon(arg); };
}

private void ShowBalloon(ShowBalloonEventArgs arg)
{

// https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/notifications/app-notifications/app-notifications-quickstart?tabs=cs
var appNotification = new AppNotificationBuilder()
.AddText(arg.Title)
.AddText(arg.Text)
.AddButton(new AppNotificationButton("OK")
.AddArgument("action", "dissmiss"))
.SetTimeStamp(new DateTime(2017, 04, 15, 19, 45, 00, DateTimeKind.Utc)).BuildNotification();

//.SetTimeStamp(new DateTime(2017, 04, 15, 19, 45, 00, DateTimeKind.Utc));

//.SetScenario(AppNotificationScenario.Alarm)
AppNotificationManager.Default.Show(appNotification);
}

protected void OnProcessExit(object sender, EventArgs e)
{
notificationManager.Unregister();
}

// Activated from other instance.
private void App_Activated(object sender, Microsoft.Windows.AppLifecycle.AppActivationArguments e)
{
CurrentDispatcherQueue?.TryEnqueue(() =>
Expand All @@ -147,6 +181,9 @@ private void App_Activated(object sender, Microsoft.Windows.AppLifecycle.AppActi
// And call SetForegroundWindow... requires Microsoft.Windows.CsWin32 NuGet package and a NativeMethods.txt file with SetForegroundWindow method
Windows.Win32.PInvoke.SetForegroundWindow(hwnd);
*/



}

private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
Expand Down Expand Up @@ -197,7 +234,7 @@ private void CurrentDomain_UnhandledException(object sender, System.UnhandledExc
public bool IsSaveErrorLog = false;
#endif
public string LogFilePath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + System.IO.Path.DirectorySeparatorChar + "BitWallpaper_errors.txt";
private StringBuilder Errortxt = new ();
private readonly StringBuilder Errortxt = new ();

public void AppendErrorLog(string kindTxt, string errorTxt)
{
Expand Down
10 changes: 9 additions & 1 deletion BitWallpaper/BitWallpaper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<ItemGroup>
<Content Include="App_Icon.ico" />
<None Remove="Views\ContentDialogContent.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="App_Icon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -81,5 +86,8 @@
<None Update="App_Icon.ico">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Page Update="Views\ContentDialogContent.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>
105 changes: 105 additions & 0 deletions BitWallpaper/Helpers/NotificationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using System;
using System.Collections.Generic;

namespace BitWallpaper.Helpers
{
internal class NotificationManager
{
private bool m_isRegistered;

//private Dictionary<string, Action<AppNotificationActivatedEventArgs>> c_map;

public NotificationManager()
{
m_isRegistered = false;

// When adding new a scenario, be sure to add its notification handler here.
//c_map = new Dictionary<int, Action<AppNotificationActivatedEventArgs>>();
//c_map.Add(ToastWithAvatar.ScenarioId, ToastWithAvatar.NotificationReceived);
//c_map.Add(ToastWithTextBox.ScenarioId, ToastWithTextBox.NotificationReceived);
}

~NotificationManager()
{
Unregister();
}

public void Init()
{
// To ensure all Notification handling happens in this process instance, register for
// NotificationInvoked before calling Register(). Without this a new process will
// be launched to handle the notification.
AppNotificationManager notificationManager = AppNotificationManager.Default;

//notificationManager.NotificationInvoked += OnNotificationInvoked;

notificationManager.Register();
m_isRegistered = true;
}

public void Unregister()
{
if (m_isRegistered)
{
AppNotificationManager.Default.Unregister();
m_isRegistered = false;
}
}

public void ProcessLaunchActivationArgs(AppNotificationActivatedEventArgs notificationActivatedEventArgs)
{
// Complete in Step 5
}

}
/*
// ToastWithAvatar.cs
class ToastWithAvatar
{
public const int ScenarioId = 1;
public const string ScenarioName = "Local Toast with Avatar Image";
public static bool SendToast()
{
var appNotification = new AppNotificationBuilder()
.AddArgument("action", "ToastClick")
.AddArgument(Common.scenarioTag, ScenarioId.ToString())
.SetAppLogoOverride(new System.Uri("file://" + App.GetFullPathToAsset("Square150x150Logo.png")), AppNotificationImageCrop.Circle)
.AddText(ScenarioName)
.AddText("This is an example message using XML")
.AddButton(new AppNotificationButton("Open App")
.AddArgument("action", "OpenApp")
.AddArgument(Common.scenarioTag, ScenarioId.ToString()))
.BuildNotification();
AppNotificationManager.Default.Show(appNotification);
return appNotification.Id != 0; // return true (indicating success) if the toast was sent (if it has an Id)
}
public static void NotificationReceived(AppNotificationActivatedEventArgs notificationActivatedEventArgs)
{
// Complete in Step 5
}
}
*/
// Call SendToast() to send a notification.

/*
var builder = new AppNotificationBuilder()
.AddArgument("conversationId", 9813)
.AddText("Adaptive Tiles Meeting", new AppNotificationTextProperties().SetMaxLines(1))
.AddText("Conf Room 2001 / Building 135")
.AddText("10:00 AM - 10:30 AM");
.SetTimeStamp(new DateTime(2017, 04, 15, 19, 45, 00, DateTimeKind.Utc));
.SetScenario(AppNotificationScenario.Alarm)
AppNotificationManager.Default.Show(appNotification);
*/



}
3 changes: 3 additions & 0 deletions BitWallpaper/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,7 @@
<data name="PrivacyPolicy.Text" xml:space="preserve">
<value>This application does not collect nor send any information.</value>
</data>
<data name="AppName" xml:space="preserve">
<value>BitWallpaper</value>
</data>
</root>
3 changes: 3 additions & 0 deletions BitWallpaper/Strings/ja-JP/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,7 @@
<data name="Settings.Title" xml:space="preserve">
<value>設定</value>
</data>
<data name="AppName" xml:space="preserve">
<value>BitWallpaper</value>
</data>
</root>
Loading

0 comments on commit c69424c

Please sign in to comment.