Skip to content

Commit

Permalink
[tree-view] Fix issue with revealing in finder on macOS…
Browse files Browse the repository at this point in the history
…by implementing `atom.showItemInFolder` to trigger `shell.showItemInFolder` from the main process.
  • Loading branch information
savetheclocktower committed Jan 14, 2025
1 parent 56f0fa5 commit f71cb57
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
3 changes: 0 additions & 3 deletions packages/tree-view/lib/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ class Directory {
this.watchSubscription?.dispose()
this.watchSubscription = null

this.parentWatchSubscription?.dispose()
this.parentWatchSubscription = null

for (let [key, entry] of this.entries) {
entry.destroy()
this.entries.delete(key)
Expand Down
4 changes: 2 additions & 2 deletions packages/tree-view/lib/tree-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ class TreeView {
`Unable to show ${filePath} in ${this.getFileManagerName()}`
);
}
return shell.showItemInFolder(filePath);
return atom.showItemInFolder(filePath);
}

showCurrentFileInFileManager() {
Expand All @@ -834,7 +834,7 @@ class TreeView {
`Unable to show ${filePath} in ${this.getFileManagerName()}`
);
}
return shell.showItemInFolder(filePath);
return atom.showItemInFolder(filePath);
}

getFileManagerName() {
Expand Down
12 changes: 12 additions & 0 deletions src/application-delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ module.exports = class ApplicationDelegate {
});
}

showItemInFolder(filePath) {
// A simple wrapper around `shell.trashItem`, which currently can only be
// called from the main process.
return ipcRenderer.invoke('showItemInFolder', filePath).then(({ outcome, error, result }) => {
if (outcome === 'success') {
return result;
} else if (outcome === 'failure') {
return Promise.reject(error);
}
});
}

async openWindowDevTools() {
// Defer DevTools interaction to the next tick, because using them during
// event handling causes some wrong input events to be triggered on
Expand Down
10 changes: 10 additions & 0 deletions src/atom-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,16 @@ class AtomEnvironment {
return this.applicationDelegate.trashItem(filePath);
}

// A proxy to `shell.showItemInFolder` — which ought to work in the renderer,
// but seems to suffer from a bug on macOS. We work around it by delegating
// to the main process.
//
// Undocumented for now, but may eventually be an official part of the API
// for when community packages need to perform this function.
showItemInFolder(filePath) {
return this.applicationDelegate.showItemInFolder(filePath);
}

// Restore the window to its previous dimensions and show it.
//
// Restores the full screen and maximized state after the window has resized to
Expand Down
14 changes: 13 additions & 1 deletion src/main-process/atom-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,22 @@ ipcMain.handle('trashItem', async (_, filePath) => {
return { outcome: 'success', result };
} catch (error) {
// …and rejects on failure.
return { outcome: 'failure', error }
return { outcome: 'failure', error };
}
});

ipcMain.handle('showItemInFolder', async (_, filePath) => {
try {
// Result will be `undefined`, but might as well return it in case of a
// future Electron API change.
let result = shell.showItemInFolder(filePath);
return { outcome: 'success', result };
} catch (error) {
// Not sure whether this can even fail, but might as well handle it.
return { outcome: 'failure', error };
}
})

// The application's singleton class.
//
// It's the entry point into the Pulsar application and maintains the global state
Expand Down

0 comments on commit f71cb57

Please sign in to comment.