Skip to content

Commit 07b2798

Browse files
committed
restart server on client update
1 parent 5885850 commit 07b2798

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

fcitx5-hazkey/src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ else()
5252
message(FATAL_ERROR "protobuf 3.12+ required for proto3 optional support. Current version: ${Protobuf_VERSION}")
5353
endif()
5454

55+
configure_file(hazkey_constants.h.in hazkey_constants.h @ONLY)
56+
5557
target_include_directories(fcitx5-hazkey PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${Protobuf_INCLUDE_DIRS})
5658
target_link_libraries(fcitx5-hazkey PRIVATE Fcitx5::Core Fcitx5::Config ${Protobuf_LITE_LIBRARIES})
5759

fcitx5-hazkey/src/hazkey_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
#include <fcitx-utils/library.h>
88
#include <fcitx/menu.h>
99

10+
#include "hazkey_constants.h"
11+
1012
namespace fcitx {
1113

1214
/// Config
1315

1416
FCITX_CONFIGURATION(HazkeyEngineConfig,
17+
HiddenOption<std::string> lastVersion{
18+
this, "LastVersion", "", ""};
1519
Option<bool> showTabToSelect{
1620
this, "showTabToSelect",
1721
_("Show [Press Tab to Select] indicator"), true};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef CONSTANTS_H
2+
#define CONSTANTS_H
3+
4+
#include <string>
5+
6+
const std::string HAZKEY_VERSION = "@PROJECT_VERSION@";
7+
8+
#endif

fcitx5-hazkey/src/hazkey_engine.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "hazkey_server_connector.h"
66
#include "hazkey_state.h"
7+
#include "hazkey_constants.h"
78

89
namespace fcitx {
910

@@ -14,7 +15,7 @@ HazkeyEngine::HazkeyEngine(Instance *instance)
1415
server_ = HazkeyServerConnector();
1516

1617
instance->inputContextManager().registerProperty("hazkeyState", &factory_);
17-
// reloadConfig();
18+
reloadConfig();
1819
}
1920

2021
void HazkeyEngine::keyEvent([[maybe_unused]] const InputMethodEntry &entry,
@@ -56,17 +57,18 @@ void HazkeyEngine::setConfig(const RawConfig &config) {
5657
}
5758

5859
void HazkeyEngine::reloadConfig() {
59-
// server will directly read config
60-
//
6160
readAsIni(config_, "conf/hazkey.conf");
62-
// server_.setServerConfig(
63-
// *config().zenzaiEnabled, *config().zenzaiInferenceLimit,
64-
// static_cast<int>(*config().numberStyle),
65-
// static_cast<int>(*config().symbolStyle),
66-
// static_cast<int>(*config().periodStyle),
67-
// static_cast<int>(*config().commaStyle),
68-
// static_cast<int>(*config().spaceStyle),
69-
// static_cast<int>(*config().diacriticStyle), *config().zenzaiProfile);
61+
62+
std::string lastVersion = config_.lastVersion.value();
63+
64+
if (lastVersion != HAZKEY_VERSION) {
65+
FCITX_DEBUG() << "Update detected. restarting server..";
66+
// server automatically restarts if current server is newer than running server.
67+
server_.start_hazkey_server();
68+
69+
config_.lastVersion.setValue(HAZKEY_VERSION);
70+
safeSaveAsIni(config_, "conf/hazkey.conf");
71+
}
7072
}
7173

7274
void HazkeyEngine::save() {

fcitx5-hazkey/src/hazkey_server_connector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class HazkeyServerConnector {
2626

2727
void connect_server();
2828

29+
void start_hazkey_server();
30+
2931
std::optional<hazkey::ResponseEnvelope> transact(
3032
const hazkey::RequestEnvelope& send_data);
3133

@@ -70,7 +72,6 @@ class HazkeyServerConnector {
7072

7173
private:
7274
bool retry_connect();
73-
void start_hazkey_server();
7475
bool is_hazkey_server_running();
7576
bool requestSuccess(hazkey::ResponseEnvelope);
7677
int sock_ = -1;

hazkey-server/Sources/hazkey-server/processManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class ProcessManager {
3434
return versionString != hazkeyVersion
3535
}
3636
}
37-
return false
37+
// restart if file does not exists
38+
return true
3839
}
3940

4041
func checkExistingServer() throws {

0 commit comments

Comments
 (0)