Skip to content

Commit

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

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

int main(int argc, char* argv[]) {
unsigned int codepage = SetConsoleOutputCodePage();
RimeApi* rime = rime_get_api();
Expand All @@ -205,9 +214,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;
if (!ensure_session(rime, session_id)) {
SetConsoleOutputCodePage(codepage);
return 1;
}
Expand All @@ -221,6 +229,10 @@ int main(int argc, char* argv[]) {
break;
}
}
if (!rime->find_session(session_id) && !ensure_session(rime, session_id)) {
SetConsoleOutputCodePage(codepage);
return 1;
}
if (!strcmp(line, "exit"))
break;
else if (!strcmp(line, "reload")) {
Expand Down

0 comments on commit 4f8bad3

Please sign in to comment.