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

Update Desktop.d.ts #3126

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 62 additions & 26 deletions frontend/Desktop.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
declare global {
declare global {
/**
* This namespace is meant for [PlutoDesktop](https://github.com/JuliaPluto/PlutoDesktop)
* related types and interfaces.
* This namespace is designed for [PlutoDesktop](https://github.com/JuliaPluto/PlutoDesktop)
* related types and interfaces, facilitating native app integration.
*/
namespace Desktop {
/**
* This enum has to be in sync with the enum "PlutoExport"
* defined in PlutoDesktop/{branch:master}/types/enums.ts
* Enum for export types. Ensure this is in sync with "PlutoExport"
* defined in `PlutoDesktop/{branch:master}/types/enums.ts`.
*
* @note Unfortunately enums can't be exported from .d.ts files.
* Inorder to use this, just map integers to the enum values
* @note Enums cannot be directly exported from `.d.ts` files. Use the integer mappings:
* - PlutoExport.FILE -> **0**
* - PlutoExport.HTML -> **1**
* - PlutoExport.STATE -> **2**
Expand All @@ -23,33 +22,70 @@ declare global {
}

/**
* This type has to be in sync with the interface "Window"
* defined in PlutoDesktop/{branch:master}/src/renderer/preload.d.ts
* Type definition for PlutoDesktop functionalities.
* Ensure sync with "Window" interface in `PlutoDesktop/{branch:master}/src/renderer/preload.d.ts`.
*/
type PlutoDesktop = {
interface PlutoDesktop {
ipcRenderer: {
sendMessage(channel: String, args: unknown[]): void
on(channel: string, func: (...args: unknown[]) => void): (() => void) | undefined
once(channel: string, func: (...args: unknown[]) => void): void
}
/**
* Sends a message to the main process via a specific channel.
* @param channel The name of the channel.
* @param args Arguments to send with the message.
*/
sendMessage(channel: string, args: unknown[]): void;

/**
* Registers a listener for a specific channel.
* @param channel The name of the channel.
* @param func The callback to invoke when the event occurs.
* @returns A function to remove the listener or `undefined` if registration fails.
*/
on(channel: string, func: (...args: unknown[]) => void): (() => void) | undefined;

/**
* Registers a one-time listener for a specific channel.
* @param channel The name of the channel.
* @param func The callback to invoke when the event occurs.
*/
once(channel: string, func: (...args: unknown[]) => void): void;
};

fileSystem: {
/**
* @param type [default = 'new'] whether you want to open a new notebook
* open a notebook from a path or from a url
* @param pathOrURL location to the file, not needed if opening a new file,
* opens that notebook. If false and no path is there, opens the file selector.
* If true, opens a new blank notebook.
* Opens a notebook.
* @param type The type of operation: "url" | "path" | "new". Defaults to "new".
* @param pathOrURL The location of the file or URL to open. Optional for "new".
*/
openNotebook(type?: "url" | "path" | "new", pathOrURL?: string): void
shutdownNotebook(id?: string): void
moveNotebook(id?: string): void
exportNotebook(id: string, type: PlutoExport): void
}
openNotebook(type?: "url" | "path" | "new", pathOrURL?: string): void;

/**
* Shuts down a notebook by its ID.
* @param id The ID of the notebook to shut down.
*/
shutdownNotebook(id?: string): void;

/**
* Moves a notebook to a new location.
* @param id The ID of the notebook to move.
*/
moveNotebook(id?: string): void;

/**
* Exports a notebook.
* @param id The ID of the notebook to export.
* @param type The export type as defined in `PlutoExport`.
*/
exportNotebook(id: string, type: PlutoExport): void;
};
}
}

/**
* Extends the Window interface for native app integration.
*/
interface Window {
plutoDesktop?: Desktop.PlutoDesktop
plutoDesktop?: Desktop.PlutoDesktop;
}
}

export {}
export {};
Loading