Skip to content

Commit

Permalink
1.3.0 test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheStanish committed Jun 8, 2023
1 parent 0b91c02 commit 5147c3f
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@

<div class="no-drag">
<h1 class="main-msg">Hello Hoseki! Meh</h1>
<p>Welcome to your Electron application v1.2.9</p>
<p>Welcome to your Electron application v1.3.0</p>
<p id="p1">First paragraph</p>
<p id="p2">Second paragraph</p>
<p id="p3">Third paragraph</p>
</div>

<div class="table">
<div class="table jobs">
<div class="heading">
<div class="cell">Name</div>
<div class="cell">Age</div>
<div class="cell">Job</div>
</div>
<div class="row">
<div class="cell">Tyler</div>
<div class="row" name="Tyler" age="31" job="Autism">
<div id="name" class="cell">Tyler</div>
<div class="cell">31</div>
<div class="cell">Autism</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
50 changes: 38 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -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')();

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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/[email protected]');
createWindow();
showNotification();

console.log(appIcon, mainWindow);


});

Expand Down
4 changes: 3 additions & 1 deletion src/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,7 @@ const ctxMenu = Menu.buildFromTemplate(ctxTemplate);

module.exports = {
mainMenu,
ctxMenu
ctxMenu,
ctxTemplate,
template
}
3 changes: 2 additions & 1 deletion src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})


Expand Down
43 changes: 43 additions & 0 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
});


0 comments on commit 5147c3f

Please sign in to comment.