From 2c92ae4957b4f8396bb657b66af9db29c71d1eea Mon Sep 17 00:00:00 2001 From: Ailton Loures Date: Tue, 1 Oct 2024 13:53:57 -0300 Subject: [PATCH] feat: implementing window component --- src/main/app/components/tray.js | 29 ++++++++--- src/main/app/components/window.js | 46 +++++++++++++++++- src/main/app/index.js | 31 ++---------- src/main/app/store/config/store.js | 1 + src/renderer/index.html | 1 - .../icons/{main-icon.png => tray-icon.png} | Bin src/resources/icons/win-icon.png | Bin 0 -> 4940 bytes 7 files changed, 72 insertions(+), 36 deletions(-) rename src/resources/icons/{main-icon.png => tray-icon.png} (100%) create mode 100644 src/resources/icons/win-icon.png diff --git a/src/main/app/components/tray.js b/src/main/app/components/tray.js index 857675d..c979100 100644 --- a/src/main/app/components/tray.js +++ b/src/main/app/components/tray.js @@ -1,23 +1,35 @@ -import { dialog, Tray as ElectronTray, Menu } from 'electron/main'; +import { dialog, Tray as ElectronTray, Menu, nativeImage } from 'electron/main'; import { spawn } from 'node:child_process'; -import { basename } from 'node:path'; +import { basename, resolve } from 'node:path'; /** * Define Tray application component * @param {import('..').Context} context */ -export const Tray = ({ - app, - info: { title, icon }, - store: { bookmarkStore }, -}) => { +export const Tray = ({ app, store: { bookmarkStore } }) => { /** * Electron Tray instance - * @type {Electron.Tray|undefined} tray + * @type {Electron.Tray|undefined} * @private */ let tray = null; + /** + * Get tray title + * @type {string} + * @private + */ + const title = `${app.getName()} - v${app.getVersion()}`; + + /** + * Get tray icon + * @type {Electron.NativeImage} + * @private + */ + const icon = nativeImage.createFromPath( + resolve('src', 'resources', 'icons', 'tray-icon.png') + ); + /** * Create a new tray instance */ @@ -34,6 +46,7 @@ export const Tray = ({ /** * Create a new context menu for the tray + * @private */ function createContextMenu() { return Menu.buildFromTemplate([ diff --git a/src/main/app/components/window.js b/src/main/app/components/window.js index 47d5de8..fbdb7ef 100644 --- a/src/main/app/components/window.js +++ b/src/main/app/components/window.js @@ -1,5 +1,49 @@ +import { BrowserWindow, nativeImage } from 'electron/main'; +import { resolve } from 'node:path'; + /** * Define Window application component * @param {import('..').Context} context */ -export const Window = () => {}; +export const Window = ({ app }) => { + /** + * Electron Browser window instance + * @type {Electron.BrowserWindow|undefined} + */ + let win = null; + + /** + * Get window title + * @type {string} + * @private + */ + const title = app.getName(); + + /** + * Get window icon + * @type {Electron.NativeImage} + * @private + */ + const icon = nativeImage.createFromPath( + resolve('src', 'resources', 'icons', 'tray-icon.png') + ); + + /** + * Create a new window instance + */ + function render() { + win = new BrowserWindow({ + icon, + title, + width: 520, + height: 400, + webPreferences: { + preload: resolve('src', 'main', 'preload.js'), + }, + }); + + win.loadFile(resolve('src', 'renderer', 'index.html')); + } + + return { render, win }; +}; diff --git a/src/main/app/index.js b/src/main/app/index.js index 2a4a3ec..08117e8 100644 --- a/src/main/app/index.js +++ b/src/main/app/index.js @@ -1,15 +1,6 @@ -import { nativeImage } from 'electron/main'; -import { resolve } from 'node:path'; - -import { Tray } from './components/index.js'; +import { Tray, Window } from './components/index.js'; import { BookmarkStore } from './store/index.js'; -/** - * @typedef Info - * @property {string} title - * @property {Electron.NativeImage} icon - */ - /** * @typedef Store * @property {BookmarkStore} bookmarkStore @@ -18,7 +9,6 @@ import { BookmarkStore } from './store/index.js'; /** * @typedef Context * @property {Electron.App} app - * @property {Info} info * @property {Store} store */ @@ -27,19 +17,6 @@ import { BookmarkStore } from './store/index.js'; * @param {Electron.App} app */ export const App = (app) => { - /** - * Get application info. - * @return {Info} - */ - function getInfo() { - return { - title: `${app.getName()} - ${app.getVersion()}`, - icon: nativeImage.createFromPath( - resolve('src', 'resources', 'icons', 'main-icon.png') - ), - }; - } - /** * Get store configuration. * @return {Store} @@ -51,14 +28,16 @@ export const App = (app) => { function start() { const context = { app, - info: getInfo(), store: getStore(), }; app .whenReady() .then(() => console.log('Application is ready\n')) - .then(() => Tray(context).render()); + .then(() => { + Tray(context).render(); + Window(context).render(); + }); } return { diff --git a/src/main/app/store/config/store.js b/src/main/app/store/config/store.js index 1a172fd..e4c49fe 100644 --- a/src/main/app/store/config/store.js +++ b/src/main/app/store/config/store.js @@ -5,6 +5,7 @@ import ElectronStore from 'electron-store'; */ export const Store = { /** + * Instance of Store * @type {ElectronStore|null} * @private */ diff --git a/src/renderer/index.html b/src/renderer/index.html index 736c486..b360b06 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -3,7 +3,6 @@ - Document diff --git a/src/resources/icons/main-icon.png b/src/resources/icons/tray-icon.png similarity index 100% rename from src/resources/icons/main-icon.png rename to src/resources/icons/tray-icon.png diff --git a/src/resources/icons/win-icon.png b/src/resources/icons/win-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..b799da482da45127ead68d5a2f7fb6415538e614 GIT binary patch literal 4940 zcmZ8lc{r49+b5Ep7-ZkZFm@8zBgTxG5i=A;_7H{aku8)h%ozK=3?^Zww?fEn29cez zr)*^jku2Zze9!ZK-~0Y?-{)~3$9bLC`TL#AbzXP8xtR$Yvj8&<4GkL%YJ{T7$UhGw z1NGgZ=h#O>!_5sdGO!G${ocmnKNH~Cy1lu%e|oz4dsb%yISjlvqUIsPHXL0(-dma` zAqA*orMIzY_4Nv9j4wG5C@K2vCNiHtTANw|5RzLl(dLe7;Di4-Bn!=Y18Ih4iUX8-{ zL&E3Ic$rh8r1@T5U&V(!VOmGyc_fkn(WJ#<)%OLqqYp#d)!w<@yq-!bsZd3ptlPO+ z8T%jisC3k0NSI<(w(yyjq7XIQLkU-#d+9g;4tyB!J38cZ+;)J zrDM|7dfcnm6yw4SL05^E$$N^sO2IMZ_KJ6p9op5ri>k|Dq^snL5uNAuhP(c!R#WEfxZPjb?ClG! z0VgQiWu@}9&xODf6kl48h*Zlg@cC$F9J|pki*u6KOZ?{C}ah;iHfcxaX zjUl8&M5n#D#dx|qr|fKzkez_UyDGFYj6_#Da*iPBF$|g5FmpixrbjP!Z@yx4>_Pz6?NAw8c#pr$ne(e%ppH#m}~{q6i-%8F3&5lg8UgigXMn=HhXEl+Mi89*}zmV_cdPGzvbB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