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 management page #24

Merged
merged 7 commits into from
Nov 15, 2023

Conversation

avidreder
Copy link
Contributor

image
  • Adds page to show/enable plugins
  • Adds service for storing and managing plugin configurations
  • Moves dev plugins to individual imports to allow them to be enabled/disabled
  • Adds destroy implementation to plugins
  • Adds return value to writeJSON

Copy link
Member

@zach-herridge zach-herridge left a comment

Choose a reason for hiding this comment

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

Nice work! Left a few small comments.

src/echo-common/src/echo-router.ts Outdated Show resolved Hide resolved
src/echo-app/src/renderer/src/plugin-settings-page.tsx Outdated Show resolved Hide resolved
@@ -3,6 +3,19 @@
* All of these plugins have HMR enabled, regardless of whether you only have the plugins folder open
*/

export const getDevPlugins = () => {
return [import('character-plugin'), import('stash-plugin'), import('poe-log-plugin')]
export const importDevPlugin = (pluginName: string) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we need to do this, importing the plugin doesn't really enabled and disable them. We can import the plugins and just selectively call start on the enabled ones. This list of plugins will always just be these 3 example plugins since the list is really just here for people to add the plugin they are working on locally but that will never be committed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main reason to do this was that I need a way to get a handle on the module and it's entry so that I call it's methods on the plugin-settings-page. I'm sure there is another way to do this, but couldn't figure it out.

Copy link
Contributor

@C3ntraX C3ntraX Nov 14, 2023

Choose a reason for hiding this comment

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

You can't set a dynamic variable as import.

We may have to write the file to the system with the plugins we want to be in dev enviornment with HMR enabled. The HMR should regonize this and will rename the imports. This would be the way. Its a bit complicated but it should work, because the HMR is listening for file changes. We just have to trigger a file change with valid imports and everything should work.

Copy link
Contributor

@C3ntraX C3ntraX Nov 14, 2023

Choose a reason for hiding this comment

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

Its because the HMR changes the module names with static replacement.
import('character-plugin') would be => require('entry-2416da1sd') or something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW HMR still worked with the solution of importing then one by one.

The switch statement that maps the stored plug-in configs to imports allows us to pseudo dynamically import.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but its hardcoded. With my idea, we could use your plugin to dynamially enable and disable plguins in HMR without this hardcoded switch. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, we would let your plugin to be static enabled and the others are controlled by your plugin

Copy link
Contributor

@C3ntraX C3ntraX Nov 14, 2023

Choose a reason for hiding this comment

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

Its basically this:
https://github.com/PoeStack/poestack-sage/blob/main/src/echo-app/bump-version.js
But the plugins writes this dynamically. And we could read every plugin within the folder echo-plugins and echo-plugin-examples.
But we have to ensure, that the package.json in echo-app has set all plugins as dependency, or the HMR can not resolve the plugins

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@C3ntraX I think I see what you mean, but I think I need a little more help with how that would be implemented. I think I need you to create a gist of how this would work, so I can understand the pattern better.

@zach-herridge a few options for this PR:

  • Merge as is, and iterate on it
  • I can revert the dev plugin enablement code, and merge just the production plugin bit, then follow up with the solution @C3ntraX mentioned
  • Keep it open

I think no matter what I'll probably need some assistance in implementing the dynamic imports

@@ -3,6 +3,19 @@
* All of these plugins have HMR enabled, regardless of whether you only have the plugins folder open
*/

export const getDevPlugins = () => {
return [import('character-plugin'), import('stash-plugin'), import('poe-log-plugin')]
export const importDevPlugin = (pluginName: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but its hardcoded. With my idea, we could use your plugin to dynamially enable and disable plguins in HMR without this hardcoded switch. What do you think?

@@ -3,6 +3,19 @@
* All of these plugins have HMR enabled, regardless of whether you only have the plugins folder open
*/

export const getDevPlugins = () => {
return [import('character-plugin'), import('stash-plugin'), import('poe-log-plugin')]
export const importDevPlugin = (pluginName: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, we would let your plugin to be static enabled and the others are controlled by your plugin

@@ -3,6 +3,19 @@
* All of these plugins have HMR enabled, regardless of whether you only have the plugins folder open
*/

export const getDevPlugins = () => {
return [import('character-plugin'), import('stash-plugin'), import('poe-log-plugin')]
export const importDevPlugin = (pluginName: string) => {
Copy link
Contributor

@C3ntraX C3ntraX Nov 14, 2023

Choose a reason for hiding this comment

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

Its basically this:
https://github.com/PoeStack/poestack-sage/blob/main/src/echo-app/bump-version.js
But the plugins writes this dynamically. And we could read every plugin within the folder echo-plugins and echo-plugin-examples.
But we have to ensure, that the package.json in echo-app has set all plugins as dependency, or the HMR can not resolve the plugins

Comment on lines +41 to +43
} else {
plugin.destroy()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make await plugin.destroy() to give the plugin the chacne to write data before it gets destroyed

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay I see. destory calls unregister Route. Within the call the plugin could write the unregister after Promise.resolve()
Do you delete the plugin afterwards? Then I would wait for the plugin, if not it would make no difference I guess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there isn't any deletion in this PR. I wouldn't delete anything except by "uninstalling" it, which isn't implemented in this PR

@zach-herridge zach-herridge merged commit 1550047 into PoeStack:main Nov 15, 2023
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.

None yet

3 participants