diff --git a/enjoy/package.json b/enjoy/package.json index 73647f55..b8fc060d 100644 --- a/enjoy/package.json +++ b/enjoy/package.json @@ -135,7 +135,6 @@ "sequelize-typescript": "^2.1.6", "sqlite3": "^5.1.7", "tailwind-scrollbar-hide": "^1.1.7", - "ts-key-enum": "^2.0.12", "umzug": "^3.5.0", "wavesurfer.js": "^7.6.3", "zod": "^3.22.4" diff --git a/enjoy/src/i18n/en.json b/enjoy/src/i18n/en.json index 69fccef2..17441c2b 100644 --- a/enjoy/src/i18n/en.json +++ b/enjoy/src/i18n/en.json @@ -201,6 +201,10 @@ "resetAll": "Reset All", "resetAllConfirmation": "It will remove all of your personal data, are you sure?", "logoutAndRemoveAllPersonalData": "Logout and remove all personal data", + "hotkeys": "Hotkeys", + "quitApp": "Quit APP", + "openPreferences": "Open preferences", + "playOrPause": "Play or pause", "about": "About", "currentVersion": "Current version", "checkUpdate": "Check update", diff --git a/enjoy/src/i18n/zh-CN.json b/enjoy/src/i18n/zh-CN.json index 6870f263..ada25107 100644 --- a/enjoy/src/i18n/zh-CN.json +++ b/enjoy/src/i18n/zh-CN.json @@ -201,6 +201,10 @@ "resetAll": "重置所有", "resetAllConfirmation": "这将删除您的所有个人数据, 您确定要重置吗?", "logoutAndRemoveAllPersonalData": "退出登录并删除所有个人数据", + "hotkeys": "快捷键", + "quitApp": "退出应用", + "openPreferences": "打开设置", + "playOrPause": "播放/暂停", "about": "关于", "currentVersion": "当前版本", "checkUpdate": "检查更新", diff --git a/enjoy/src/main.ts b/enjoy/src/main.ts index 5ccdc271..4f51ed9c 100644 --- a/enjoy/src/main.ts +++ b/enjoy/src/main.ts @@ -50,14 +50,6 @@ app.on("ready", async () => { }); mainWindow.init(); - - globalShortcut.register("CommandOrControl+Shift+I", () => { - mainWindow.win.webContents.toggleDevTools(); - }); - - globalShortcut.register("CommandOrControl+Q", () => { - app.quit(); - }); }); // Quit when all windows are closed, except on macOS. There, it's common diff --git a/enjoy/src/main/window.ts b/enjoy/src/main/window.ts index 16ebb4a8..c802f85d 100644 --- a/enjoy/src/main/window.ts +++ b/enjoy/src/main/window.ts @@ -247,6 +247,14 @@ main.init = () => { return process.env.WEB_API_URL || WEB_API_URL; }); + ipcMain.handle("app-quit", () => { + app.quit(); + }); + + ipcMain.handle("app-open-dev-tools", () => { + mainWindow.webContents.openDevTools(); + }); + // Shell ipcMain.handle("shell-open-external", (_event, url) => { shell.openExternal(url); diff --git a/enjoy/src/preload.ts b/enjoy/src/preload.ts index 8d85f91b..fcabd446 100644 --- a/enjoy/src/preload.ts +++ b/enjoy/src/preload.ts @@ -20,6 +20,12 @@ contextBridge.exposeInMainWorld("__ENJOY_APP__", { apiUrl: () => { return ipcRenderer.invoke("app-api-url"); }, + quit: () => { + ipcRenderer.invoke("app-quit"); + }, + openDevTools: () => { + ipcRenderer.invoke("app-open-dev-tools"); + }, version, }, providers: { diff --git a/enjoy/src/renderer/app.tsx b/enjoy/src/renderer/app.tsx index 29e78e36..cc91d41a 100644 --- a/enjoy/src/renderer/app.tsx +++ b/enjoy/src/renderer/app.tsx @@ -9,6 +9,7 @@ import { RouterProvider } from "react-router-dom"; import { Toaster, useToast } from "@renderer/components/ui"; import { t } from "i18next"; import { Tooltip } from "react-tooltip"; +import { useHotkeys } from "react-hotkeys-hook"; function App() { const { toast } = useToast(); @@ -20,6 +21,18 @@ function App() { }); }); + useHotkeys("Control+Comma", () => { + document.getElementById("preferences-button")?.click(); + }); + + useHotkeys("Control+Q", () => { + window.__ENJOY_APP__.app.quit(); + }); + + useHotkeys(["Control+Shift+I", "Command+Shift+I"], () => { + window.__ENJOY_APP__.app.openDevTools(); + }); + return ( diff --git a/enjoy/src/renderer/components/medias/media-player.tsx b/enjoy/src/renderer/components/medias/media-player.tsx index e48fe8ec..f4a20e70 100644 --- a/enjoy/src/renderer/components/medias/media-player.tsx +++ b/enjoy/src/renderer/components/medias/media-player.tsx @@ -27,7 +27,6 @@ import { defaultLayoutIcons, } from "@vidstack/react/player/layouts/default"; import { useHotkeys } from "react-hotkeys-hook"; -import { Key } from "ts-key-enum"; const minPxPerSecBase = 150; diff --git a/enjoy/src/renderer/components/preferences/hotkeys.tsx b/enjoy/src/renderer/components/preferences/hotkeys.tsx new file mode 100644 index 00000000..829de334 --- /dev/null +++ b/enjoy/src/renderer/components/preferences/hotkeys.tsx @@ -0,0 +1,36 @@ +import { t } from "i18next"; +import { Separator } from "@renderer/components/ui"; + +export const Hotkeys = () => { + const commandOrCtrl = navigator.platform.includes("Mac") ? "Cmd" : "Ctrl"; + + return ( + <> +
{t("hotkeys")}
+ +
+
{t("quitApp")}
+ + {commandOrCtrl} + Q + +
+ + +
+
{t("openPreferences")}
+ + {commandOrCtrl} + , + +
+ + +
+
{t("playOrPause")}
+ + Space + +
+ + + ); +}; diff --git a/enjoy/src/renderer/components/preferences/index.ts b/enjoy/src/renderer/components/preferences/index.ts index 29233ea4..5c261484 100644 --- a/enjoy/src/renderer/components/preferences/index.ts +++ b/enjoy/src/renderer/components/preferences/index.ts @@ -2,3 +2,4 @@ export * from './preferences'; export * from './basic-settings'; export * from './advanced-settings'; export * from './about'; +export * from './hotkeys'; diff --git a/enjoy/src/renderer/components/preferences/preferences.tsx b/enjoy/src/renderer/components/preferences/preferences.tsx index 4525968f..17d044bd 100644 --- a/enjoy/src/renderer/components/preferences/preferences.tsx +++ b/enjoy/src/renderer/components/preferences/preferences.tsx @@ -1,6 +1,6 @@ import { t } from "i18next"; import { Button, ScrollArea } from "@renderer/components/ui"; -import { BasicSettings, AdvancedSettings, About } from "@renderer/components"; +import { BasicSettings, AdvancedSettings, About, Hotkeys } from "@renderer/components"; import { useState } from "react"; export const Preferences = () => { @@ -15,6 +15,11 @@ export const Preferences = () => { label: t("advancedSettings"), component: () => , }, + { + value: "hotkeys", + label: t("hotkeys"), + component: () => , + }, { value: "about", label: t("about"), diff --git a/enjoy/src/renderer/components/sidebar.tsx b/enjoy/src/renderer/components/sidebar.tsx index 15de0f69..ed0dd273 100644 --- a/enjoy/src/renderer/components/sidebar.tsx +++ b/enjoy/src/renderer/components/sidebar.tsx @@ -19,17 +19,11 @@ import { useLocation, Link } from "react-router-dom"; import { t } from "i18next"; import { Preferences } from "@renderer/components"; import { Tooltip } from "react-tooltip"; -import { useHotkeys } from "react-hotkeys-hook"; export const Sidebar = () => { const location = useLocation(); const activeTab = location.pathname; - useHotkeys("Control+Comma", () => { - console.log("open preferences"); - document.getElementById("preferences-button")?.click(); - }); - return (
diff --git a/enjoy/src/types/enjoy-app.d.ts b/enjoy/src/types/enjoy-app.d.ts index d0b4bde5..5144b055 100644 --- a/enjoy/src/types/enjoy-app.d.ts +++ b/enjoy/src/types/enjoy-app.d.ts @@ -5,6 +5,8 @@ type EnjoyAppType = { reload: () => Promise; isPackaged: () => Promise; apiUrl: () => Promise; + quit: () => Promise; + openDevTools: () => Promise; version: string; }; providers: { diff --git a/yarn.lock b/yarn.lock index ab80137d..279ab712 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5840,7 +5840,6 @@ __metadata: tailwind-scrollbar-hide: "npm:^1.1.7" tailwindcss: "npm:^3.4.1" tailwindcss-animate: "npm:^1.0.7" - ts-key-enum: "npm:^2.0.12" ts-node: "npm:^10.9.2" tslib: "npm:^2.6.2" typescript: "npm:^5.3.3" @@ -12163,13 +12162,6 @@ __metadata: languageName: node linkType: hard -"ts-key-enum@npm:^2.0.12": - version: 2.0.12 - resolution: "ts-key-enum@npm:2.0.12" - checksum: 1d9cf8085785bdc324827c5c38f6359b09d9438deab81dfab7fa6d8315c618280ba7527e98d06b68c11066a5a81b06ef84eb378a48bf80ca5772ab0e4c6683d5 - languageName: node - linkType: hard - "ts-node@npm:^10.9.2": version: 10.9.2 resolution: "ts-node@npm:10.9.2"