Files
ShadowsocksX-NG/ShadowsocksX-NG2/App/LaunchAgentService.swift
T
Qiu Yuzhou 00fcd61a99 refactor(ng2): change bundle id to ShadowsocksX-NG2
Distinct id from Legacy (com.qiuyuzhou.ShadowsocksX-NG) lets NG2 own
~/Library/Application Support/ShadowsocksX-NG2/ directly; the v2/
subdir prefix is removed from all runtime paths.

- app/agent/tests targets + LaunchAgent plist renamed accordingly
- keychain service, queue labels, and Vendor signIdentifiers follow
  the new bundle id; embedded helpers re-sign at build time
- Legacy handoff/import constants keep pointing at the old id

Migration: dev data under ShadowsocksX-NG/v2/ is not carried over
(fresh catalog/activation); old LaunchAgent registration and old
keychain entries must be cleaned up manually.
2026-09-21 20:33:37 +08:00

42 lines
1.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
import ServiceManagement
/// LaunchAgent 管理缝(spec #21 D2):控制器经此协议启停 agent,单元测试以
/// fake 替换(真实 SMAppService 注册会改动用户登录项,不进单测)。
protocol LaunchAgentControlling {
var status: LaunchAgentStatus { get }
func register() throws
func unregister() throws
}
/// 生产实现:plist 必须位于 app bundle `Contents/Library/LaunchAgents/`,
/// ProgramArguments 为 bundle 相对路径(launchd 按注册 app 的 bundle 解析)。
struct SMAppLaunchAgentService: LaunchAgentControlling {
static let plistName = "com.qiuyuzhou.ShadowsocksX-NG2.agent.plist"
private let service = SMAppService.agent(plistName: Self.plistName)
var status: LaunchAgentStatus {
switch service.status {
case .notRegistered:
return .notRegistered
case .enabled:
return .registered
case .requiresApproval:
return .requiresApproval
case .notFound:
return .notFound
@unknown default:
return .notFound
}
}
func register() throws {
try service.register()
}
func unregister() throws {
try service.unregister()
}
}