restartService method

  1. @override
Future<bool> restartService()
override

重启 Windows 系统服务(UAC 提权 + 两段式状态迁移轮询确认完成), 供 helper 更新落盘后使新版服务无感生效。

helper.exe 缺失或任何异常返回 false;调用方应降级用旧版继续业务。

Implementation

@override
Future<bool> restartService() async {
  try {
    final io.Directory dir = await ProfileStorage().getStorageDirectory();
    final io.File helperExe = io.File(p.join(dir.path, WindowsConstants.helperFileName));
    if (!await helperExe.exists()) {
      return false;
    }
    final cli = _buildCli(dir);
    return await cli.restart();
  } catch (e) {
    debugPrint('flutter_sing_box 插件重启服务失败, $e');
    return false;
  }
}