Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the ability to open files from the UI #486

Merged
merged 2 commits into from
Sep 11, 2024

Conversation

tylerslaton
Copy link
Contributor

This uses Electron's IPC code to open system files through the UI. It is done through a listeners on in the main.js of electron and an emitter in the next js app. Once the emitted event is received with a file it is opened with the system default.

https://www.electronjs.org/docs/latest/tutorial/ipc for more info.

#322

@tylerslaton tylerslaton marked this pull request as ready for review September 10, 2024 20:48
StrongMonkey
StrongMonkey previously approved these changes Sep 10, 2024
Copy link
Contributor

@StrongMonkey StrongMonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh Cool, I wonder if this will help fix #280

@tylerslaton
Copy link
Contributor Author

Oh Cool, I wonder if this will help fix #280

We'd have to do some stuff with our Markdown renderer to know to treat those links in a custom way but yeah its doable.

thedadams
thedadams previously approved these changes Sep 11, 2024
window.alert(
'Coming soon, we promise! This will open your file.'
// This submits a request to the electron main process to open the file
(window as any).electronAPI.openFile(
Copy link
Contributor

@ryanhopperlowe ryanhopperlowe Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you globally update the window object to add TypeScript support?

ideally add a file @/types/window.d.ts with these contents:

declare global {
  interface Window {
    electronApi: <ElectronApiType>; // You may have to type this yourself
  }
}

export {} // this is required to allow the types to be globally accessible throughout the application

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@tylerslaton tylerslaton dismissed stale reviews from thedadams and StrongMonkey via 942aebc September 11, 2024 14:36
ryanhopperlowe
ryanhopperlowe previously approved these changes Sep 11, 2024
ryanhopperlowe
ryanhopperlowe previously approved these changes Sep 11, 2024
@tylerslaton
Copy link
Contributor Author

For those coming back to the PR, the latest change is that I added typing for the electron API in the window object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants