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

Plugin in same package as app #245

Open
cohenstyle opened this issue Apr 4, 2023 · 3 comments
Open

Plugin in same package as app #245

cohenstyle opened this issue Apr 4, 2023 · 3 comments

Comments

@cohenstyle
Copy link

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 ?
@dimer47
Copy link

dimer47 commented Jun 30, 2023

@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
Copy link

dimer47 commented Jul 1, 2023

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.

@cohenstyle
Copy link
Author

cohenstyle commented Jul 2, 2023

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.

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

No branches or pull requests

2 participants