Skip to content

Build your personal knowledge base with Trilium Notes

feat(desktop): reveal exported files in the OS file manager

Elian Dorande422f03a558
diff --git a/apps/desktop/src/services/export.ts b/apps/desktop/src/services/export.ts
index 80ac927848..ea69e9d48a 100644
--- a/apps/desktop/src/services/export.ts
+++ b/apps/desktop/src/services/export.ts
@@ -37,6 +37,9 @@ export function setupExportHandlers() {
try {
await zipExportService.exportBranchToZipFile(branchId, format as ExportFormat, filePath, taskId);
+ // Reveal the saved archive in the OS file manager, selecting it — more useful than opening the
+ // zip itself (cf. PDF export, which opens the document).
+ electron.shell.showItemInFolder(filePath);
return { status: "saved", filePath };
} catch (e) {
// Remove the partial/incomplete archive left at the destination.
diff --git a/apps/desktop/src/services/window.ts b/apps/desktop/src/services/window.ts
index b78c72ba31..a779481f9d 100644
--- a/apps/desktop/src/services/window.ts
+++ b/apps/desktop/src/services/window.ts
@@ -35,6 +35,7 @@ let mainWindow: BrowserWindow | null;
let setupWindow: BrowserWindow | null;
let allWindows: BrowserWindow[] = []; // Used to store all windows, sorted by the order of focus.
const loadedSpellcheckSessions = new WeakSet<Session>();
+const exportRevealSessions = new WeakSet<Session>();
// Set to `true` once the app is genuinely quitting (via `before-quit`, which fires
// for every real quit path: Cmd+Q, the tray "Quit" item, the app menu, OS shutdown).
@@ -206,6 +207,7 @@ async function configureWebContents(webContents: WebContents, spellcheckEnabled:
// which never pass through this function) by web_contents_security.ts.
setupSpellcheckForSession(webContents.session, spellcheckEnabled);
+ setupExportRevealForSession(webContents.session);
// Forward full-screen events to the renderer via IPC.
const win = electron.BrowserWindow.fromWebContents(webContents);
@@ -262,6 +264,30 @@ function isDevToolsDocked(webContents: WebContents) {
return devToolsWindow !== null && devToolsWindow === electron.BrowserWindow.fromWebContents(webContents);
}
+/**
+ * Reveals note exports in the OS file manager once their download finishes, matching the native subtree
+ * export (which reveals via shell.showItemInFolder). Single-note and OPML exports go through Electron's
+ * download manager rather than the native handler, so they're caught here. Scoped to `/export/` URLs so
+ * attachment/revision/file downloads are left alone, and registered once per session.
+ */
+function setupExportRevealForSession(session: Session) {
+ if (exportRevealSessions.has(session)) {
+ return;
+ }
+ exportRevealSessions.add(session);
+
+ session.on("will-download", (_event, item) => {
+ if (!/\/export\//.test(item.getURL())) {
+ return;
+ }
+ item.once("done", (_e, state) => {
+ if (state === "completed") {
+ electron.shell.showItemInFolder(item.getSavePath());
+ }
+ });
+ });
+}
+
function setupSpellcheckForSession(session: Session, enabled: boolean) {
session.setSpellCheckerEnabled(enabled);
// Preload the configured languages once per session (idempotent thereafter via the