-
Tyler
+
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
+ });
+ }
+});