#### i. Electron menu shortcut key

accelerator:"Custom shortcut key combination"If you want to customize method eventsCopy the code

To register a global shortcut key, uppercase —- Ctrl+X

const { app, globalShortcut } = require("electron");
app.on("ready", () = > {// Register a global shortcut for 'CommandOrControl+X'
	const ret = globalShortcut.register("Ctrl+X", () = > {console.log("Ctrl+X is pressed");
});
	if(! ret) {console.log("registration failed");
	}
// Check whether the shortcut keys are registered successfully
	console.log(globalShortcut.isRegistered("Ctrl+X"));
});
app.on("will-quit", () = > {// Logout shortcut key
	globalShortcut.unregister("Ctrl+X");
	// Unlog all shortcut keys
	globalShortcut.unregisterAll();
});
Copy the code
Copy and paste
const { remote, clipboard } = require("electron"); Clipboard.writetext (dP.innerhtml) ---- Copy the content clipboard.readtext () -- Paste the contentCopy the code

Two, printing function

BrowserWindow.getFocusedWindow().webContents.print();
Copy the code

Three, monitor network changes

window.addEventListener('online'.function(){}); - have a networkwindow.addEventListener('offline'.function(){}); -- Disconnect the networkCopy the code

Realization of message notification

const option = {
title: 'title'.body: 'body'.icon: path.join('main-process/favicon2.ico')}const myNotification = new window.Notification(option.title,option);
myNotification.onclick = (a)= >{
console.log('clicked');
}
Copy the code

Hide the menu at the top

Add mainwindow.setmenu (null) to main process
2. Hide the close, close, maximize and minimize button in electron-vue
mainWindow = new BrowserWindow({
	height: 620.useContentSize: true.width: 1280
	frame: false /* Remove top navigation remove close button maximize minimize button */
})

var { ipcMain, BrowserWindow } = require("electron");

/ / get the current window object BrowserWindow. The keyboardfocusmanager.getfocusedwindow ();
varmainWindow = BrowserWindow.getFocusedWindow(); Electronic-vue custom close Close Maximize minimize button IPc.on ('window-min'.function(){
		mainWindow.minimize();
	})
// Maximize the login window
	ipc.on('window-max'.function(){
		if(mainWindow.isMaximized()){ mainWindow.restore(); - reduction}else{
			mainWindow.maximize();
		}
	})
	ipc.on('window-close'.function(){
		mainWindow.close();
	})
Copy the code

Six, the electron-vue custom navigation can be dragged

Draggable CSS: -webkit-app-region: drag; Undraggable CSS: -webkit-app-region: no-drag;

Note that when a drag is added to the outer layer and a click event is added to the inner layer, the click event element must add this style to add the click event