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 authored and lotem committed Jan 14, 2025
1 parent b34e4ac commit 6f6f540
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/rime_api_console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,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 @@ -225,13 +233,7 @@ 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");
SetConsoleOutputCodePage(codepage);
return 1;
}

RimeSessionId session_id = 0;
const int kMaxLength = 99;
char line[kMaxLength + 1] = {0};
while (fgets(line, kMaxLength, stdin) != NULL) {
Expand All @@ -241,6 +243,11 @@ 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 6f6f540

Please sign in to comment.