From c43fd787a0973c160516d30c09c04722b5bc7c22 Mon Sep 17 00:00:00 2001 From: Sylvie Crowe <107814465+oneirocosm@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:12:20 -0700 Subject: [PATCH] Simple Quicklook (#998) This adds some ability to use quicklook from the directory view with the spacebar on mac. --- emain/emain.ts | 11 +++++++++++ emain/preload.ts | 1 + frontend/app/view/preview/directorypreview.tsx | 9 +++++++-- frontend/types/custom.d.ts | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/emain/emain.ts b/emain/emain.ts index 5dec24e1a..34f37fb0e 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -787,6 +787,17 @@ if (unamePlatform !== "darwin") { }); } +electron.ipcMain.on("quicklook", (event, filePath: string) => { + if (unamePlatform == "darwin") { + child_process.execFile("/usr/bin/qlmanage", ["-p", filePath], (error, stdout, stderr) => { + if (error) { + console.error(`Error opening Quick Look: ${error}`); + return; + } + }); + } +}); + async function createNewWaveWindow(): Promise { const clientData = await services.ClientService.GetClientData(); const fullConfig = await services.FileService.GetFullConfig(); diff --git a/emain/preload.ts b/emain/preload.ts index 6368812f3..6fbec0d59 100644 --- a/emain/preload.ts +++ b/emain/preload.ts @@ -38,6 +38,7 @@ contextBridge.exposeInMainWorld("api", { registerGlobalWebviewKeys: (keys) => ipcRenderer.send("register-global-webview-keys", keys), onControlShiftStateUpdate: (callback) => ipcRenderer.on("control-shift-state-update", (_event, state) => callback(state)), + onQuicklook: (filePath: string) => ipcRenderer.send("quicklook", filePath), }); // Custom event for "new-window" diff --git a/frontend/app/view/preview/directorypreview.tsx b/frontend/app/view/preview/directorypreview.tsx index d8afe804d..0d667934e 100644 --- a/frontend/app/view/preview/directorypreview.tsx +++ b/frontend/app/view/preview/directorypreview.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { ContextMenuModel } from "@/app/store/contextmenu"; -import { atoms, createBlock, getApi } from "@/app/store/global"; +import { PLATFORM, atoms, createBlock, getApi } from "@/app/store/global"; import { FileService } from "@/app/store/services"; import type { PreviewModel } from "@/app/view/preview/preview"; import { checkKeyPressed, isCharacterKeyEvent } from "@/util/keyutil"; @@ -594,6 +594,11 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { setSearchText((current) => current.slice(0, -1)); return true; } + if (checkKeyPressed(waveEvent, "Space") && searchText == "" && PLATFORM == "darwin") { + getApi().onQuicklook(selectedPath); + console.log(selectedPath); + return true; + } if (isCharacterKeyEvent(waveEvent)) { setSearchText((current) => current + waveEvent.key); return true; @@ -603,7 +608,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) { return () => { model.directoryKeyDownHandler = null; }; - }, [filteredData, selectedPath]); + }, [filteredData, selectedPath, searchText]); useEffect(() => { if (filteredData.length != 0 && focusIndex > filteredData.length - 1) { diff --git a/frontend/types/custom.d.ts b/frontend/types/custom.d.ts index 7736335b0..a032d1bf3 100644 --- a/frontend/types/custom.d.ts +++ b/frontend/types/custom.d.ts @@ -77,6 +77,7 @@ declare global { setWebviewFocus: (focusedId: number) => void; // focusedId si the getWebContentsId of the webview registerGlobalWebviewKeys: (keys: string[]) => void; onControlShiftStateUpdate: (callback: (state: boolean) => void) => void; + onQuicklook: (filePath: string) => void; }; type ElectronContextMenuItem = {