Files
clash-verge-rev/src/services/service-request.ts
T
Tunglies e3ad1cd319 feat(linux): preserve Service state across upgrades and surface failures
Reinstall an existing Service while keeping its enabled, runtime-masked
and active state. Detect, from the journal, a running Service removed by
a previous deb prerm and reinstall it with its recorded group. Package
script output never reaches the app, so leave a /run marker that makes
the app offer a reinstall once when the Service is not ready.

Hold the core lifecycle until the package manager exits, even after the
startup install times out, so no core start overlaps the Service
reinstall; restart the app once a late install succeeds.

Refs #8515
2026-11-10 07:52:59 +08:00

44 lines
1013 B
TypeScript

/** Why a privileged service is needed. */
export type ServiceRequestReason =
| 'sysproxyRefused'
| 'sysproxySidecarReady'
| 'tunNeedsService'
| 'serviceLocationRefused'
| 'serviceNotAutoStarted'
| 'serviceUpgradeIncomplete'
export interface ServiceRequest {
readonly reason: ServiceRequestReason
/** Settings to apply after the core enters service mode. */
readonly restore?: Partial<IVergeConfig>
}
type Subscriber = () => void
let request: ServiceRequest | null = null
const subscribers = new Set<Subscriber>()
const notify = () => {
subscribers.forEach((subscriber) => subscriber())
}
export const requestService = (next: ServiceRequest) => {
request = next
notify()
}
export const clearServiceRequest = () => {
if (request === null) return
request = null
notify()
}
export const subscribeServiceRequest = (subscriber: Subscriber) => {
subscribers.add(subscriber)
return () => {
subscribers.delete(subscriber)
}
}
export const getServiceRequest = () => request