angular-electron icon indicating copy to clipboard operation
angular-electron copied to clipboard

menu

Open hitokiri opened this issue 8 years ago • 5 comments

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)

hitokiri avatar Mar 28 '18 16:03 hitokiri

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?

cjackson234 avatar Apr 01 '18 03:04 cjackson234

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);

LaetitiaDall avatar Apr 08 '18 14:04 LaetitiaDall

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;
  }

}

belnadris avatar Apr 15 '18 09:04 belnadris

Thank you, this solution worked perfectly!

LaetitiaDall avatar Apr 15 '18 09:04 LaetitiaDall

You're welcome :)

belnadris avatar Apr 15 '18 10:04 belnadris