mirror of
https://github.com/tiennm99/claude-code-usage-bubble.git
synced 2026-10-23 18:17:21 +00:00
run() keeps the pre-builder order: diagnostic log, the Windows WebView2 guard (a message box with the download link, then exit 0), the --wait-pid wait capped at 15 s, GDK_BACKEND=x11 under Wayland when Xwayland is present, and the single-instance plugin registered first with a no-op callback. setup() loads the settings, drops positions on missing monitors, reads the theme, cleans up after earlier updates, starts the scheduler and polls. The state sits behind one mutex reached only through with_state, so no Tauri call runs under the lock. The poll worker keeps the in-flight gate, applies the results, runs the CLI credential refresh and pushes bubble payloads from the main thread. Commands: get_bubble_state, get_strings, log_js and bubble_ready. Bubble windows ignore close requests; Restart saves the settings and exits only once the new instance spawned. The scaffold window now renders its payload as JSON. The Win32 app module is removed.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
// Test view: renders the bubble payload as raw JSON until the real bubble
|
|
// UI replaces this page.
|
|
|
|
const tauri = window.__TAURI__;
|
|
const view = /** @type {HTMLElement} */ (document.getElementById('payload'));
|
|
const webview = tauri.webviewWindow.getCurrentWebviewWindow();
|
|
const provider = webview.label.replace(/^bubble-/, '');
|
|
|
|
/**
|
|
* Forward a message to the diagnostic log.
|
|
* @param {'error' | 'warn' | 'info' | 'debug'} level Log level.
|
|
* @param {string} message Text to log.
|
|
* @returns {void}
|
|
*/
|
|
function logJs(level, message) {
|
|
tauri.core.invoke('log_js', { level, message }).catch(() => {});
|
|
}
|
|
|
|
/**
|
|
* Show one payload.
|
|
* @param {unknown} payload The bubble payload from Rust.
|
|
* @returns {void}
|
|
*/
|
|
function render(payload) {
|
|
view.textContent = JSON.stringify(payload, null, 2);
|
|
}
|
|
|
|
window.addEventListener('error', (event) => {
|
|
logJs('error', `${event.message} at ${event.filename}:${event.lineno}`);
|
|
});
|
|
window.addEventListener('unhandledrejection', (event) => {
|
|
logJs('error', `unhandled rejection: ${String(event.reason)}`);
|
|
});
|
|
|
|
webview
|
|
.listen('bubble:update', (event) => render(event.payload))
|
|
.catch((err) => logJs('error', `listen failed: ${String(err)}`));
|
|
|
|
tauri.core
|
|
.invoke('get_bubble_state', { provider })
|
|
.then((payload) => {
|
|
render(payload);
|
|
return tauri.core.invoke('bubble_ready', { label: webview.label });
|
|
})
|
|
.catch((err) => {
|
|
view.textContent = `get_bubble_state failed: ${String(err)}`;
|
|
logJs('error', `startup failed: ${String(err)}`);
|
|
});
|