Skip to content

Commit

Permalink
feat: Bind close button
Browse files Browse the repository at this point in the history
  • Loading branch information
jimbob88 committed Jun 4, 2024
1 parent 80546fd commit 947a185
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ ipcMain.handle(
throw new Error("Unsupported file format!");
},
);

ipcMain.handle("close", async (event: Electron.IpcMainEvent) => {
app.quit();
});
1 change: 1 addition & 0 deletions main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type IpcHandler = typeof handler;
contextBridge.exposeInMainWorld("electron", {
readFile: (filePath: string) =>
ipcRenderer.invoke("read-excel-file", filePath),
close: () => ipcRenderer.invoke("close"),
});
12 changes: 11 additions & 1 deletion renderer/pages/layouts/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import logo from "../../../resources/icon.svg";

export default function Layout(props: PropsWithChildren) {
const { children } = props;

const close = () => {
console.log("Gonna Close!");
window.electron.close();
};

return (
<div className="flex flex-col h-full rounded-lg">
<header className="shadow-md">
Expand All @@ -20,7 +26,11 @@ export default function Layout(props: PropsWithChildren) {
</span>
</span>
<span className="flex items-center">
<button className="w-6 h-6 text-gray-800 dark:text-white">
<button
id="close-button"
className="w-6 h-6 text-gray-800 dark:text-white"
onClick={close}
>
<svg
className="w-6 h-6 text-gray-800 dark:text-white"
aria-hidden="true"
Expand Down
4 changes: 4 additions & 0 deletions renderer/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
-webkit-app-region: drag;
user-select: none;
}

#close-button {
-webkit-app-region: no-drag;
}
}

0 comments on commit 947a185

Please sign in to comment.