Custom title bar (#278)

* #127 intiialize custom title bar

---------

Co-authored-by: neil <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-03-09 12:15:26 +08:00 committed by GitHub
parent bb6dc9903e
commit 1154aa0dc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 23 deletions

View file

@ -1,5 +1,6 @@
import windowStateManager from "electron-window-state"; import windowStateManager from "electron-window-state";
import { app, BrowserWindow, ipcMain, net } from "electron"; import { app, BrowserWindow, ipcMain, net } from "electron";
import { setupTitlebar, attachTitlebarToWindow } from "custom-electron-titlebar/main";
import * as Sentry from "@sentry/electron"; import * as Sentry from "@sentry/electron";
import contextMenu from "electron-context-menu"; import contextMenu from "electron-context-menu";
import serve from "electron-serve"; import serve from "electron-serve";
@ -34,6 +35,8 @@ const port = process.env.PORT || 3000;
const allowDebug = !app.isPackaged || process.env.DEBUG_BUILD === "1"; const allowDebug = !app.isPackaged || process.env.DEBUG_BUILD === "1";
let mainWindow: BrowserWindow | null; let mainWindow: BrowserWindow | null;
setupTitlebar();
function createWindow() { function createWindow() {
const windowState = windowStateManager({ const windowState = windowStateManager({
defaultWidth: 800, defaultWidth: 800,
@ -41,11 +44,12 @@ function createWindow() {
}); });
const mainWindow = new BrowserWindow({ const mainWindow = new BrowserWindow({
titleBarStyle: "hidden",
backgroundColor: "black", backgroundColor: "black",
autoHideMenuBar: true, autoHideMenuBar: true,
trafficLightPosition: { trafficLightPosition: {
x: 17, x: 14,
y: 32 y: 13
}, },
minHeight: 450, minHeight: 450,
minWidth: 500, minWidth: 500,
@ -74,6 +78,7 @@ function createWindow() {
windowState.saveState(mainWindow); windowState.saveState(mainWindow);
}); });
attachTitlebarToWindow(mainWindow);
return mainWindow; return mainWindow;
} }

View file

@ -1,3 +1,5 @@
import { Titlebar } from "custom-electron-titlebar";
const isVite = () => { const isVite = () => {
try { try {
return window.location.href.includes("is-vite"); return window.location.href.includes("is-vite");
@ -17,3 +19,10 @@ if (!isVite()) {
SvelteSentry.init SvelteSentry.init
); );
} }
window.addEventListener("DOMContentLoaded", () => {
// Title bar implemenation
new Titlebar({
titleHorizontalAlignment: "left"
});
});

View file

@ -82,6 +82,7 @@
"axios": "^1.3.2", "axios": "^1.3.2",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"buffer": "^6.0.3", "buffer": "^6.0.3",
"custom-electron-titlebar": "4.2.0-beta.0",
"dayjs": "^1.11.7", "dayjs": "^1.11.7",
"electron-context-menu": "^3.6.1", "electron-context-menu": "^3.6.1",
"electron-log": "^4.4.8", "electron-log": "^4.4.8",

View file

@ -21,20 +21,26 @@
}); });
</script> </script>
<header class="border-gray flex w-full border border-l-0 border-r-0"> <header class="border-gray flex w-full border border-l-0 border-r-0" style="-webkit-app-region: drag">
<a href="/"> <div class="w-16 mr-2">
<img width="40" height="40" src="/images/tea-icon.png" alt="tea" /> <!-- just spacing for the close/expand/ buttons in title bar
</a> todo: handle this different when on linux probably move to right
<ul class="text-gray flex h-10 gap-4 pl-4 align-middle leading-10"> -->
<button on:click={navStore.back} class={$prevPath ? 'active' : ''}>&#8592</button> </div>
<button on:click={navStore.next} class={$nextPath ? 'active' : ''}>&#8594</button> {#if $prevPath || $nextPath}
</ul> <ul class="text-gray flex h-10 gap-4 pl-2 align-middle leading-10 mr-2">
<SearchInput <button on:click={navStore.back} class={$prevPath ? 'active' : ''}>&#8592</button>
class="flex-grow border border-none py-4" <button on:click={navStore.next} class={$nextPath ? 'active' : ''}>&#8594</button>
size="small" </ul>
placeholder={$t("store-search-placeholder")} {/if}
{onSearch} <div class="p-1 flex-grow h-8">
/> <SearchInput
class="w-full border border-gray rounded-sm"
size="small"
placeholder={$t("store-search-placeholder")}
{onSearch}
/>
</div>
<!-- <ul class="text-gray flex gap-4 pr-4 pt-2 align-middle"> <!-- <ul class="text-gray flex gap-4 pr-4 pt-2 align-middle">
<button class="icon-filter hover:text-white" /> <button class="icon-filter hover:text-white" />
<button class="icon-share hover:text-white" /> <button class="icon-share hover:text-white" />

View file

@ -6,7 +6,7 @@
"cli": { "cli": {
"install": "install tea" "install": "install tea"
}, },
"store-search-placeholder": "search the tea store", "store-search-placeholder": "type to search",
"search": "search", "search": "search",
"home": { "home": {
"discover-title": "DISCOVER", "discover-title": "DISCOVER",

View file

@ -17,7 +17,7 @@
}; };
</script> </script>
<section class={`flex items-center border-b border-r-0 border-l-0 py-2 ${size} ${clazz}`}> <section class={`flex items-center pb-1 ${size} ${clazz}`}>
<div class="icon pl-4"> <div class="icon pl-4">
<i class="icon-search-icon" /> <i class="icon-search-icon" />
</div> </div>
@ -26,15 +26,18 @@
<!-- <input type="search" class="w-full bg-black h-12 p-4 border border-x-0 border-gray"/> --> <!-- <input type="search" class="w-full bg-black h-12 p-4 border border-x-0 border-gray"/> -->
<style> <style>
section {
padding-top: 0.15rem;
}
.icon-search-icon { .icon-search-icon {
color: #949494; color: #949494;
margin-right: 20px; margin-right: 10px;
position: relative; position: relative;
top: 2px; top: 3px;
} }
section.medium .icon-search-icon { section.medium .icon-search-icon {
font-size: 30px; font-size: 24px;
} }
section.medium { section.medium {
@ -47,7 +50,6 @@
section input { section input {
font-family: "pp-neue-machina", sans-serif; font-family: "pp-neue-machina", sans-serif;
color: #00ffd0; color: #00ffd0;
text-transform: uppercase;
margin-bottom: -5px; margin-bottom: -5px;
min-width: 60%; min-width: 60%;
padding: 0px; padding: 0px;
@ -59,7 +61,7 @@
} }
section.medium input { section.medium input {
font-size: 24px; font-size: 16px;
} }
section.large input { section.large input {
font-size: 32px; font-size: 32px;

View file

@ -42,6 +42,7 @@ importers:
buffer: ^6.0.3 buffer: ^6.0.3
concurrently: ^7.6.0 concurrently: ^7.6.0
cross-env: ^7.0.3 cross-env: ^7.0.3
custom-electron-titlebar: 4.2.0-beta.0
dayjs: ^1.11.7 dayjs: ^1.11.7
electron: 22.1.0 electron: 22.1.0
electron-builder: ^23.6.0 electron-builder: ^23.6.0
@ -93,6 +94,7 @@ importers:
axios: 1.3.2 axios: 1.3.2
bcryptjs: 2.4.3 bcryptjs: 2.4.3
buffer: 6.0.3 buffer: 6.0.3
custom-electron-titlebar: 4.2.0-beta.0_electron@22.1.0
dayjs: 1.11.7 dayjs: 1.11.7
electron-context-menu: 3.6.1 electron-context-menu: 3.6.1
electron-log: 4.4.8 electron-log: 4.4.8
@ -6006,6 +6008,14 @@ packages:
resolution: {integrity: sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==} resolution: {integrity: sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==}
dev: true dev: true
/custom-electron-titlebar/4.2.0-beta.0_electron@22.1.0:
resolution: {integrity: sha512-d2HMG5uwlnTk6Qug37lYUsRFchXgqEyjhR+b9FnyIAN2l+GGnJohLOfmjgzBM3w/9TmuKI4XGvQiiyHujuZskg==}
peerDependencies:
electron: '>20.0.0'
dependencies:
electron: 22.1.0
dev: false
/data-urls/3.0.2: /data-urls/3.0.2:
resolution: {integrity: sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==} resolution: {integrity: sha512-Jy/tj3ldjZJo63sVAvg6LHt2mHvl4V6AgRAmNDtLdm7faqtsx+aJG42rsyCo9JCoRVKwPFzKlIPx3DIibwSIaQ==}
engines: {node: '>=12'} engines: {node: '>=12'}