Skip to content

Commit

Permalink
Update Plugin Manager (client)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Feb 17, 2025
1 parent 633e612 commit e12330e
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 89 deletions.
15 changes: 14 additions & 1 deletion application/client/src/app/service/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetupService, Interface, Implementation, register } from '@platform/entity/service';
import { services } from '@register/services';
import { InvalidPluginEntity, PluginEntity } from '@platform/types/bindings/plugins';
import { InvalidPluginEntity, PluginEntity, PluginRunData } from '@platform/types/bindings/plugins';

import * as Requests from '@platform/ipc/request/index';

Expand Down Expand Up @@ -84,6 +84,19 @@ export class Service extends Implementation {
});
}

public getPluginRunData(pluginPath: string): Promise<PluginRunData | undefined> {
return new Promise((reslove, reject) => {
Requests.IpcRequest.send(
Requests.Plugins.PluginRunData.Response,
new Requests.Plugins.PluginRunData.Request({ pluginPath }),
)
.then((response: Requests.Plugins.PluginRunData.Response) => {
reslove(response.data);
})
.catch(reject);
});
}

public reloadPlugins(): Promise<void> {
return new Promise((resolve, reject) => {
Requests.IpcRequest.send(
Expand Down
76 changes: 62 additions & 14 deletions application/client/src/app/ui/tabs/plugins/desc.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
import { PluginEntity } from '@platform/types/bindings/plugins';
import { PluginEntity, InvalidPluginEntity } from '@platform/types/bindings/plugins';
import { bridge } from '@service/bridge';
import { ParsedPath } from '@platform/types/files';

export class PluginDesc {
export abstract class PluginDescription {
public name: string = '';
public desc: string = '';
public icon: string = '';
public path: ParsedPath | undefined;

constructor(public readonly entity: PluginEntity) {}
protected abstract getName(): string;
protected abstract getDesc(): string;
protected abstract getIcon(): string;

protected update() {
this.icon = this.getIcon();
this.name = this.getName();
this.desc = this.getDesc();
}

public abstract getPath(): string;
public abstract isValid(): boolean;

public load(): Promise<void> {
return bridge
.files()
.name(this.entity.dir_path)
.name(this.getPath())
.then((path: ParsedPath) => {
this.path = path;
this.update();
});
}
}

protected update() {
this.icon = this.getIcon();
this.name = this.getName();
this.desc = this.getDesc();
export class InstalledPluginDesc extends PluginDescription {
constructor(public readonly entity: PluginEntity) {
super();
}

protected getIcon(): string {
protected override getIcon(): string {
switch (this.entity.plugin_type) {
case 'Parser':
return 'swap_vert';
case 'ByteSource':
return 'input';
}
}

protected getName(): string {
protected override getName(): string {
if (!this.entity.metadata && !this.path) {
return this.entity.dir_path;
} else if (!this.entity.metadata && this.path) {
Expand All @@ -46,8 +55,7 @@ export class PluginDesc {
return this.entity.dir_path;
}
}

protected getDesc(): string {
protected override getDesc(): string {
if (!this.entity.metadata && !this.path) {
return this.entity.dir_path;
} else if (!this.entity.metadata && this.path) {
Expand All @@ -58,4 +66,44 @@ export class PluginDesc {
return this.entity.dir_path;
}
}
public override getPath(): string {
return this.entity.dir_path;
}
public override isValid(): boolean {
return true;
}
}

export class InvalidPluginDesc extends PluginDescription {
constructor(public readonly entity: InvalidPluginEntity) {
super();
}
protected override getIcon(): string {
switch (this.entity.plugin_type) {
case 'Parser':
return 'swap_vert';
case 'ByteSource':
return 'input';
}
}
protected override getName(): string {
if (!this.path) {
return this.entity.dir_path;
} else {
return this.path.name;
}
}
protected override getDesc(): string {
if (!this.path) {
return this.entity.dir_path;
} else {
return this.path.name;
}
}
public override getPath(): string {
return this.entity.dir_path;
}
public override isValid(): boolean {
return false;
}
}
29 changes: 13 additions & 16 deletions application/client/src/app/ui/tabs/plugins/details/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { Ilc, IlcInterface } from '@env/decorators/component';
import { Initial } from '@env/decorators/initial';
import { ChangesDetector } from '@ui/env/extentions/changes';
import { micromark } from 'micromark';
import { PluginDesc } from '../desc';
import { PluginDescription } from '../desc';
import { Provider } from '../provider';
import { bridge } from '@service/bridge';

import * as dom from '@ui/env/dom';

Expand All @@ -29,7 +28,7 @@ import * as dom from '@ui/env/dom';
@Ilc()
export class Details extends ChangesDetector implements AfterViewInit, AfterContentInit, OnDestroy {
@Input() public provider!: Provider;
@Input() public plugin!: PluginDesc;
@Input() public plugin!: PluginDescription;

@ViewChild('content') contentRef!: ElementRef<HTMLElement>;

Expand All @@ -48,21 +47,19 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
if (!this.plugin.path) {
return drop();
}
const delimiter = await bridge.folders().delimiter();
const path = `${this.plugin.path.filename}${delimiter}README.md`;
if (!(await bridge.files().exists(path))) {
return drop();
}
bridge
.files()
.read(path)
.then((content: string) => {
this.readme = this.sanitizer.bypassSecurityTrustHtml(micromark(content));
this.detectChanges();
this.links().bind();
this.provider
.readme(this.plugin.path.filename)
.then((content: string | undefined) => {
if (content !== undefined) {
this.readme = this.sanitizer.bypassSecurityTrustHtml(micromark(content));
this.detectChanges();
this.links().bind();
} else {
drop();
}
})
.catch((err: Error) => {
this.log().error(`Fail to read "${path}": ${err.message}`);
this.log().error(`Fail to read "${this.plugin.getPath()}": ${err.message}`);
this.readme = '';
})
.finally(() => {
Expand Down
12 changes: 9 additions & 3 deletions application/client/src/app/ui/tabs/plugins/list/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { Ilc, IlcInterface } from '@env/decorators/component';
import { Initial } from '@env/decorators/initial';
import { ChangesDetector } from '@ui/env/extentions/changes';
import { Provider } from '../provider';
import { PluginDesc } from '../desc';
import { PluginDescription } from '../desc';

export enum Target {
Installed,
Invalid,
Available,
}

Expand All @@ -22,7 +23,7 @@ export class List extends ChangesDetector implements AfterContentInit {
@Input() public provider!: Provider;
@Input() public target!: Target;

public plugins: PluginDesc[] = [];
public plugins: PluginDescription[] = [];

constructor(cdRef: ChangeDetectorRef) {
super(cdRef);
Expand All @@ -43,6 +44,8 @@ export class List extends ChangesDetector implements AfterContentInit {
switch (this.target) {
case Target.Installed:
return 'Installed Plugins';
case Target.Invalid:
return 'Invalid Plugins';
case Target.Available:
return 'Available Plugins';
}
Expand All @@ -51,7 +54,10 @@ export class List extends ChangesDetector implements AfterContentInit {
protected update() {
switch (this.target) {
case Target.Installed:
this.plugins = this.provider.get().active();
this.plugins = this.provider.get().installed();
break;
case Target.Invalid:
this.plugins = this.provider.get().invalid();
break;
case Target.Available:
this.plugins = this.provider.get().available();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, ChangeDetectorRef, Input, HostListener, HostBinding } from '
import { Ilc, IlcInterface } from '@env/decorators/component';
import { Initial } from '@env/decorators/initial';
import { ChangesDetector } from '@ui/env/extentions/changes';
import { PluginDesc } from '../desc';
import { PluginDescription } from '../desc';
import { Provider } from '../provider';

@Component({
Expand All @@ -15,15 +15,15 @@ import { Provider } from '../provider';
@Ilc()
export class Plugin extends ChangesDetector {
@Input() public provider!: Provider;
@Input() public plugin!: PluginDesc;
@Input() public plugin!: PluginDescription;

@HostListener('click', ['$event']) onClick(_event: MouseEvent) {
this.provider.select(this.plugin.entity.dir_path);
this.provider.select(this.plugin.getPath());
}
@HostBinding('class') get getClass() {
return !this.provider.selected
? ''
: this.provider.selected.entity.dir_path === this.plugin.entity.dir_path
: this.provider.selected.getPath() === this.plugin.getPath()
? 'selected'
: '';
}
Expand Down
Loading

0 comments on commit e12330e

Please sign in to comment.