Check service status before destroying working directory
This commit is contained in:
@@ -4,7 +4,9 @@ import SwiftUI
|
|||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
public struct CoreView: View {
|
public struct CoreView: View {
|
||||||
|
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||||
@State private var isLoading = true
|
@State private var isLoading = true
|
||||||
|
@State private var alert: AlertState?
|
||||||
|
|
||||||
@State private var disableDeprecatedWarnings = false
|
@State private var disableDeprecatedWarnings = false
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ public struct CoreView: View {
|
|||||||
#endif
|
#endif
|
||||||
FormButton(role: .destructive) {
|
FormButton(role: .destructive) {
|
||||||
Task {
|
Task {
|
||||||
await destroyWorkingDirectory()
|
await confirmDestroyWorkingDirectory()
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Label("Destroy", systemImage: "trash.fill")
|
Label("Destroy", systemImage: "trash.fill")
|
||||||
@@ -53,6 +55,7 @@ public struct CoreView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Core")
|
.navigationTitle("Core")
|
||||||
|
.alert($alert)
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
#endif
|
#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 {
|
private nonisolated func destroyWorkingDirectory() async {
|
||||||
try? FileManager.default.removeItem(at: FilePath.workingDirectory)
|
try? FileManager.default.removeItem(at: FilePath.workingDirectory)
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
|
|||||||
@@ -1629,6 +1629,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Service is Running" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "服务正在运行"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Service Log" : {
|
"Service Log" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"zh-Hans" : {
|
"zh-Hans" : {
|
||||||
@@ -1812,6 +1822,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"Stop Service and Continue" : {
|
||||||
|
"localizations" : {
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "停止服务并继续"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"System Extension" : {
|
"System Extension" : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"zh-Hans" : {
|
"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." : {
|
"This app needs to be placed under the Applications folder to work." : {
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
"zh-Hans" : {
|
"zh-Hans" : {
|
||||||
|
|||||||
Reference in New Issue
Block a user