capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
335 stars 59 forks source link

Documentation to create a plugin is missing a step #158

Closed RandomEngy closed 2 years ago

RandomEngy commented 2 years ago

https://capacitor-community.github.io/electron/docs/creatingplugins/

This did not work until I edited src/index.ts in the plugin directory. I needed to add:

electron: () => (window as any).CapacitorCustomPlatform.plugins.Dialog,

Otherwise it would just run the web implementation of the plugin on Electron.

IT-MikeS commented 2 years ago

Where you looking to run this in the renderer?

The electron plugins are meant to run in main, as to act as native layer interactions as the official platforms plugins do.

RandomEngy commented 2 years ago

Yeah, I was trying to call it from the renderer process. I was looking for an abstraction model where I could have a platform-agnostic web page that calls into an interface that gives it platform-specific functionality. I was originally trying to use the capacitor electron plugins to do this, but I think this was probably the wrong approach.

My current approach is to set up a "plat" global object that exposes this functionality, set up in preload.ts. I plan to have a different implementation for this object for other platforms.

export interface PlatformApi {
    signIn: () => Promise<void>;
    getUserInfo: () => Promise<any>;
    getIdToken: () => Promise<string>;
    getComputerName: () => string;
    registerForNotifications: (callback: (notificationData: MutationPushMessage) => void) => void;
    getFcmToken: () => Promise<string>;
    testAction: () => void;
}