electron icon indicating copy to clipboard operation
electron copied to clipboard

Plugin in same package as app

Open cohenstyle opened this issue 2 years ago • 3 comments

Describe the bug I'm developing a plugin in the same package as my app to make it easy to iterate. I'm able to get it into the window by adding it in electron-plugins.js But even though I've added an electron platform to the registerPlugin call, whenever I try to use it I get a not implemented error. I may be missing another place I have to hook it up? When I call the echo function (only implemented function) on the CapacitorCustomPlugin.plugins.name object it seems to work.

To Reproduce Steps to reproduce the behavior:

Create a plugin in a project and manually add it in electron-plugins.js

Expected behavior Be able to use it.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
  • Browser Chrome I suspect
  • Version ?

cohenstyle avatar Apr 04 '23 13:04 cohenstyle

@cohenstyle Thank you for posting this issue. I'm facing the same problem as well. From what I understand, the loadPluginImplementation() method of '@capacitor/core' (https://github.com/ionic-team/capacitor/blob/d0ab34fb04d63d6feba496a7c2bd802b455861d6/core/src/runtime.ts#L100) returns undefined instead of returning the plugin code for the platform.

@cohenstyle Have you found a solution or workaround for this issue?

dimer47 avatar Jun 30 '23 19:06 dimer47

Hi @cohenstyle,

After investigating further in my index.ts file, where I reference the code for Electron, I realized that I had pointed to a different reference than the one loaded by Electron when capacitor-electron loads the plugins. In fact, it takes the class name and not the object name that we want to call with the plugin.

import { registerPlugin } from '@capacitor/core';

import type { SerialPortPlugin } from './definitions';

const SerialPort = registerPlugin<SerialPortPlugin>('SerialPort', {
  web: () => import('./web').then(m => new m.SerialPortWeb()),
  // electron: () => (window as any).CapacitorCustomPlatform.plugins.SerialPort,    => my error SerialPort instead of SerialPortElectron
  electron: () => (window as any).CapacitorCustomPlatform.plugins.SerialPortElectron,
});

export * from './definitions';
export { SerialPort };

We may not have the same issue, but sometimes, it's these small details that cause our problems. Perhaps you are facing the same issue, and if so, I hope I could help you.

Best regards.

dimer47 avatar Jul 01 '23 08:07 dimer47

Thanks @dimer47. I've been focused on Android lately and am having trouble getting electron running in my project altogether at the moment. I'll likely give this a shot when I get it running.

cohenstyle avatar Jul 02 '23 11:07 cohenstyle