From 52fa22ff1a075df68cdda9fac8eb24ef7d9e2028 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Wed, 1 Jan 2025 17:50:24 -0500 Subject: [PATCH] Support switch between debug and release (#216) --- .github/workflows/ci.yml | 2 + .gitignore | 1 - assets/update.sh | 6 ++- assets/zh-Hans.lproj/Localizable.strings | Bin 22560 -> 23262 bytes logging/CMakeLists.txt | 9 ++-- logging/debug.swift | 1 + logging/debug.swift.in | 1 - logging/release.swift | 1 + src/CMakeLists.txt | 5 ++ src/config/about.swift | 65 +++++++++++++++++++---- src/config/installer.swift | 14 +++-- src/config/plugin.swift | 3 +- src/fcitx.cpp | 14 ++--- src/fcitx.h | 2 +- 14 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 logging/debug.swift delete mode 100644 logging/debug.swift.in create mode 100644 logging/release.swift diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02b34396..e966dccf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,8 +68,10 @@ jobs: - name: Build run: | + # Don't log key on any CI artifact. cmake -B build -G Ninja \ -DCMAKE_Swift_COMPILER=`which swiftc` \ + -DVERBOSE_LOGGING=OFF \ -DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} \ -DCMAKE_BUILD_TYPE=${{ matrix.type }} cmake --build build diff --git a/.gitignore b/.gitignore index ca42552f..3daa43e9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,4 @@ build assets/en.lproj/Localizable.strings assets/po/base.pot meta.swift -debug.swift *~ diff --git a/assets/update.sh b/assets/update.sh index edb5aa2b..ee807ab7 100755 --- a/assets/update.sh +++ b/assets/update.sh @@ -7,7 +7,11 @@ INSTALL_DIR="/Library/Input Methods" APP_DIR="$INSTALL_DIR/Fcitx5.app" RESOURCES_DIR="$APP_DIR/Contents/Resources" -rm -rf "$APP_DIR/Contents/*" +# Don't remove files that must exist (which will be overwritten) as that will put Fcitx5 in a registered-but-not-listed state. +rm -rf "$APP_DIR"/Contents/{bin,lib,share,Resources} +if ls "$APP_DIR"/Contents/MacOS/Fcitx5.*; then # Debug symbols + rm -rf "$APP_DIR"/Contents/MacOS/Fcitx5.* +fi tar xjvf "$tar_ball" -C "$INSTALL_DIR" rm -f "$tar_ball" xattr -dr com.apple.quarantine "$APP_DIR" diff --git a/assets/zh-Hans.lproj/Localizable.strings b/assets/zh-Hans.lproj/Localizable.strings index b0fe57a7772b04d6061580b00f8528240f1909b4..a8213e14668d641b0039ab186031bbe869939586 100644 GIT binary patch delta 378 zcmZ3mf$`o}#tnPKrBfM_7)lw^8I%|l7;J%9iNS>dDmK|rCUWyGaUT=gV1{yrOokGM zWQGi&k`jh|APHB7q?J7=DcK+hSx$k$V{)NqbUmj26qq$Yv+^187;+dYfvil1G$82) zw5bHhu3#_)@{$>f7!nzZfp(_?Nd+J~k0Av}R|55w0_k$FNC}VyaT!Qm4nqNu54Xde zK@Z89NBx51`C}OUUFT`WHs_VaiTJHZuutSq^bcMcG%5LMx^L2yIILbNnyla+V}j|I gAh3<8U{|IhSp+iVUf9K8=D5iR Bool { } class Updater { - private var main: Bool - private var nativePlugins: [String] - private var dataPlugins: [String] + private let main: Bool + private let debug: Bool + private let nativePlugins: [String] + private let dataPlugins: [String] - init(main: Bool, nativePlugins: [String], dataPlugins: [String]) { + init(main: Bool, debug: Bool, nativePlugins: [String], dataPlugins: [String]) { self.main = main + self.debug = debug self.nativePlugins = nativePlugins self.dataPlugins = dataPlugins } @@ -70,6 +72,8 @@ class Updater { onFinish: @escaping (Bool, [String: Bool], [String: Bool]) -> Void, onProgress: ((Double) -> Void)? = nil ) { + let mainAddress = + "\(sourceRepo)/releases/download/latest/\(self.debug ? mainDebugFileName : mainFileName)" let downloader = Downloader( nativePlugins.map({ getAddress($0, native: true) }) + dataPlugins.map({ getAddress($0, native: false) }) + (main ? [mainAddress] : []) diff --git a/src/config/plugin.swift b/src/config/plugin.swift index 94f441cd..a87438e8 100644 --- a/src/config/plugin.swift +++ b/src/config/plugin.swift @@ -222,7 +222,8 @@ struct PluginView: View { let selectedPlugins = selectedAvailable selectedAvailable.removeAll() - let updater = Updater(main: false, nativePlugins: nativeAvailable, dataPlugins: dataAvailable) + let updater = Updater( + main: false, debug: false, nativePlugins: nativeAvailable, dataPlugins: dataAvailable) updater.update( onFinish: { _, nativeResults, dataResults in processing = false diff --git a/src/fcitx.cpp b/src/fcitx.cpp index 47d0494b..6d301329 100644 --- a/src/fcitx.cpp +++ b/src/fcitx.cpp @@ -38,7 +38,7 @@ Fcitx &Fcitx::shared() { } Fcitx::Fcitx() { - setupLog(true); + setupLog(); setupEnv(); } @@ -99,15 +99,15 @@ void Fcitx::teardown() { instance_.reset(); } -void Fcitx::setupLog(bool verbose) { +void Fcitx::setupLog() { static native_streambuf log_streambuf; static std::ostream stream(&log_streambuf); fcitx::Log::setLogStream(stream); - if (verbose) { - fcitx::Log::setLogRule("*=5,notimedate"); - } else { - fcitx::Log::setLogRule("notimedate"); - } +#ifdef VERBOSE_LOGGING + fcitx::Log::setLogRule("*=5,notimedate"); +#else + fcitx::Log::setLogRule("*=4,notimedate"); +#endif } void Fcitx::setupEnv() { diff --git a/src/fcitx.h b/src/fcitx.h index 4897705a..602e2482 100644 --- a/src/fcitx.h +++ b/src/fcitx.h @@ -30,7 +30,7 @@ class Fcitx final { fcitx::MacosFrontend *frontend(); private: - void setupLog(bool verbose); + void setupLog(); void setupEnv(); void setupInstance();