feat: tauri custom titlebar#198
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements a custom window titlebar for the application. It disables default OS window decorations in tauri.conf.json, configures the necessary Tauri window permissions, and introduces a new Titlebar.astro component with custom controls (minimize, close, bug, and donate buttons). Additionally, layout and style adjustments are made across several components to accommodate the new titlebar. Feedback highlights include renaming the shadowed global window variable and replacing unsafe non-null assertions (!) with optional chaining (?.) in Titlebar.astro, as well as removing a commented-out debug border in Sidebar.astro.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const window = getCurrentWindow(); | ||
| const title = document.getElementById("title"); | ||
|
|
||
| function updateTitle(isFocused) { | ||
| if (isFocused) { | ||
| title!.style.color = "var(--text)"; | ||
| } else { | ||
| title!.style.color = "var(--muted)"; | ||
| } | ||
| } | ||
|
|
||
| window.isFocused().then((focused) => { | ||
| updateTitle(focused); | ||
| }); | ||
|
|
||
| window.listen("tauri://focus", () => { | ||
| updateTitle(true); | ||
| }); | ||
|
|
||
| window.listen("tauri://blur", () => { | ||
| updateTitle(false); | ||
| }); | ||
|
|
||
| document.querySelector(".bug")!.addEventListener("click", () => { | ||
| open("https://github.com/flick9000/winscript/issues"); | ||
| }); | ||
| document.querySelector(".donate")!.addEventListener("click", () => { | ||
| open("https://ko-fi.com/flick9000"); | ||
| }); | ||
| document.querySelector(".minimize")!.addEventListener("click", () => { | ||
| window.minimize(); | ||
| }); | ||
| document.querySelector(".close")!.addEventListener("click", () => { | ||
| window.close(); | ||
| }); |
There was a problem hiding this comment.
Shadowing the global window object by declaring const window = getCurrentWindow() can lead to unexpected bugs and confusion, as other scripts or browser APIs might rely on the global window object. Additionally, using the non-null assertion operator (!) on DOM queries (e.g., title!, document.querySelector(...)!) can cause runtime crashes if the elements are not yet available in the DOM.
It is highly recommended to rename window to appWindow and use optional chaining (?.) or explicit null checks instead of non-null assertions.
const appWindow = getCurrentWindow();
const title = document.getElementById("title");
function updateTitle(isFocused) {
if (title) {
title.style.color = isFocused ? "var(--text)" : "var(--muted)";
}
}
appWindow.isFocused().then((focused) => {
updateTitle(focused);
});
appWindow.listen("tauri://focus", () => {
updateTitle(true);
});
appWindow.listen("tauri://blur", () => {
updateTitle(false);
});
document.querySelector(".bug")?.addEventListener("click", () => {
open("https://github.com/flick9000/winscript/issues");
});
document.querySelector(".donate")?.addEventListener("click", () => {
open("https://ko-fi.com/flick9000");
});
document.querySelector(".minimize")?.addEventListener("click", () => {
appWindow.minimize();
});
document.querySelector(".close")?.addEventListener("click", () => {
appWindow.close();
});
| margin-left: 1rem; | ||
| /* border: 1px solid red; */ |
PR Type
What kind of change does this PR introduce?
Description
Replaced native titlebar with custom one