Files
ShadowsocksX-NG/ShadowsocksX-NG2/App/Application/RulesWorkflow/RulesWorkspaces.swift
T
Qiu Yuzhou 57df01e5ed feat(rules)!: add isolated routing presets
Add Mainland China proxy routing with independent rule workspaces.
Preserve existing routing choices through equivalent preset mappings.

BREAKING CHANGE: existing custom rules and enablement settings are
not migrated. Recreate them in the appropriate preset.
2026-10-24 20:32:36 +08:00

23 lines
795 B
Swift

import Combine
import Foundation
/// Each preset owns an unchanged workflow, including its in-flight operations.
@MainActor
final class RulesWorkspaces: ObservableObject {
@Published var selectedPreset: RulePreset = .chinaDirect
@Published private(set) var reportSource: RulesSourceSnapshot?
private let workflows: [RulePreset: RulesWorkflow]
private var reports: Set<AnyCancellable> = []
init(makeWorkflow: (RulePreset) -> RulesWorkflow) {
workflows = Dictionary(uniqueKeysWithValues: RulePreset.allCases.map { ($0, makeWorkflow($0)) })
for workflow in workflows.values {
workflow.$reportSource.compactMap { $0 }.sink { [weak self] in
self?.reportSource = $0
}.store(in: &reports)
}
}
var current: RulesWorkflow { workflows[selectedPreset]! }
}