Skip to content

Commit

Permalink
fix(rime_api_console): recreate session when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf committed Jan 13, 2025
1 parent a735e42 commit 6446a82
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions tools/rime_api_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ void on_message(void* context_object,
}
}

RimeSessionId ensure_session(RimeApi *rime) {
RimeSessionId id = rime->create_session();
if (!id) {
fprintf(stderr, "Error creating rime session.\n");
}
return id;
}

int main(int argc, char* argv[]) {
unsigned int codepage = SetConsoleOutputCodePage();
RimeApi* rime = rime_get_api();
Expand All @@ -205,9 +213,8 @@ int main(int argc, char* argv[]) {
rime->join_maintenance_thread();
fprintf(stderr, "ready.\n");

RimeSessionId session_id = rime->create_session();
if (!session_id) {
fprintf(stderr, "Error creating rime session.\n");
RimeSessionId session_id = 0;
if (!(session_id = ensure_session(rime))) {
SetConsoleOutputCodePage(codepage);
return 1;
}
Expand All @@ -221,6 +228,10 @@ int main(int argc, char* argv[]) {
break;
}
}
if (!rime->find_session(session_id) && !(session_id = ensure_session(rime))) {
SetConsoleOutputCodePage(codepage);
return 1;
}
if (!strcmp(line, "exit"))
break;
else if (!strcmp(line, "reload")) {
Expand Down

0 comments on commit 6446a82

Please sign in to comment.