From 5147c3f8e5c8da154058e098e5dbcba68f1b8f17 Mon Sep 17 00:00:00 2001 From: TheStanish Date: Thu, 8 Jun 2023 10:32:13 -0400 Subject: [PATCH] 1.3.0 test --- .github/workflows/build.yaml | 2 +- index.html | 8 +++--- package.json | 2 +- src/main.js | 50 +++++++++++++++++++++++++++--------- src/menus.js | 4 ++- src/preload.js | 3 ++- src/renderer.js | 43 +++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 83835ec..5686205 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,7 @@ jobs: - name: Find latest asset id: find_latest_asset run: | - asset_path=$(pwd)/out/make + asset_path=$(pwd)/out/make/*.zip echo "::set-output name=asset_path::$asset_path" - name: Create Release diff --git a/index.html b/index.html index 3ee82a7..1c9d5c8 100644 --- a/index.html +++ b/index.html @@ -24,20 +24,20 @@

Hello Hoseki! Meh

-

Welcome to your Electron application v1.2.9

+

Welcome to your Electron application v1.3.0

First paragraph

Second paragraph

Third paragraph

-
+
Name
Age
Job
-
-
Tyler
+
+
Tyler
31
Autism
diff --git a/package.json b/package.json index f5d1760..8b01456 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hoseki-admin", "productName": "hoseki-admin", - "version": "1.2.9", + "version": "1.3.0", "description": "Hoseki admin app test", "main": ".vite/build/main.js", "scripts": { diff --git a/src/main.js b/src/main.js index f317697..4018eeb 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ const electron = require('electron'); const { app, BrowserWindow, ipcMain, dialog, Notification, Menu, Tray } = electron; -const { mainMenu, ctxMenu } = require('/Users/bear/projects/electron-test/hoseki-admin/src/menus'); +const { mainMenu, ctxMenu, template, ctxTemplate } = require('/Users/bear/projects/electron-test/hoseki-admin/src/menus'); const path = require('path'); require('update-electron-app')(); @@ -27,8 +27,34 @@ const customNotification = () => { notification.show(); } -const context = () => { - ctxMenu.popup(); +const handleHeadingMenu = ({pinga}) => { + + if(pinga) { + const menu = Menu.buildFromTemplate([ + ...ctxTemplate, + { + label: 'Heading', + } + ]); + + menu.popup(); + } + +} + +const handleNameMenu = ({name}) => { + if(name) { + + const menu = Menu.buildFromTemplate([ + ...ctxTemplate, + { + label: 'Name', + } + ]); + + menu.popup(); + } + } // App hot reload @@ -96,13 +122,6 @@ const createWindow = () => { Menu.setApplicationMenu(mainMenu); - mainWindow.webContents.on('context-menu', (e) => { - e.preventDefault(); - context(); - } - ); - - // and load the index.html of the app. if (MAIN_WINDOW_VITE_DEV_SERVER_URL) { @@ -127,13 +146,20 @@ app.on('ready', () => { ipcMain.on('set-title', handleSetTitle); ipcMain.handle('dialog:openFile', handleFileOpen); ipcMain.handle('custom-notification', customNotification); - ipcMain.handle('ctx-alert', context); + ipcMain.handle('heading-menu', (event, ...args) => { + event.preventDefault(); + handleHeadingMenu(...args); + }); + ipcMain.handle('name-menu', (event, ...args) => { + event.preventDefault(); + handleNameMenu(...args); + }); // ipcMain.handle('show-notification', showNotification); const appIcon = new Tray('/Users/bear/projects/electron-test/hoseki-admin/src/images/logo@3x.png'); createWindow(); showNotification(); - console.log(appIcon, mainWindow); + }); diff --git a/src/menus.js b/src/menus.js index 01df9fd..01ecd26 100644 --- a/src/menus.js +++ b/src/menus.js @@ -95,5 +95,7 @@ const ctxMenu = Menu.buildFromTemplate(ctxTemplate); module.exports = { mainMenu, - ctxMenu + ctxMenu, + ctxTemplate, + template } diff --git a/src/preload.js b/src/preload.js index ef23a61..ed66f5a 100644 --- a/src/preload.js +++ b/src/preload.js @@ -4,7 +4,8 @@ contextBridge.exposeInMainWorld('electronAPI', { setTitle: (title) => ipcRenderer.send('set-title', title), openFile: () => ipcRenderer.invoke('dialog:openFile'), customNotification: () => ipcRenderer.invoke('custom-notification'), - ctxAlert: () => ipcRenderer.invoke('ctx-alert'), + headingMenu: (data) => ipcRenderer.invoke('heading-menu', data), + nameMenu: (data) => ipcRenderer.invoke('name-menu', data), }) diff --git a/src/renderer.js b/src/renderer.js index c365deb..4cf0b42 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -72,6 +72,49 @@ btn.addEventListener('click', function(e) { window.electronAPI.customNotification(); }); +window.addEventListener('contextmenu', (e) => { + e.preventDefault(); + /** @type {HTMLElement} */ + const el = e.target; + + const table = el?.closest('.table'); + + console.log({table}); + + if(table) { + + /** + * @type {HTMLElement} + */ + const row = el?.closest('.row'); + + if (row) { + + console.log({ + + name: row.getAttribute('name'), + age: row.getAttribute('age'), + job: row.getAttribute('job'), + }); + + window.electronAPI.headingMenu({ + name: row.getAttribute('name'), + age: row.getAttribute('age'), + job: row.getAttribute('job'), + }); + } + } +}); + +window.addEventListener('contextmenu', (e) => { + e.preventDefault(); + + if(e.target.id === 'name') { + window.electronAPI.nameMenu({ + name : true + }); + } +});