-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/build-with-obfuscated-bundle
- Loading branch information
Showing
42 changed files
with
733 additions
and
812 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
import express from 'express'; | ||
import { app, Menu } from 'electron'; | ||
import { mapMenu } from "./helper"; | ||
import { compileMenu } from './helper'; | ||
import state from '../state'; | ||
const router = express.Router(); | ||
router.post('/', (req, res) => { | ||
const menuEntries = req.body.items.map(mapMenu); | ||
const menuEntries = req.body.items.map(compileMenu); | ||
const menu = Menu.buildFromTemplate(menuEntries); | ||
app.dock.setMenu(menu); | ||
res.sendStatus(200); | ||
}); | ||
router.post('/show', (req, res) => { | ||
app.dock.show(); | ||
res.sendStatus(200); | ||
}); | ||
router.post('/hide', (req, res) => { | ||
app.dock.hide(); | ||
res.sendStatus(200); | ||
}); | ||
router.post('/icon', (req, res) => { | ||
app.dock.setIcon(req.body.path); | ||
res.sendStatus(200); | ||
}); | ||
router.post('/bounce', (req, res) => { | ||
const { type } = req.body; | ||
state.dockBounce = app.dock.bounce(type); | ||
res.sendStatus(200); | ||
}); | ||
router.post('/cancel-bounce', (req, res) => { | ||
app.dock.cancelBounce(state.dockBounce); | ||
res.sendStatus(200); | ||
}); | ||
router.get('/badge', (req, res) => { | ||
res.json({ | ||
label: app.dock.getBadge(), | ||
}); | ||
}); | ||
router.post('/badge', (req, res) => { | ||
app.dock.setBadge(req.body.label); | ||
res.sendStatus(200); | ||
}); | ||
export default router; |
92 changes: 49 additions & 43 deletions
92
resources/js/electron-plugin/dist/server/api/helper/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,66 @@ | ||
import { shell } from "electron"; | ||
import { notifyLaravel } from "../../utils"; | ||
function triggerMenuItemEvent(menuItem) { | ||
import { shell } from 'electron'; | ||
import { notifyLaravel, goToUrl } from '../../utils'; | ||
import state from '../../state'; | ||
function triggerMenuItemEvent(menuItem, combo) { | ||
notifyLaravel('events', { | ||
event: '\\Native\\Laravel\\Events\\Menu\\MenuItemClicked', | ||
payload: [ | ||
{ | ||
event: menuItem.event || '\\Native\\Laravel\\Events\\Menu\\MenuItemClicked', | ||
payload: { | ||
item: { | ||
id: menuItem.id, | ||
label: menuItem.label, | ||
checked: menuItem.checked | ||
} | ||
] | ||
checked: menuItem.checked, | ||
}, | ||
combo, | ||
}, | ||
}); | ||
} | ||
const mapMenu = (menu) => { | ||
if (menu.submenu) { | ||
menu.submenu = menu.submenu.map(mapMenu); | ||
} | ||
if (menu.type === 'link') { | ||
menu.type = 'normal'; | ||
menu.click = () => { | ||
triggerMenuItemEvent(menu); | ||
shell.openExternal(menu.url); | ||
}; | ||
return menu; | ||
export function compileMenu(item) { | ||
var _a, _b; | ||
if (item.submenu) { | ||
if (Array.isArray(item.submenu)) { | ||
item.submenu = (_a = item.submenu) === null || _a === void 0 ? void 0 : _a.map(compileMenu); | ||
} | ||
else { | ||
item.submenu = (_b = item.submenu.submenu) === null || _b === void 0 ? void 0 : _b.map(compileMenu); | ||
} | ||
} | ||
if (menu.type === 'checkbox') { | ||
menu.click = () => { | ||
menu.checked = !menu.checked; | ||
triggerMenuItemEvent(menu); | ||
if (item.type === 'link') { | ||
item.type = 'normal'; | ||
item.click = (menuItem, focusedWindow, combo) => { | ||
triggerMenuItemEvent(item, combo); | ||
if (item.openInBrowser) { | ||
shell.openExternal(item.url); | ||
return; | ||
} | ||
if (!focusedWindow) { | ||
return; | ||
} | ||
const id = Object.keys(state.windows) | ||
.find(key => state.windows[key] === focusedWindow); | ||
goToUrl(item.url, id); | ||
}; | ||
return item; | ||
} | ||
if (menu.type === 'event') { | ||
return { | ||
label: menu.label, | ||
accelerator: menu.accelerator, | ||
click() { | ||
notifyLaravel('events', { | ||
event: menu.event | ||
}); | ||
} | ||
if (item.type === 'checkbox' || item.type === 'radio') { | ||
item.click = (menuItem, focusedWindow, combo) => { | ||
item.checked = !item.checked; | ||
triggerMenuItemEvent(item, combo); | ||
}; | ||
return item; | ||
} | ||
if (menu.type === 'role') { | ||
if (item.type === 'role') { | ||
let menuItem = { | ||
role: menu.role | ||
role: item.role | ||
}; | ||
if (menu.label) { | ||
menuItem['label'] = menu.label; | ||
if (item.label) { | ||
menuItem['label'] = item.label; | ||
} | ||
return menuItem; | ||
} | ||
if (!menu.click) { | ||
menu.click = () => { | ||
triggerMenuItemEvent(menu); | ||
if (!item.click) { | ||
item.click = (menuItem, focusedWindow, combo) => { | ||
triggerMenuItemEvent(item, combo); | ||
}; | ||
} | ||
return menu; | ||
}; | ||
export { mapMenu, }; | ||
return item; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.