Skip to content

Commit

Permalink
WIP commit, Implementing use of filetype plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Oct 4, 2023
1 parent 00f042f commit 779d6eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/main/ipc/invokes/getFileTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default async function getFileTypes(
event: IpcMainInvokeEvent,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_: undefined
): Promise<string[]> {
const pluginsService = project.pluginsService;
const fileTypes = pluginsService.getFileTypePlugins();
return ['ok'];
): Promise<any[]> {
const { pluginsService } = project;
const fileTypePlugins = pluginsService.getFileTypePlugins();
return fileTypePlugins;
}
12 changes: 8 additions & 4 deletions src/main/services/pluginsService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import project from 'main/project';
import { LogLevel } from 'shared/types';
import { sanitizePath, tryGetAsync } from 'shared/utils';

import PluginApi from './pluginApi';
import PluginApi, { PluginConfig } from './pluginApi';

import IService from '../IService';

Expand All @@ -15,15 +15,15 @@ class PluginsService implements IService {

#pluginsFolder: string;

#plugins: any;
#plugins: { [name: string]: PluginConfig };

constructor(pluginsFolder: string, messageBroker: ProjectMessageBroker) {
this.#messageBroker = messageBroker;
this.#pluginsFolder = sanitizePath(pluginsFolder);
this.#plugins = {};
}

async init(): Promise<boolean> {
this.#plugins = {};
try {
await this.loadPlugins();
return true;
Expand Down Expand Up @@ -87,7 +87,11 @@ class PluginsService implements IService {
// TODO: consider better naming
getFileTypePlugins() {
const plugins = this.#plugins;
console.log(plugins);
const result = Object.entries(plugins)
.filter((kv) => kv[1].flowView.fileType !== null)
.map((kv) => kv[0])
.map((key) => plugins[key]);
return result;
}

// eslint-disable-next-line class-methods-use-this
Expand Down
21 changes: 15 additions & 6 deletions src/main/services/pluginsService/pluginApi.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
type ConnectionInfo = {
export type ConnectionInfo = {

Check failure on line 1 in src/main/services/pluginsService/pluginApi.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

File has too many classes (2). Maximum allowed is 1
in: number;
out: number;
};

type NodeInfo = {
export type NodeInfo = {
type: string;
connection: ConnectionInfo;
};

export type FlowViewConfig = {
fileType: string;
nodes: NodeInfo[];
};

export type PluginConfig = {
flowView: FlowViewConfig;
};

// builder.flowView.setFileType('xxx') // *.xxx
// builder.flowView.setNodes(xxx)
// builder.globalShortcut.setShortcutAction(yyy)

class FlowViewBuilder {
export class FlowViewBuilder {
#fileType: string | null = null;

#nodes: NodeInfo[] | null = null;
Expand All @@ -28,10 +37,10 @@ class FlowViewBuilder {
}

// TODO: making these build functions private can help with a well constructed API
build() {
build(): FlowViewConfig {
const fileType = this.#fileType;
const nodes = this.#nodes;
return { fileType, nodes };
return { fileType: fileType || '', nodes: nodes || [] };
}
}

Expand All @@ -42,7 +51,7 @@ export default class PluginBuilder {
this.flowView = new FlowViewBuilder();
}

build() {
build(): PluginConfig {
const flowViewBuilder = this.flowView;
const flowView = flowViewBuilder.build();
return { flowView };
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/Tab/TabView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default function TabView({ tabId }: TabViewProps) {
[dispatch, tabId]
);
const dispatchFileView = () => {
console.log(fileTypes, 'fileTypes')
console.log(fileTypes, 'fileTypes');
console.log(fileTypes[tabData.extension], '??');
if (tabData.extension === 'xflow') {
return <FlowView tabId={tabId} setTabIsDirty={setTabIsDirty} />;
}
Expand Down

0 comments on commit 779d6eb

Please sign in to comment.