Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear Swift warnings #173

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -77,7 +83,7 @@ include_directories(
"${HOMEBREW_PATH}/include" # nlohmann-json
)

add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-macos\")
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:-DFCITX_GETTEXT_DOMAIN=\"fcitx5-macos\">)

add_subdirectory(macosfrontend)
add_subdirectory(macosnotifications)
Expand Down
2 changes: 1 addition & 1 deletion src/config/customphrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct CustomPhraseView: View {
return
}
}
openInEditor(customphrase.localPath())
openInEditor(url: customphrase)
} label: {
Text("Open in editor")
}
Expand Down
6 changes: 3 additions & 3 deletions src/config/dictmanager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/config/imageoptionview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct ImageOptionView: OptionView {
var body: some View {
VStack {
Picker("", selection: $model.mode) {
ForEach(0..<modes.count) { idx in
Text(modes[idx])
ForEach(Array(modes.enumerated()), id: \.0) { idx, mode in
Text(mode)
ksqsf marked this conversation as resolved.
Show resolved Hide resolved
}
}
if model.mode == 0 {
Expand Down
2 changes: 1 addition & 1 deletion src/config/installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private func extractPlugin(_ plugin: String, native: Bool) -> 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
}

Expand Down
4 changes: 2 additions & 2 deletions src/config/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/config/quickphrase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -206,7 +205,7 @@ struct QuickPhraseView: View {
return
}
}
openInEditor(path)
openInEditor(url: localURL)
} label: {
Text("Open in editor")
}.disabled(quickphraseVM.current.isEmpty)
Expand Down
14 changes: 11 additions & 3 deletions src/config/util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,24 @@ func readJSON(_ file: URL) -> JSON? {
return nil
}

func openInEditor(_ path: String) {
func openInEditor(url: URL) {
let apps = ["VSCodium", "Visual Studio Code"]
for app in apps {
let appURL = URL(fileURLWithPath: "/Applications/\(app).app")
if appURL.exists() {
NSWorkspace.shared.openFile(path, withApplication: app)
NSWorkspace.shared.open(
[url], 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(
[url], withApplicationAt: textEditURL, configuration: NSWorkspace.OpenConfiguration(),
completionHandler: nil)
}
}

func exec(_ command: String, _ args: [String]) -> Bool {
Expand Down