Skip to content

Commit

Permalink
feat: switch ascii mode of active session or global(if global_ascii s…
Browse files Browse the repository at this point in the history
…et true), from command line with `WeaselServer.exe /ascii` or `WeaselServer.exe /nascii`
  • Loading branch information
fxliang authored and lotem committed Feb 24, 2024
1 parent 071185c commit c45dfa9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,19 @@ void RimeWithWeaselHandler::EndMaintenance()

void RimeWithWeaselHandler::SetOption(UINT session_id, const std::string & opt, bool val)
{
RimeSetOption(session_id, opt.c_str(), val);
// from no-session client, not actual typing session
if (!session_id)
{
if (m_global_ascii_mode && opt == "ascii_mode")
{
for (auto& pair : m_session_status_map)
RimeSetOption(pair.first, "ascii_mode", val);
}
else
RimeSetOption(m_active_session, opt.c_str(), val);
}
else
RimeSetOption(session_id, opt.c_str(), val);
}

void RimeWithWeaselHandler::OnUpdateUI(std::function<void()> const &cb)
Expand Down
13 changes: 13 additions & 0 deletions WeaselServer/WeaselServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lp
WeaselServerApp::explore(WeaselServerApp::install_dir());
return 0;
}
if (!wcscmp(L"/ascii", lpstrCmdLine) || !wcscmp(L"/nascii", lpstrCmdLine))
{
weasel::Client client;
bool ascii = !wcscmp(L"/ascii", lpstrCmdLine);
if (client.Connect()) // try to connect to running server
{
if (ascii)
client.TrayCommand(ID_WEASELTRAY_ENABLE_ASCII);
else
client.TrayCommand(ID_WEASELTRAY_DISABLE_ASCII);
}
return 0;
}

// command line option /q stops the running server
bool quit = !wcscmp(L"/q", lpstrCmdLine) || !wcscmp(L"/quit", lpstrCmdLine);
Expand Down

0 comments on commit c45dfa9

Please sign in to comment.