Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable or customize Context menu #682

Closed
jdounivers opened this issue May 7, 2020 · 10 comments
Closed

Disable or customize Context menu #682

jdounivers opened this issue May 7, 2020 · 10 comments
Labels
question Further information is requested

Comments

@jdounivers
Copy link

Hello,

I'm trying to disable or change the context menu but everything i saw on tutoriel doesn't seems to work.
Is there a specific way to change it with this template ?

@mubaidr
Copy link
Owner

mubaidr commented May 7, 2020

You mean context menu or application menu? Also which tutorial please?

@mubaidr mubaidr added the question Further information is requested label May 7, 2020
@jdounivers
Copy link
Author

jdounivers commented May 7, 2020

I mean the context menu, this :
image
And i tried differents tutorials.
Doing this (as i saw in off doc) :

window.addEventListener('contextmenu', (e) => {
  e.preventDefault()
  menu.popup({ window: remote.getCurrentWindow() })
}, false)

or using electron-context-menu dependency

@mubaidr
Copy link
Owner

mubaidr commented May 7, 2020

This should work as expected. Can you share your complete code, please?

@jdounivers
Copy link
Author

I didn't change a lot of things.
Here is my src/renderer/main.js :

import Vue from 'vue'
import App from './App.vue'
import './assets/style/main.scss'
import router from './router/index'
import store from './store/index'

const { remote } = require('electron')
const { Menu, MenuItem } = remote

const isDev = process.env.NODE_ENV === 'development'

Vue.config.devtools = isDev
Vue.config.performance = isDev
Vue.config.productionTip = isDev

// tslint:disable-next-line: no-unused-expression
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App),
})

const menu = new Menu()
menu.append(new MenuItem({ type: 'separator' }))

window.addEventListener('contextmenu', (e) => {
  e.preventDefault()
  menu.popup({ window: remote.getCurrentWindow() })
}, false)

// to avoild accesing electorn api from web app build
if (window && window.process && window.process.type === 'renderer') {
  const { ipcRenderer } = require('electron')

  // handle menu event updates from main script
  ipcRenderer.on('change-view', (event, data) => {
    if (data.route) {
      router.push(data.route)
    }
  })
}

@mubaidr
Copy link
Owner

mubaidr commented May 7, 2020

Looks good to me, I will check and update you.

@jdounivers
Copy link
Author

jdounivers commented May 7, 2020

Thanks
and thanks for your quick answers

@mubaidr
Copy link
Owner

mubaidr commented May 7, 2020

It works as expected for me.

Untitled

Code sample used:

const { remote } = require('electron')
const { Menu, MenuItem } = remote
const menu = new Menu()
menu.append(new MenuItem({ label: 'Home' }))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: 'Other' }))

window.addEventListener(
  'contextmenu',
  (e) => {
    e.preventDefault()
    menu.popup({ window: remote.getCurrentWindow() })
  },
  false
)

@jdounivers
Copy link
Author

jdounivers commented May 7, 2020

I saw where is the difference :

  mainWindow = new BrowserWindow({
    backgroundColor: '#fff',
    width: 960,
    height: 540,
    minWidth: 960,
    minHeight: 540,
    // useContentSize: true,
    webPreferences: {
      nodeIntegration: true,
      nodeIntegrationInWorker: false,
      webSecurity: false,
    },
    frame: false,
    show: false,
    resizable: false
  })

@jdounivers
Copy link
Author

With frame : false the contextmenu doesn't work anymore

@mubaidr
Copy link
Owner

mubaidr commented May 7, 2020

Then it must be electronjs implementation,nothing to do with this template.

@mubaidr mubaidr closed this as completed May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants