Call AngularJS function from main electron menu


#1

Hey Guys, I would need some help:

I would like to call a defined function like “removeSelected()” using the “edit > delete” menu item in the main electron menu. Ist there a simple way for doing such things? From inside my main.html I am using simply “ng-click=“removeSelected()””…

Thanks!


#2

Hey,

have a look at the WebContent Module, esp. contents.executeJavaScript

Greets


#3

@sukapx Thanks for taking the time. I was trying this two ways but apparently I am doing something wrong:

      {
    role: 'delete',
	label: 'Delete',
	click (item, focusedWindow) {
      if (focusedWindow) focusedWindow.webContents.executeJavaScript('removeSelected()')
    }
  },	
	
      {
    role: 'delete',
	label: 'Delete',
	click (item, focusedWindow) {
      if (focusedWindow) contents.executeJavaScript('removeSelected()')
    }
  },

Sorry for the ingnorance but I am really a newbie…

Oh, yes this is from my mainmenu.js…


#4

Hm, I’m a bit confused now.

Could you please specify a bit more from where to where you’re calling what code exactly?


#5

I am defining this function im my controller.js file like this:

	$scope.removeSelected = function () {
	var activeObject = canvas.getActiveObject(),
		activeGroup = canvas.getActiveGroup();

	if (activeGroup) {
		var objectsInGroup = activeGroup.getObjects();
		canvas.discardActiveGroup();
		objectsInGroup.forEach(function (object) {
			canvas.remove(object);
		});
	} else if (activeObject) {
		canvas.remove(activeObject);
	}
};

I am calling this function from inside my index.html file if I click a button like this:

ng-click=“removeSelected()"