Merge pull request #366 from PANDAJSR/feat--允许第三方程序通过系统URI来控制部分功能

This commit is contained in:
2,2,3-三甲基戊烷
2026-02-04 12:54:27 +08:00
committed by GitHub
11 changed files with 363 additions and 3 deletions
+23
View File
@@ -2853,6 +2853,29 @@ namespace Ink_Canvas
SaveSettingsToFile();
}
private void ToggleSwitchIsEnableUriScheme_Toggled(object sender, RoutedEventArgs e)
{
if (!isLoaded) return;
Settings.Advanced.IsEnableUriScheme = ToggleSwitchIsEnableUriScheme.IsOn;
if (Settings.Advanced.IsEnableUriScheme)
{
if (!UriSchemeHelper.IsUriSchemeRegistered())
{
UriSchemeHelper.RegisterUriScheme();
}
}
else
{
if (UriSchemeHelper.IsUriSchemeRegistered())
{
UriSchemeHelper.UnregisterUriScheme();
}
}
SaveSettingsToFile();
}
private void TouchMultiplierSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
if (!isLoaded) return;
@@ -857,6 +857,7 @@ namespace Ink_Canvas
ToggleSwitchIsSecondConfimeWhenShutdownApp.IsOn = Settings.Advanced.IsSecondConfirmWhenShutdownApp;
ToggleSwitchWindowMode.IsOn = Settings.Advanced.WindowMode;
ToggleSwitchIsSpecialScreen.IsOn = Settings.Advanced.IsSpecialScreen;
ToggleSwitchIsEnableUriScheme.IsOn = Settings.Advanced.IsEnableUriScheme;
ToggleSwitchIsQuadIR.IsOn = Settings.Advanced.IsQuadIR;
ToggleSwitchEraserBindTouchMultiplier.IsOn = Settings.Advanced.EraserBindTouchMultiplier;
ToggleSwitchIsEnableFullScreenHelper.IsOn = Settings.Advanced.IsEnableFullScreenHelper;
+77
View File
@@ -0,0 +1,77 @@
using Ink_Canvas.Helpers;
using System;
using System.Windows;
namespace Ink_Canvas
{
public partial class MainWindow
{
public void HandleUriCommand(string uri)
{
try
{
if (string.IsNullOrEmpty(uri)) return;
LogHelper.WriteLogToFile($"正在处理URI命令: {uri}", LogHelper.LogType.Event);
// 解析URI
// 格式: icc://command?param=value
// 如果URI以icc:开头但不是标准URI格式,尝试手动解析
string command = "";
if (Uri.TryCreate(uri, UriKind.Absolute, out Uri uriObj))
{
command = uriObj.Host.ToLower();
}
else if (uri.StartsWith("icc:", StringComparison.OrdinalIgnoreCase))
{
// 简单的手动解析: icc:fold
string path = uri.Substring(4);
// 移除可能的斜杠
command = path.Trim('/').ToLower();
}
switch (command)
{
case "fold":
if (!isFloatingBarFolded)
{
FoldFloatingBar_MouseUp(new object(), null);
ShowNotification("已进入收纳模式");
}
break;
case "unfold":
case "show": // 兼容旧习惯
if (isFloatingBarFolded)
{
UnFoldFloatingBar_MouseUp(new object(), null);
ShowNotification("已退出收纳模式");
}
break;
case "toggle":
if (isFloatingBarFolded)
{
UnFoldFloatingBar_MouseUp(new object(), null);
ShowNotification("已退出收纳模式");
}
else
{
FoldFloatingBar_MouseUp(new object(), null);
ShowNotification("已进入收纳模式");
}
break;
default:
LogHelper.WriteLogToFile($"未知的URI命令: {command}", LogHelper.LogType.Warning);
break;
}
}
catch (Exception ex)
{
LogHelper.WriteLogToFile($"处理URI命令时出错: {ex.Message}", LogHelper.LogType.Error);
}
}
}
}