mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-11-22 14:20:50 +08:00
feat: support global shortcuts
This commit is contained in:
parent
2a9a53a940
commit
7efe109c83
|
@ -1,5 +1,12 @@
|
|||
"use strict";
|
||||
import { app, protocol, BrowserWindow, shell, dialog } from "electron";
|
||||
import {
|
||||
app,
|
||||
protocol,
|
||||
BrowserWindow,
|
||||
shell,
|
||||
dialog,
|
||||
globalShortcut,
|
||||
} from "electron";
|
||||
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
|
||||
import { startNeteaseMusicApi } from "./electron/services";
|
||||
import { initIpcMain } from "./electron/ipcMain.js";
|
||||
|
@ -7,6 +14,7 @@ import { createMenu } from "./electron/menu";
|
|||
import { createTray } from "@/electron/tray";
|
||||
import { createTouchBar } from "./electron/touchBar";
|
||||
import { createDockMenu } from "./electron/dockMenu";
|
||||
import { registerGlobalShortcut } from "./electron/globalShortcut";
|
||||
import { autoUpdater } from "electron-updater";
|
||||
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer";
|
||||
import express from "express";
|
||||
|
@ -214,6 +222,9 @@ class Background {
|
|||
|
||||
// create touch bar
|
||||
this.window.setTouchBar(createTouchBar(this.window));
|
||||
|
||||
// register global shortcuts
|
||||
registerGlobalShortcut(this.window);
|
||||
});
|
||||
|
||||
app.on("activate", () => {
|
||||
|
@ -240,6 +251,11 @@ class Background {
|
|||
app.on("quit", () => {
|
||||
this.expressApp.close();
|
||||
});
|
||||
|
||||
app.on("will-quit", () => {
|
||||
// unregister all global shortcuts
|
||||
globalShortcut.unregisterAll();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
src/electron/globalShortcut.js
Normal file
22
src/electron/globalShortcut.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const { globalShortcut } = require("electron");
|
||||
|
||||
export function registerGlobalShortcut(win) {
|
||||
globalShortcut.register("Alt+CommandOrControl+P", () => {
|
||||
win.webContents.send("play");
|
||||
});
|
||||
globalShortcut.register("Alt+CommandOrControl+Right", () => {
|
||||
win.webContents.send("next");
|
||||
});
|
||||
globalShortcut.register("Alt+CommandOrControl+Left", () => {
|
||||
win.webContents.send("previous");
|
||||
});
|
||||
globalShortcut.register("Alt+CommandOrControl+Up", () => {
|
||||
win.webContents.send("increaseVolume");
|
||||
});
|
||||
globalShortcut.register("Alt+CommandOrControl+Down", () => {
|
||||
win.webContents.send("decreaseVolume");
|
||||
});
|
||||
globalShortcut.register("Alt+CommandOrControl+L", () => {
|
||||
win.webContents.send("like");
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user