From a0d71a9708da0c0effd5d87695e4bc2f1ced3f65 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Mon, 8 Jul 2024 22:43:21 +0200 Subject: [PATCH 1/2] Clear Swift warnings --- CMakeLists.txt | 8 +++++++- src/config/dictmanager.swift | 6 +++--- src/config/imageoptionview.swift | 4 ++-- src/config/installer.swift | 2 +- src/config/plugin.swift | 4 ++-- src/config/util.swift | 15 ++++++++++++--- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d9f69..4db2209 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,12 @@ set(LibIntl_DIR "${PREBUILT_INSTALL_PATH}/lib/cmake") find_package(LibIntl) set(fmt_DIR "${PREBUILT_INSTALL_PATH}/lib/cmake/fmt") find_package(fmt) +if (TARGET fmt::fmt-header-only) + # Resolve swiftc warnings + set_target_properties(fmt::fmt-header-only PROPERTIES + INTERFACE_COMPILE_DEFINITIONS "FMT_HEADER_ONLY" + ) +endif() option(ENABLE_TEST "" OFF) option(ENABLE_COVERAGE "" OFF) @@ -77,7 +83,7 @@ include_directories( "${HOMEBREW_PATH}/include" # nlohmann-json ) -add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-macos\") +add_compile_definitions($<$:-DFCITX_GETTEXT_DOMAIN=\"fcitx5-macos\">) add_subdirectory(macosfrontend) add_subdirectory(macosnotifications) diff --git a/src/config/dictmanager.swift b/src/config/dictmanager.swift index 2134e7c..8fc616c 100644 --- a/src/config/dictmanager.swift +++ b/src/config/dictmanager.swift @@ -92,9 +92,9 @@ struct DictManagerView: View { let enabledPath = dictDir.appendingPathComponent(dict.id + ".dict") let disabledPath = dictDir.appendingPathComponent(dict.id + ".dict.disable") if $0 { - moveFile(disabledPath, enabledPath) + let _ = moveFile(disabledPath, enabledPath) } else { - moveFile(enabledPath, disabledPath) + let _ = moveFile(enabledPath, disabledPath) } reloadDicts() } @@ -145,7 +145,7 @@ struct DictManagerView: View { Button { for dict in selectedDicts { - removeFile(dictDir.appendingPathComponent(dict + ".dict")) + let _ = removeFile(dictDir.appendingPathComponent(dict + ".dict")) } selectedDicts.removeAll() reloadDicts() diff --git a/src/config/imageoptionview.swift b/src/config/imageoptionview.swift index ee8e527..5e51ed0 100644 --- a/src/config/imageoptionview.swift +++ b/src/config/imageoptionview.swift @@ -43,8 +43,8 @@ struct ImageOptionView: OptionView { var body: some View { VStack { Picker("", selection: $model.mode) { - ForEach(0.. Bool { let url = getCacheURL(plugin, native: native) let path = url.localPath() let ret = exec("/usr/bin/tar", ["-xjf", path, "-C", libraryDir.localPath()]) - removeFile(url) + let _ = removeFile(url) return ret } diff --git a/src/config/plugin.swift b/src/config/plugin.swift index 4505fe6..0c08fdd 100644 --- a/src/config/plugin.swift +++ b/src/config/plugin.swift @@ -176,9 +176,9 @@ struct PluginView: View { if keptFiles.contains(file) { continue } - removeFile(libraryDir.appendingPathComponent(file)) + let _ = removeFile(libraryDir.appendingPathComponent(file)) } - removeFile(descriptor) + let _ = removeFile(descriptor) FCITX_INFO("Uninstalled \(selectedPlugin)") } selectedInstalled.removeAll() diff --git a/src/config/util.swift b/src/config/util.swift index 9f1693a..ed958dd 100644 --- a/src/config/util.swift +++ b/src/config/util.swift @@ -175,14 +175,23 @@ func readJSON(_ file: URL) -> JSON? { func openInEditor(_ path: String) { let apps = ["VSCodium", "Visual Studio Code"] + let fileURL = URL(fileURLWithPath: path) for app in apps { let appURL = URL(fileURLWithPath: "/Applications/\(app).app") - if appURL.exists() { - NSWorkspace.shared.openFile(path, withApplication: app) + if FileManager.default.fileExists(atPath: appURL.path) { + NSWorkspace.shared.open( + [fileURL], withApplicationAt: appURL, configuration: NSWorkspace.OpenConfiguration(), + completionHandler: nil) return } } - NSWorkspace.shared.openFile(path, withApplication: "TextEdit") + if let textEditURL = NSWorkspace.shared.urlForApplication( + withBundleIdentifier: "com.apple.TextEdit") + { + NSWorkspace.shared.open( + [fileURL], withApplicationAt: textEditURL, configuration: NSWorkspace.OpenConfiguration(), + completionHandler: nil) + } } func exec(_ command: String, _ args: [String]) -> Bool { From 884cb51770750de834e1c3211df60bc39e4025f7 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Tue, 9 Jul 2024 19:25:47 +0200 Subject: [PATCH 2/2] address comments --- src/config/customphrase.swift | 2 +- src/config/imageoptionview.swift | 2 +- src/config/quickphrase.swift | 3 +-- src/config/util.swift | 9 ++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/config/customphrase.swift b/src/config/customphrase.swift index b47c4b0..eb84632 100644 --- a/src/config/customphrase.swift +++ b/src/config/customphrase.swift @@ -201,7 +201,7 @@ struct CustomPhraseView: View { return } } - openInEditor(customphrase.localPath()) + openInEditor(url: customphrase) } label: { Text("Open in editor") } diff --git a/src/config/imageoptionview.swift b/src/config/imageoptionview.swift index 5e51ed0..523eaae 100644 --- a/src/config/imageoptionview.swift +++ b/src/config/imageoptionview.swift @@ -43,7 +43,7 @@ struct ImageOptionView: OptionView { var body: some View { VStack { Picker("", selection: $model.mode) { - ForEach(Array(modes.enumerated()), id: \.element) { idx, mode in + ForEach(Array(modes.enumerated()), id: \.0) { idx, mode in Text(mode) } } diff --git a/src/config/quickphrase.swift b/src/config/quickphrase.swift index 3c48b32..8772b73 100644 --- a/src/config/quickphrase.swift +++ b/src/config/quickphrase.swift @@ -196,7 +196,6 @@ struct QuickPhraseView: View { Button { mkdirP(localQuickphrasePath) let localURL = localQuickphraseDir.appendingPathComponent(quickphraseVM.current + ".mb") - let path = localURL.localPath() if !localURL.exists() { if !copyFile( globalQuickphraseDir.appendingPathComponent(quickphraseVM.current + ".mb"), @@ -206,7 +205,7 @@ struct QuickPhraseView: View { return } } - openInEditor(path) + openInEditor(url: localURL) } label: { Text("Open in editor") }.disabled(quickphraseVM.current.isEmpty) diff --git a/src/config/util.swift b/src/config/util.swift index ed958dd..30c453a 100644 --- a/src/config/util.swift +++ b/src/config/util.swift @@ -173,14 +173,13 @@ func readJSON(_ file: URL) -> JSON? { return nil } -func openInEditor(_ path: String) { +func openInEditor(url: URL) { let apps = ["VSCodium", "Visual Studio Code"] - let fileURL = URL(fileURLWithPath: path) for app in apps { let appURL = URL(fileURLWithPath: "/Applications/\(app).app") - if FileManager.default.fileExists(atPath: appURL.path) { + if appURL.exists() { NSWorkspace.shared.open( - [fileURL], withApplicationAt: appURL, configuration: NSWorkspace.OpenConfiguration(), + [url], withApplicationAt: appURL, configuration: NSWorkspace.OpenConfiguration(), completionHandler: nil) return } @@ -189,7 +188,7 @@ func openInEditor(_ path: String) { withBundleIdentifier: "com.apple.TextEdit") { NSWorkspace.shared.open( - [fileURL], withApplicationAt: textEditURL, configuration: NSWorkspace.OpenConfiguration(), + [url], withApplicationAt: textEditURL, configuration: NSWorkspace.OpenConfiguration(), completionHandler: nil) } }