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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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