queryServiceStatus method

  1. @override
Future<WindowsServiceStatus> queryServiceStatus()
override

查询 Windows 端 clash_sing_service 的安装/运行状态。

流程:定位 helper.exe → 不存在直接返回 error → 委托 HelperCli.status。 任何异常(超时、进程失败)由 HelperCli 归一为 WindowsServiceStatus.error。 进程非零退出(含 helper.json 缺失等导致的 Go panic)同样由 HelperCli 归一为 WindowsServiceStatus.error,调用方无需区分具体失败原因。

Implementation

@override
Future<WindowsServiceStatus> queryServiceStatus() 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 WindowsServiceStatus.notInstalled;
    }
    final io.File configFile = io.File(p.join(dir.path, WindowsConstants.helperConfigFileName));
    if (!await configFile.exists()) {
      return WindowsServiceStatus.notInstalled;
    }
    final cli = _buildCli(dir);
    return cli.status();
  } catch (_) {
    return WindowsServiceStatus.error;
  }
}