menu
hello, when I make the call
const {remote, ipcRenderer} = require('electron'); let {dialog} = remote;
Uncaught TypeError: fs.existsSync is not a function
at Object.eval (index.js:6)
at eval (index.js:10)
at Object../node_modules/electron/index.js (vendor.bundle.js:687)
at __webpack_require__ (inline.bundle.js:55)
at eval (app.component.ts:7)
at Object../src/app/app.component.ts (main.bundle.js:43)
at __webpack_require__ (inline.bundle.js:55)
at eval (app.module.ts:20)
at Object../src/app/app.module.ts (main.bundle.js:59)
at __webpack_require__ (inline.bundle.js:55)
Your issue is called "menu" what does this have to do with a menu?
Where is this call being made?
What are you trying to do here?
I have the same issue, and it happens with those three lines
import {Menu, MenuItemConstructorOptions, dialog} from 'electron';
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
You have to use window.require('electron').remote.Menu
Please try this . It does work on Windows.
electron.service.ts:
import { Injectable } from '@angular/core';
// If you import a module but never use any of the imported values other than as TypeScript types,
// the resulting javascript file will look as if you never imported the module at all.
import { ipcRenderer, Menu } from 'electron';
import * as childProcess from 'child_process';
@Injectable()
export class ElectronService {
ipcRenderer: typeof ipcRenderer;
childProcess: typeof childProcess;
menu: typeof Menu;
template = [
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
{role: 'pasteandmatchstyle'},
{role: 'delete'},
{role: 'selectall'}
]
},
{
label: 'View',
submenu: [
{role: 'reload'},
{role: 'forcereload'},
{role: 'toggledevtools'},
{role: 'resetzoom'},
{role: 'zoomin'},
{role: 'zoomout'},
{role: 'togglefullscreen'}
]
},
{
role: 'window',
submenu: [
{role: 'minimize'},
{role: 'close'}
]
}
];
constructor() {
// Conditional imports
if (this.isElectron()) {
this.ipcRenderer = window.require('electron').ipcRenderer;
this.childProcess = window.require('child_process');
this.menu = window.require('electron').remote.Menu;
const menu = this.menu.buildFromTemplate(this.template);
this.menu.setApplicationMenu(menu);
}
}
isElectron = () => {
return window && window.process && window.process.type;
}
}
Thank you, this solution worked perfectly!
You're welcome :)