Simple Quicklook (#998)

This adds some ability to use quicklook from the directory view with the
spacebar on mac.
This commit is contained in:
Sylvie Crowe 2024-10-09 15:12:20 -07:00 committed by GitHub
parent 9dd4188810
commit c43fd787a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 2 deletions

View File

@ -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<void> {
const clientData = await services.ClientService.GetClientData();
const fullConfig = await services.FileService.GetFullConfig();

View File

@ -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"

View File

@ -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) {

View File

@ -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 = {