Skip to content
Open
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
15 changes: 13 additions & 2 deletions TopNotify/GUI/MainCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void About()
.Show();
}

[Command("Donate")]
[Command("Donate")]
public static async void Donate()
{
try
Expand All @@ -68,7 +68,7 @@ public static string GetVersion()
{
// Read version from Appx Manifest
var appxManifest = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "AppxManifest.xml");
if (File.Exists(appxManifest)) {
if (File.Exists(appxManifest)) {
var manifestData = File.ReadAllText(appxManifest);

var from = manifestData.IndexOf("Version=\"") + "Version=\"".Length;
Expand All @@ -86,6 +86,17 @@ public static string GetVersion()
[Command("RequestConfig")]
public static void RequestConfig(WebWindow target)
{
// Calculate window height based on preview aspect ratio
var resolution = ResolutionFinder.GetRealResolution();
float aspect = (float)resolution.Height / resolution.Width;

// Preview width is 352px, so preview height = 352 * aspect
// Add fixed UI height for header, dropdown, controls, buttons, and padding
float previewHeight = 352f * aspect;
float windowHeight = previewHeight + 420f;

target.Bounds = new WindowBounds((int)(400f * ResolutionFinder.GetScale()), (int)(windowHeight * ResolutionFinder.GetScale()));

target.SendConfig();
}

Expand Down
45 changes: 44 additions & 1 deletion TopNotify/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#define TRACE // Enable Trace.WriteLine
#define TRACE // Enable Trace.WriteLine

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using Microsoft.Toolkit.Uwp.Notifications;
using TopNotify.Daemon;
Expand All @@ -11,6 +12,7 @@
using IgniteView.Desktop;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Windows.Services.Store;
using Serilog;
using Serilog.Core;
Expand Down Expand Up @@ -109,6 +111,18 @@ public static void Main(string[] args)

// Open The GUI App In Settings Mode
GUI = new ViteAppManager();

// WebView2 fails to read/write its data directory when the path contains
// non-ASCII characters (e.g. Japanese usernames). If non-ASCII characters
// are detected, fall back to an ASCII-safe path under ProgramData.
if (GUI.CurrentIdentity.AppDataPath.Any(c => c > 127))
{
GUI.CurrentIdentity = new AsciiSafeAppIdentity(
GUI.CurrentIdentity.Name,
GUI.CurrentIdentity.Developer
);
}

App();
}
else
Expand Down Expand Up @@ -153,5 +167,34 @@ public static async Task App()
}

}

/// <summary>
/// AppIdentity subclass that works around WebView2's inability to handle non-ASCII paths.
/// When the user profile path contains non-ASCII characters (e.g. Japanese usernames),
/// this class redirects the data directory to an ASCII-safe path under ProgramData (C:\ProgramData).
/// </summary>
public class AsciiSafeAppIdentity : AppIdentity
{
[SetsRequiredMembers]
public AsciiSafeAppIdentity(string name, string developer) : base(name, developer) { }

public override string AppDataPath
{
get
{
// ProgramData (C:\ProgramData) always has an ASCII-only path,
// making it safe to use as the WebView2 data directory
var basePath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
var fullPath = Path.Join(basePath, Developer, Name);

if (!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
}

return fullPath;
}
}
}
}