mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-16 13:17:46 +00:00
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:
parent
b98bf909fb
commit
36447ae5d8
7 changed files with 50 additions and 7 deletions
|
|
@ -50,9 +50,6 @@ class Background {
|
||||||
// create Express app
|
// create Express app
|
||||||
this.createExpressApp();
|
this.createExpressApp();
|
||||||
|
|
||||||
// init ipcMain
|
|
||||||
initIpcMain(this.window, this.store);
|
|
||||||
|
|
||||||
// Scheme must be registered before the app is ready
|
// Scheme must be registered before the app is ready
|
||||||
protocol.registerSchemesAsPrivileged([
|
protocol.registerSchemesAsPrivileged([
|
||||||
{ scheme: "app", privileges: { secure: true, standard: true } },
|
{ scheme: "app", privileges: { secure: true, standard: true } },
|
||||||
|
|
@ -226,6 +223,9 @@ class Background {
|
||||||
this.createWindow();
|
this.createWindow();
|
||||||
this.handleWindowEvents();
|
this.handleWindowEvents();
|
||||||
|
|
||||||
|
// init ipcMain
|
||||||
|
initIpcMain(this.window, this.store);
|
||||||
|
|
||||||
// check for updates
|
// check for updates
|
||||||
this.checkForUpdates();
|
this.checkForUpdates();
|
||||||
|
|
||||||
|
|
@ -244,7 +244,9 @@ class Background {
|
||||||
this.window.setTouchBar(createTouchBar(this.window));
|
this.window.setTouchBar(createTouchBar(this.window));
|
||||||
|
|
||||||
// register global shortcuts
|
// register global shortcuts
|
||||||
registerGlobalShortcut(this.window);
|
if (this.store.get("settings.enableGlobalShortcut")) {
|
||||||
|
registerGlobalShortcut(this.window);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { app, ipcMain, dialog } from "electron";
|
import { app, dialog, globalShortcut, ipcMain } from "electron";
|
||||||
import match from "@njzy/unblockneteasemusic";
|
import match from "@njzy/unblockneteasemusic";
|
||||||
|
import { registerGlobalShortcut } from "@/electron/globalShortcut";
|
||||||
|
|
||||||
const client = require("discord-rich-presence")("818936529484906596");
|
const client = require("discord-rich-presence")("818936529484906596");
|
||||||
|
|
||||||
export function initIpcMain(win, store) {
|
export function initIpcMain(win, store) {
|
||||||
|
|
@ -61,6 +63,14 @@ export function initIpcMain(win, store) {
|
||||||
|
|
||||||
ipcMain.on("settings", (event, options) => {
|
ipcMain.on("settings", (event, options) => {
|
||||||
store.set("settings", 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) => {
|
ipcMain.on("playDiscordPresence", (event, track) => {
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ export default {
|
||||||
showUnavailableSongInGreyStyle: "Show unavailable song in grey style",
|
showUnavailableSongInGreyStyle: "Show unavailable song in grey style",
|
||||||
showPlaylistsByAppleMusic: "Show playlists by Apple Music",
|
showPlaylistsByAppleMusic: "Show playlists by Apple Music",
|
||||||
enableDiscordRichPresence: "Enable Discord Rich Presence",
|
enableDiscordRichPresence: "Enable Discord Rich Presence",
|
||||||
|
enableGlobalShortcut: "Enable Global Shortcut",
|
||||||
},
|
},
|
||||||
contextMenu: {
|
contextMenu: {
|
||||||
play: "Play",
|
play: "Play",
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ export default {
|
||||||
showUnavailableSongInGreyStyle: "显示不可播放的歌曲为灰色",
|
showUnavailableSongInGreyStyle: "显示不可播放的歌曲为灰色",
|
||||||
showPlaylistsByAppleMusic: "首页显示来自 Apple Music 的歌单",
|
showPlaylistsByAppleMusic: "首页显示来自 Apple Music 的歌单",
|
||||||
enableDiscordRichPresence: "启用 Discord Rich Presence",
|
enableDiscordRichPresence: "启用 Discord Rich Presence",
|
||||||
|
enableGlobalShortcut: "启用全局快捷键",
|
||||||
},
|
},
|
||||||
contextMenu: {
|
contextMenu: {
|
||||||
play: "播放",
|
play: "播放",
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ let localStorage = {
|
||||||
showLyricsDynamicBackground: false,
|
showLyricsDynamicBackground: false,
|
||||||
minimizeToTray: false,
|
minimizeToTray: false,
|
||||||
enableDiscordRichPresence: false,
|
enableDiscordRichPresence: false,
|
||||||
|
enableGlobalShortcut: true,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
user: {},
|
user: {},
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export function getSendSettingsPlugin() {
|
||||||
if (mutation.type !== "updateSettings") return;
|
if (mutation.type !== "updateSettings") return;
|
||||||
ipcRenderer.send("settings", {
|
ipcRenderer.send("settings", {
|
||||||
minimizeToTray: state.settings.minimizeToTray,
|
minimizeToTray: state.settings.minimizeToTray,
|
||||||
|
enableGlobalShortcut: state.settings.enableGlobalShortcut,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="item" v-if="isElectron">
|
||||||
|
<div class="left">
|
||||||
|
<div class="title"> {{ $t("settings.enableGlobalShortcut") }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="right">
|
||||||
|
<div class="toggle">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="enable-enable-global-shortcut"
|
||||||
|
id="enable-enable-global-shortcut"
|
||||||
|
v-model="enableGlobalShortcut"
|
||||||
|
/>
|
||||||
|
<label for="enable-enable-global-shortcut"></label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<div class="title" style="transform: scaleX(-1)">🐈️ 🏳️🌈</div>
|
<div class="title" style="transform: scaleX(-1)">🐈️ 🏳️🌈</div>
|
||||||
|
|
@ -491,8 +507,19 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isLastfmConnected() {
|
enableGlobalShortcut: {
|
||||||
return this.lastfm.key !== undefined;
|
get() {
|
||||||
|
return this.settings.enableGlobalShortcut;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
this.$store.commit("updateSettings", {
|
||||||
|
key: "enableGlobalShortcut",
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
isLastfmConnected() {
|
||||||
|
return this.lastfm.key !== undefined;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue