Check service status before destroying working directory

This commit is contained in:
世界
2025-12-07 11:33:31 +08:00
parent bbf0d4945c
commit 9b25243b6a
2 changed files with 56 additions and 1 deletions
@@ -4,7 +4,9 @@ import SwiftUI
@MainActor
public struct CoreView: View {
@EnvironmentObject private var environments: ExtensionEnvironments
@State private var isLoading = true
@State private var alert: AlertState?
@State private var disableDeprecatedWarnings = false
@@ -42,7 +44,7 @@ public struct CoreView: View {
#endif
FormButton(role: .destructive) {
Task {
await destroyWorkingDirectory()
await confirmDestroyWorkingDirectory()
}
} label: {
Label("Destroy", systemImage: "trash.fill")
@@ -53,6 +55,7 @@ public struct CoreView: View {
}
}
.navigationTitle("Core")
.alert($alert)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
@@ -84,6 +87,28 @@ public struct CoreView: View {
}
}
private func confirmDestroyWorkingDirectory() async {
if environments.extensionProfile?.status.isConnected == true {
alert = AlertState(
title: String(localized: "Service is Running"),
message: String(localized: "The service must be stopped before destroying the working directory."),
primaryButton: .destructive(String(localized: "Stop Service and Continue")) { [self] in
Task {
await stopServiceAndDestroy()
}
},
secondaryButton: .cancel()
)
} else {
await destroyWorkingDirectory()
}
}
private func stopServiceAndDestroy() async {
try? await environments.extensionProfile?.stop()
await destroyWorkingDirectory()
}
private nonisolated func destroyWorkingDirectory() async {
try? FileManager.default.removeItem(at: FilePath.workingDirectory)
await MainActor.run {
+30
View File
@@ -1629,6 +1629,16 @@
}
}
},
"Service is Running" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "服务正在运行"
}
}
}
},
"Service Log" : {
"localizations" : {
"zh-Hans" : {
@@ -1812,6 +1822,16 @@
}
}
},
"Stop Service and Continue" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "停止服务并继续"
}
}
}
},
"System Extension" : {
"localizations" : {
"zh-Hans" : {
@@ -1875,6 +1895,16 @@
}
}
},
"The service must be stopped before destroying the working directory." : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "必须先停止服务才能清理工作目录。"
}
}
}
},
"This app needs to be placed under the Applications folder to work." : {
"localizations" : {
"zh-Hans" : {