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

fix(rime_api_console): recreate session when necessary #893

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
21 changes: 14 additions & 7 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,13 +213,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 @@ -221,6 +223,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
Loading