Skip to content

Commit

Permalink
WIP commit, Migrating to new plugin API
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Oct 10, 2023
1 parent 37ba76f commit 3807f23
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
16 changes: 10 additions & 6 deletions src/main/services/pluginsService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fsUtils } from 'main/utils';
import { ProjectMessageBroker } from 'main/project/projectMessageBroker';
import project from 'main/project';

import { LogLevel } from 'shared/types';
import { LogLevel, FileTypeMap } from 'shared/types';
import { PluginConfig } from 'shared/types/plugin';
import { sanitizePath, tryGetAsync } from 'shared/utils';

Expand Down Expand Up @@ -88,11 +88,15 @@ class PluginsService implements IService {
// TODO: consider better naming
getFileTypePlugins() {
const plugins = this.#plugins;
const result = Object.fromEntries(
Object.entries(plugins)
.filter((kv) => kv[1].flowView.fileType !== null)
.map((kv) => [kv[1].flowView.fileType, kv[1]])
);

const result: FileTypeMap = {};

Object.entries(plugins).forEach(([_key, plug]) => {
plug.flowViews.forEach((fv) => {
result[fv.fileType] = fv;
});
});

return result;
}

Expand Down
13 changes: 7 additions & 6 deletions src/main/services/pluginsService/pluginApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ export class FlowViewBuilder {
}

export default class PluginBuilder {
flowView: FlowViewBuilder;
#flowViews: FlowViewBuilder[] = [];

constructor() {
this.flowView = new FlowViewBuilder();
addFlowView(): FlowViewBuilder {
const flowView = new FlowViewBuilder();
this.#flowViews.push(flowView);
return flowView;
}

build(): PluginConfig {
const flowViewBuilder = this.flowView;
const flowView = flowViewBuilder.build();
return { flowView };
const flowViews = this.#flowViews.map((builder) => builder.build());
return { flowViews };
}
}
2 changes: 1 addition & 1 deletion src/renderer/components/Tab/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function TabView({ tabId }: TabViewProps) {
<FlowView
tabId={tabId}
setTabIsDirty={setTabIsDirty}
config={fileTypePlugin.flowView}
config={fileTypePlugin}
/>
);
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/shared/types/fileTypeMap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PluginConfig } from './plugin';
import { FlowViewConfig } from './plugin';
// import { PluginConfig } from './plugin';

export type FileTypeMap = { [name: string]: PluginConfig };
export type FileTypeMap = { [name: string]: FlowViewConfig };
// export type FileTypeMap = { [name: string]: PluginConfig };
2 changes: 1 addition & 1 deletion src/shared/types/plugin/pluginConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export type FlowViewConfig = {
};

export type PluginConfig = {
flowView: FlowViewConfig;
flowViews: FlowViewConfig[];
};

0 comments on commit 3807f23

Please sign in to comment.