webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.95k stars 171 forks source link

High Contrast Management #433

Closed malisipi closed 3 months ago

malisipi commented 3 months ago

To get more information about why it's required, you can browse #432.

malisipi commented 3 months ago

I am not much knowledge about WebUI Frontend API. So I couldn't implement the API however since backend is exist of API, it should not be hard. Also I have not a Mac computer, so I can not implement detecting on MacOS.

hassandraga commented 3 months ago

Thank you @malisipi for this new feature, I will try to implement the macOS and frontend part later.

hassandraga commented 3 months ago

Backend (https://github.com/webui-dev/webui/commit/acc77ce5d22cb4883ecee73abfd9a22ee2ed99e4). Frontend (https://github.com/webui-dev/webui/commit/88cd5f3774a00ff37a2fdf5557e4f3e76fcf5a58).

Thank you @malisipi for the idea of frontend, now, we have an easy mechanism to internally call any core API from Bridge:

Bridge:

async isHighContrast(): Promise<boolean> {
    // Call a core function and wait for response
    const response = await this.callCore("_YOUR_CORE_SHORT_ID_HERE_") as boolean; // Any datatype
    if (this.#log) console.log(`Core Response: [${response}]`);
    return response;
}

webui.c:

static void _webui_bridge_api_handler(webui_event_t* e) {
    // ...

    if (strcmp(api_name, "_YOUR_CORE_SHORT_ID_HERE_") == 0) {
        webui_return_bool(e, webui_is_high_contrast()); // Any API
    }
}