11import Cocoa
22import Core
3- import Darwin
43import SwiftUI
54
65struct ConfigWindow : View {
@@ -25,6 +24,7 @@ struct ConfigWindow: View {
2524 @ConfigState private var keyboardLayout = Config . KeyboardLayout ( )
2625 @ConfigState private var aiBackend = Config . AIBackendPreference ( )
2726
27+ @State private var converterServerClient = ConverterServerClient ( )
2828 @State private var selectedTab : Tab = . basic
2929 @State private var zenzaiProfileHelpPopover = false
3030 @State private var zenzaiInferenceLimitHelpPopover = false
@@ -67,17 +67,6 @@ struct ConfigWindow: View {
6767 case successfulUpdate
6868 }
6969
70- private enum ConverterProcessRestartError : LocalizedError {
71- case launchctlFailed( String )
72-
73- var errorDescription : String ? {
74- switch self {
75- case . launchctlFailed( let message) :
76- " launchctl kickstart failed: \( message) "
77- }
78- }
79- }
80-
8170 private var azooKeyApplicationSupportDirectoryURL : URL {
8271 AppGroup . applicationSupportDirectoryURL ( )
8372 }
@@ -195,53 +184,14 @@ struct ConfigWindow: View {
195184 }
196185 self . converterProcessRestartInProgress = true
197186 self . converterProcessRestartMessage = nil
198- Task {
199- do {
200- try await Task . detached ( priority: . utility) {
201- try Self . restartConverterProcessService ( )
202- } . value
203- await MainActor . run {
204- self . converterProcessRestartMessage = " 再起動しました "
205- self . converterProcessRestartInProgress = false
206- }
207- } catch {
208- await MainActor . run {
209- self . converterProcessRestartMessage = error. localizedDescription
210- self . converterProcessRestartInProgress = false
211- }
187+ self . converterServerClient. restartServer { success in
188+ DispatchQueue . main. async {
189+ self . converterProcessRestartMessage = success ? " 再起動しました " : " Converter Processに再起動を依頼できませんでした "
190+ self . converterProcessRestartInProgress = false
212191 }
213192 }
214193 }
215194
216- nonisolated private static func restartConverterProcessService( ) throws {
217- let serviceName = " dev.ensan.inputmethod.azooKeyMac.ConverterServer "
218- let process = Process ( )
219- process. executableURL = URL ( fileURLWithPath: " /bin/launchctl " )
220- process. arguments = [
221- " kickstart " ,
222- " -k " ,
223- " gui/ \( getuid ( ) ) / \( serviceName) "
224- ]
225-
226- let outputPipe = Pipe ( )
227- let errorPipe = Pipe ( )
228- process. standardOutput = outputPipe
229- process. standardError = errorPipe
230-
231- try process. run ( )
232- process. waitUntilExit ( )
233-
234- guard process. terminationStatus == 0 else {
235- let standardError = String ( data: errorPipe. fileHandleForReading. readDataToEndOfFile ( ) , encoding: . utf8) ?? " "
236- let standardOutput = String ( data: outputPipe. fileHandleForReading. readDataToEndOfFile ( ) , encoding: . utf8) ?? " "
237- let message = [ standardError, standardOutput]
238- . map { $0. trimmingCharacters ( in: . whitespacesAndNewlines) }
239- . filter { !$0. isEmpty }
240- . joined ( separator: " \n " )
241- throw ConverterProcessRestartError . launchctlFailed ( message. isEmpty ? " exit status \( process. terminationStatus) " : message)
242- }
243- }
244-
245195 private func openAzooKeyDataDirectoryInFinder( ) {
246196 do {
247197 try FileManager . default. createDirectory (
0 commit comments