Skip to content

Commit

Permalink
SKKServの設定画面に辞書の参照テストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgto committed Nov 2, 2024
1 parent 4f22d2e commit 4f4ba41
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
82 changes: 58 additions & 24 deletions macSKK/Settings/SKKServDictView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct SKKServDictView: View {
@Binding var isShowSheet: Bool
@State var information: String = ""
@State var testing: Bool = false
@State var yomi: String = ""

var body: some View {
VStack {
Expand All @@ -25,6 +26,35 @@ struct SKKServDictView: View {
.pickerStyle(.radioGroup)
} header: {
Text("SKKServDictTitle")
}
Section {
TextField("Yomi", text: $yomi)
HStack {
Spacer()
Button {
let skkservService = SKKServService()
let setting = settingsViewModel.skkservDictSetting
let destination = SKKServDestination(host: setting.address,
port: setting.port,
encoding: setting.encoding)
testing = true
let result = Result {
try skkservService.refer(yomi: yomi, destination: destination, timeout: 1.0)
}
switch result {
case .success(let response):
logger.log("skkservの応答: \(response, privacy: .public)")
information = response
case .failure(let error):
showError(error)
}
testing = false
} label: {
Text("Refer")
}.disabled(yomi.isEmpty || testing)
}
} header: {
Text("SKKServDictReferTestTitle")
} footer: {
if testing {
ProgressView().controlSize(.small)
Expand All @@ -51,32 +81,11 @@ struct SKKServDictView: View {
logger.log("skkservのバージョン: \(version, privacy: .public)")
information = String(localized: "SKKServClientConnected")
case .failure(let error):
if let error = error as? SKKServClientError {
switch error {
case .unexpected:
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
case .connectionRefused:
logger.info("skkservへの通信ができませんでした")
information = String(localized: "SKKServClientConnectionRefused")
case .connectionTimeout:
logger.info("skkservへの接続がタイムアウトしました")
information = String(localized: "SKKServClientConnectionTimeout")
case .timeout:
logger.info("skkservへの通信がタイムアウトしました")
information = String(localized: "SKKServClientTimeout")
default:
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
}
} else {
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
}
showError(error)
}
testing = false
} label: {
Text("Test")
Text("Connection Test")
.padding([.leading, .trailing])
}
.disabled(testing)
Expand All @@ -98,7 +107,32 @@ struct SKKServDictView: View {
.padding()
Spacer()
}
.frame(width: 480, height: 270)
.frame(width: 480, height: 400)
}

private func showError(_ error: any Error) {
if let error = error as? SKKServClientError {
switch error {
case .unexpected:
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
case .connectionRefused:
logger.info("skkservへの通信ができませんでした")
information = String(localized: "SKKServClientConnectionRefused")
case .connectionTimeout:
logger.info("skkservへの接続がタイムアウトしました")
information = String(localized: "SKKServClientConnectionTimeout")
case .timeout:
logger.info("skkservへの通信がタイムアウトしました")
information = String(localized: "SKKServClientTimeout")
default:
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
}
} else {
logger.error("SKKServClientへのXPC呼び出しで不明なエラーが発生しました")
information = String(localized: "SKKServClientUnknownError")
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion macSKK/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"LoadingStatusUnknown" = "Unknown";
"SKKServDictTitle" = "SKKServ Dictionary Setting";
"SKKServDictTesting" = "Testing to connect to skkserv…";
"SKKServDictReferTestTitle" = "SKKServ Dictionary Referring Test";
"SKKServClientConnected" = "Succeeded to connect to skkserv.";
"SKKServClientUnknownError" = "Unknown error occurred while connecting to skkserv.";
"SKKServClientConnectionRefused" = "Failed to connect to skkserv.";
Expand Down Expand Up @@ -74,10 +75,12 @@
"Add…" = "Add…";
"Cancel" = "Cancel";
"Add" = "Add";
"Test" = "Test";
"Connection Test" = "Connection Test";
"Address" = "Address";
"TCP Port" = "TCP Port No.";
"Response Encoding" = "Response Encoding";
"Yomi" = "Yomi";
"Refer" = "Refer";
"Rename" = "Rename";
"Duplicate" = "Duplicate";
"Edit" = "Edit";
Expand Down
5 changes: 4 additions & 1 deletion macSKK/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"LoadingStatusUnknown" = "不明";
"SKKServDictTitle" = "SKKServ辞書の設定";
"SKKServDictTesting" = "SKKServへの接続テスト中…";
"SKKServDictReferTestTitle" = "SKKServ辞書の参照テスト";
"SKKServClientConnected" = "skkservへの接続に成功しました";
"SKKServClientUnknownError" = "skkservへの接続中に不明なエラーが発生しました";
"SKKServClientConnectionRefused" = "skkservに接続できませんでした";
Expand Down Expand Up @@ -74,10 +75,12 @@
"Add…" = "追加…";
"Cancel" = "キャンセル";
"Add" = "追加";
"Test" = "テスト";
"Connection Test" = "接続テスト";
"Address" = "アドレス";
"TCP Port" = "TCPポート番号";
"Response Encoding" = "応答エンコーディング";
"Yomi" = "読み";
"Refer" = "参照";
"Rename" = "リネーム";
"Duplicate" = "複製";
"Edit" = "編集";
Expand Down

0 comments on commit 4f4ba41

Please sign in to comment.