import 'dart:io'; import '../utils/command_runner.dart'; /// zaxprint:// URL scheme 注册: /// - macOS:Info.plist CFBundleURLTypes 已声明(构建即生效),无需运行时处理 /// - Windows:写 HKCU\Software\Classes\zaxprint(用户级,免管理员),App 启动时 ensure class UrlScheme { static const scheme = 'zaxprint'; static bool get needsRuntimeRegister => Platform.isWindows; /// Windows:确保 scheme 已注册到当前可执行文件(每次启动幂等调用,路径变了会刷新)。 static Future ensureRegistered() async { if (!Platform.isWindows) return; final exe = Platform.resolvedExecutable; final root = r'HKCU\Software\Classes' '\\$scheme'; await runCommand('reg', ['add', root, '/ve', '/t', 'REG_SZ', '/d', 'URL:资安信插件助手唤起', '/f']); await runCommand('reg', ['add', root, '/v', 'URL Protocol', '/t', 'REG_SZ', '/d', '', '/f']); await runCommand('reg', [ 'add', r'HKCU\Software\Classes' '\\$scheme' r'\shell\open\command', '/ve', '/t', 'REG_SZ', '/d', '"$exe" "%1"', '/f', ]); } /// Windows:注册是否指向当前可执行文件(向导自检展示用)。 static Future isRegisteredToSelf() async { if (!Platform.isWindows) return true; // mac 由 Info.plist 保证 final exe = Platform.resolvedExecutable; final out = await runCommand( 'reg', ['query', r'HKCU\Software\Classes' '\\$scheme' r'\shell\open\command', '/ve'], tolerateExit: true, ); return out.contains(exe); } }