feat: add global shortcut setting (#470)

* feat: add global short cut setting

* fix: fix settings not work

* fix: call initIpcMan after createWindow

* fix: fix build error (typo)
This commit is contained in:
wenjie 2021-03-25 21:20:53 +08:00 committed by GitHub
parent b98bf909fb
commit 36447ae5d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 7 deletions

View file

@ -1,5 +1,7 @@
import { app, ipcMain, dialog } from "electron";
import { app, dialog, globalShortcut, ipcMain } from "electron";
import match from "@njzy/unblockneteasemusic";
import { registerGlobalShortcut } from "@/electron/globalShortcut";
const client = require("discord-rich-presence")("818936529484906596");
export function initIpcMain(win, store) {
@ -61,6 +63,14 @@ export function initIpcMain(win, store) {
ipcMain.on("settings", (event, options) => {
store.set("settings", options);
const isRegisterShortcut = globalShortcut.isRegistered(
"Alt+CommandOrControl+P"
);
if (options.enableGlobalShortcut) {
!isRegisterShortcut && registerGlobalShortcut(win);
} else {
isRegisterShortcut && globalShortcut.unregisterAll();
}
});
ipcMain.on("playDiscordPresence", (event, track) => {