add:issue #317
This commit is contained in:
+14
-1
@@ -544,6 +544,19 @@ namespace Ink_Canvas
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsLaunchByFileOrUri(string[] args)
|
||||||
|
{
|
||||||
|
if (args == null || args.Length == 0) return false;
|
||||||
|
foreach (string a in args)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(a)) continue;
|
||||||
|
string t = a.Trim();
|
||||||
|
if (t.StartsWith("icc:", StringComparison.OrdinalIgnoreCase)) return true;
|
||||||
|
if (Path.GetExtension(t).Equals(".icstk", StringComparison.OrdinalIgnoreCase)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// 记录崩溃日志
|
// 记录崩溃日志
|
||||||
private static void WriteCrashLog(string message)
|
private static void WriteCrashLog(string message)
|
||||||
{
|
{
|
||||||
@@ -683,7 +696,7 @@ namespace Ink_Canvas
|
|||||||
appStartupStartTime = DateTime.Now;
|
appStartupStartTime = DateTime.Now;
|
||||||
|
|
||||||
// 根据设置决定是否显示启动画面
|
// 根据设置决定是否显示启动画面
|
||||||
if (ShouldShowSplashScreen())
|
if (ShouldShowSplashScreen() && !IsLaunchByFileOrUri(e.Args))
|
||||||
{
|
{
|
||||||
ShowSplashScreen();
|
ShowSplashScreen();
|
||||||
SetSplashMessage("正在启动 Ink Canvas...");
|
SetSplashMessage("正在启动 Ink Canvas...");
|
||||||
|
|||||||
@@ -1,74 +1,37 @@
|
|||||||
using Ink_Canvas.Helpers;
|
using Ink_Canvas.Helpers;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace Ink_Canvas
|
namespace Ink_Canvas
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 处理 icc: URL 协议命令
|
||||||
|
/// 支持:收纳/展开/切换、彻底隐藏、点名/计时器/白板、工具状态切换与查询。
|
||||||
|
/// </summary>
|
||||||
public partial class MainWindow
|
public partial class MainWindow
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 处理URI命令方法
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="uri">URI命令字符串</param>
|
|
||||||
/// <remarks>
|
|
||||||
/// 处理ICC协议的URI命令,包括以下步骤:
|
|
||||||
/// 1. 检查URI是否为空
|
|
||||||
/// 2. 检查是否启用了外部协议
|
|
||||||
/// 3. 记录处理URI命令的日志
|
|
||||||
/// 4. 解析URI获取命令
|
|
||||||
/// 5. 根据命令执行相应的操作:
|
|
||||||
/// - fold: 进入收纳模式
|
|
||||||
/// - unfold/show: 退出收纳模式
|
|
||||||
/// - toggle: 切换收纳模式
|
|
||||||
/// - thoroughhideon: 开启收起时彻底隐藏
|
|
||||||
/// - thoroughhideoff: 关闭收起时彻底隐藏
|
|
||||||
/// - thoroughhidetoggle: 切换收起时彻底隐藏状态
|
|
||||||
/// - randone: 随机一个
|
|
||||||
/// - rand: 随机
|
|
||||||
/// - timer: 计时器
|
|
||||||
/// - whiteboard/board: 白板
|
|
||||||
/// 6. 捕获并记录可能出现的异常
|
|
||||||
/// </remarks>
|
|
||||||
public void HandleUriCommand(string uri)
|
public void HandleUriCommand(string uri)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(uri)) return;
|
if (string.IsNullOrEmpty(uri)) return;
|
||||||
|
|
||||||
// 检查是否启用了外部协议
|
|
||||||
if (!Settings.Advanced.IsEnableUriScheme)
|
if (!Settings.Advanced.IsEnableUriScheme)
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"URI协议已禁用,忽略请求: {uri}", LogHelper.LogType.Warning);
|
LogHelper.WriteLogToFile($"URI 协议已禁用,忽略请求: {uri}", LogHelper.LogType.Warning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogHelper.WriteLogToFile($"正在处理URI命令: {uri}", LogHelper.LogType.Event);
|
LogHelper.WriteLogToFile($"正在处理 URI 命令: {uri}", LogHelper.LogType.Event);
|
||||||
|
|
||||||
// 解析URI
|
string command = ParseUriCommand(uri);
|
||||||
// 格式: icc://command?param=value
|
if (string.IsNullOrEmpty(command)) return;
|
||||||
// 如果URI以icc:开头但不是标准URI格式,尝试手动解析
|
|
||||||
string command = "";
|
|
||||||
|
|
||||||
if (Uri.TryCreate(uri, UriKind.Absolute, out Uri uriObj))
|
string path = command;
|
||||||
{
|
string pathLower = path.ToLowerInvariant();
|
||||||
command = uriObj.Host.ToLower();
|
|
||||||
// 处理像 icc:fold 这样 Host 可能为空的情况
|
|
||||||
if (string.IsNullOrEmpty(command))
|
|
||||||
{
|
|
||||||
command = uriObj.AbsolutePath.Trim('/').ToLower();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果解析失败且是 icc: 协议,则手动处理
|
switch (pathLower)
|
||||||
if (string.IsNullOrEmpty(command) && uri.StartsWith("icc:", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
// 简单的手动解析: icc:fold
|
|
||||||
string path = uri.Substring(4);
|
|
||||||
// 移除可能的斜杠
|
|
||||||
command = path.Trim('/').ToLower();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (command)
|
|
||||||
{
|
{
|
||||||
case "fold":
|
case "fold":
|
||||||
if (!isFloatingBarFolded)
|
if (!isFloatingBarFolded)
|
||||||
@@ -76,17 +39,15 @@ namespace Ink_Canvas
|
|||||||
FoldFloatingBar_MouseUp(new object(), null);
|
FoldFloatingBar_MouseUp(new object(), null);
|
||||||
ShowNotification("已进入收纳模式");
|
ShowNotification("已进入收纳模式");
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "unfold":
|
case "unfold":
|
||||||
case "show": // 兼容旧习惯
|
case "show":
|
||||||
if (isFloatingBarFolded)
|
if (isFloatingBarFolded)
|
||||||
{
|
{
|
||||||
UnFoldFloatingBar_MouseUp(new object(), null);
|
UnFoldFloatingBar_MouseUp(new object(), null);
|
||||||
ShowNotification("已退出收纳模式");
|
ShowNotification("已退出收纳模式");
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "toggle":
|
case "toggle":
|
||||||
if (isFloatingBarFolded)
|
if (isFloatingBarFolded)
|
||||||
{
|
{
|
||||||
@@ -98,63 +59,103 @@ namespace Ink_Canvas
|
|||||||
FoldFloatingBar_MouseUp(new object(), null);
|
FoldFloatingBar_MouseUp(new object(), null);
|
||||||
ShowNotification("已进入收纳模式");
|
ShowNotification("已进入收纳模式");
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "thoroughhideon":
|
case "thoroughhideon":
|
||||||
Settings.Automation.ThoroughlyHideWhenFolded = true;
|
Settings.Automation.ThoroughlyHideWhenFolded = true;
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
ShowNotification("已开启:收起时彻底隐藏");
|
ShowNotification("已开启:收起时彻底隐藏");
|
||||||
// 如果当前已经是在收纳模式,立即隐藏
|
|
||||||
if (isFloatingBarFolded)
|
if (isFloatingBarFolded)
|
||||||
{
|
|
||||||
this.Visibility = Visibility.Hidden;
|
this.Visibility = Visibility.Hidden;
|
||||||
}
|
return;
|
||||||
break;
|
|
||||||
|
|
||||||
case "thoroughhideoff":
|
case "thoroughhideoff":
|
||||||
Settings.Automation.ThoroughlyHideWhenFolded = false;
|
Settings.Automation.ThoroughlyHideWhenFolded = false;
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
ShowNotification("已关闭:收起时彻底隐藏");
|
ShowNotification("已关闭:收起时彻底隐藏");
|
||||||
// 确保窗口可见
|
|
||||||
this.Visibility = Visibility.Visible;
|
this.Visibility = Visibility.Visible;
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "thoroughhidetoggle":
|
case "thoroughhidetoggle":
|
||||||
Settings.Automation.ThoroughlyHideWhenFolded = !Settings.Automation.ThoroughlyHideWhenFolded;
|
Settings.Automation.ThoroughlyHideWhenFolded = !Settings.Automation.ThoroughlyHideWhenFolded;
|
||||||
SaveSettingsToFile();
|
SaveSettingsToFile();
|
||||||
ShowNotification(Settings.Automation.ThoroughlyHideWhenFolded ? "已开启:收起时彻底隐藏" : "已关闭:收起时彻底隐藏");
|
ShowNotification(Settings.Automation.ThoroughlyHideWhenFolded ? "已开启:收起时彻底隐藏" : "已关闭:收起时彻底隐藏");
|
||||||
if (isFloatingBarFolded)
|
if (isFloatingBarFolded)
|
||||||
{
|
|
||||||
this.Visibility = Settings.Automation.ThoroughlyHideWhenFolded ? Visibility.Hidden : Visibility.Visible;
|
this.Visibility = Settings.Automation.ThoroughlyHideWhenFolded ? Visibility.Hidden : Visibility.Visible;
|
||||||
}
|
return;
|
||||||
break;
|
|
||||||
|
|
||||||
case "randone":
|
case "randone":
|
||||||
SymbolIconRandOne_MouseUp(null, null);
|
SymbolIconRandOne_MouseUp(null, null);
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "rand":
|
case "rand":
|
||||||
SymbolIconRand_MouseUp(null, null);
|
SymbolIconRand_MouseUp(null, null);
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "timer":
|
case "timer":
|
||||||
ImageCountdownTimer_MouseUp(null, null);
|
ImageCountdownTimer_MouseUp(null, null);
|
||||||
break;
|
return;
|
||||||
|
|
||||||
case "whiteboard":
|
case "whiteboard":
|
||||||
case "board":
|
case "board":
|
||||||
ImageBlackboard_MouseUp(null, null);
|
ImageBlackboard_MouseUp(null, null);
|
||||||
break;
|
return;
|
||||||
|
|
||||||
default:
|
|
||||||
LogHelper.WriteLogToFile($"未知的URI命令: {command}", LogHelper.LogType.Warning);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pathLower == "tool/state")
|
||||||
|
{
|
||||||
|
string state = GetCurrentSelectedMode() ?? "cursor";
|
||||||
|
string stateFile = Path.Combine(Path.GetTempPath(), "InkCanvasToolState.txt");
|
||||||
|
File.WriteAllText(stateFile, state, System.Text.Encoding.UTF8);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pathLower.StartsWith("tool/"))
|
||||||
|
{
|
||||||
|
string tool = pathLower.Length > 5 ? pathLower.Substring(5).TrimEnd('/') : "";
|
||||||
|
switch (tool)
|
||||||
|
{
|
||||||
|
case "pen":
|
||||||
|
case "color":
|
||||||
|
PenIcon_Click(null, null);
|
||||||
|
break;
|
||||||
|
case "cursor":
|
||||||
|
CursorIcon_Click(null, null);
|
||||||
|
break;
|
||||||
|
case "eraser":
|
||||||
|
PenIcon_Click(null, null);
|
||||||
|
EraserIcon_Click(null, null);
|
||||||
|
break;
|
||||||
|
case "eraserbystrokes":
|
||||||
|
case "eraserstroke":
|
||||||
|
PenIcon_Click(null, null);
|
||||||
|
EraserIconByStrokes_Click(EraserByStrokes_Icon, null);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
LogHelper.WriteLogToFile($"未知的 URI 工具: {tool}", LogHelper.LogType.Warning);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogHelper.WriteLogToFile($"未知的 URI 命令: {command}", LogHelper.LogType.Warning);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"处理URI命令时出错: {ex.Message}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"处理 URI 命令时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ParseUriCommand(string uri)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(uri) || !uri.Trim().StartsWith("icc:", StringComparison.OrdinalIgnoreCase))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
if (Uri.TryCreate(uri, UriKind.Absolute, out Uri uriObj))
|
||||||
|
{
|
||||||
|
string host = (uriObj.Host ?? "").Trim().ToLowerInvariant();
|
||||||
|
string path = (uriObj.AbsolutePath ?? "").Trim('/').ToLowerInvariant();
|
||||||
|
if (!string.IsNullOrEmpty(host))
|
||||||
|
return string.IsNullOrEmpty(path) ? host : host + "/" + path;
|
||||||
|
if (!string.IsNullOrEmpty(path))
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
string raw = uri.Trim().Substring(4).TrimStart('/').ToLowerInvariant();
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user