mac电脑,按command + r 会刷新项目。这个功能能关闭吗。

cqr 4月前 257

command + r 快捷键在mac电脑会刷新,影响不大。但是想咨询一下是否有关闭的方法。 (试过设置 command + r快捷键。但会影响浏览器刷新)

最新回复 (1)
  • x86 4月前
    引用 2

    请参考这儿:https://stackoverflow.com/questions/39190476/disable-reload-via-keyboard-shortcut-electron-app

    Prevent BrowserWindow refreshes A user can press Cmd+R (on macOS) or Ctrl+R/Ctrl+Shift+R/F5 (on Windows) to refresh the webpage shown by the BrowserWindow. True native applications don’t exhibit this behaviour.

    The recommended solution is to replace the default menu to disable this behaviour. On Windows, you can call win.removeMenu(). On macOS, you can call Menu.setApplicationMenu(Menu.buildFromTemplate([])). You should only do it for production since you will lose access to DevTools.

    For Kiosk Mode, another solution is to Disable the keyboard shortcuts when the BrowserWindow takes focus and then unregister the shortcuts when the BrowserWindow loses focus or is closed/hidden.

    const electronLocalshortcut = require('electron-localshortcut')
    
    win.on('focus', (event) => {
        electronLocalshortcut.register(win, ['CommandOrControl+R','CommandOrControl+Shift+R', 'F5'], () => {})
    })
    
    win.on('blur', (event) => {
        electronLocalshortcut.unregisterAll(win)
    })
返回