Skip to content

Commit

Permalink
Update types on holder/client scope
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Dec 19, 2024
1 parent ffe997f commit 6396d4b
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 195 deletions.
75 changes: 23 additions & 52 deletions application/apps/rustcore/ts-bindings/src/api/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { CancelablePromise } from 'platform/env/promise';
import { Base, Cancelled, decode } from '../native/native.jobs';
import { error } from 'platform/log/utils';
import { IFilter } from 'platform/types/filter';
import { ShellProfile } from 'platform/types/shells';
import { SomeipStatistic } from 'platform/types/observe/parser/someip';
import { StatisticInfo } from 'platform/types/observe/parser/dlt';
import { FoldersScanningResult } from 'platform/types/bindings';
import {
FoldersScanningResult,
DltStatisticInfo,
Profile,
ProfileList,
MapKeyValue,
} from 'platform/types/bindings';

import * as protocol from 'protocol';
import * as types from 'platform/types';
Expand Down Expand Up @@ -109,20 +113,18 @@ export class Jobs extends Base {
return job;
}

public getDltStats(paths: string[]): CancelablePromise<StatisticInfo> {
public getDltStats(paths: string[]): CancelablePromise<DltStatisticInfo> {
const sequence = this.sequence();
const job: CancelablePromise<StatisticInfo> = this.execute(
const job: CancelablePromise<DltStatisticInfo> = this.execute(
(buf: Uint8Array): any | Error => {
const decoded = decode<string>(buf, protocol.decodeCommandOutcomeWithString);
const decoded = decode<DltStatisticInfo>(
buf,
protocol.decodeCommandOutcomeWithDltStatisticInfo,
);
if (decoded instanceof Error) {
return decoded;
}
console.log(decoded);
try {
return JSON.parse(decoded) as StatisticInfo;
} catch (e) {
return new Error(error(e));
}
return decoded;
},
this.native.getDltStats(sequence, paths),
sequence,
Expand Down Expand Up @@ -152,27 +154,12 @@ export class Jobs extends Base {
return job;
}

public getShellProfiles(): CancelablePromise<ShellProfile[]> {
public getShellProfiles(): CancelablePromise<Profile[]> {
const sequence = this.sequence();
const job: CancelablePromise<ShellProfile[]> = this.execute(
const job: CancelablePromise<Profile[]> = this.execute(
(buf: Uint8Array): any | Error => {
const decoded = decode<string>(buf, protocol.decodeCommandOutcomeWithString);
if (decoded instanceof Error) {
return decoded;
}
try {
const unparsed: unknown[] = JSON.parse(decoded);
const profiles: ShellProfile[] = [];
unparsed.forEach((unparsed: unknown) => {
const profile = ShellProfile.fromObj(unparsed);
if (!(profile instanceof Error)) {
profiles.push(profile);
}
});
return profiles;
} catch (e) {
return new Error(error(e));
}
const decoded = decode<ProfileList>(buf, protocol.decodeCommandOutcomeWithString);
return decoded;
},
this.native.getShellProfiles(sequence),
sequence,
Expand All @@ -185,27 +172,11 @@ export class Jobs extends Base {
const sequence = this.sequence();
const job: CancelablePromise<Map<string, string>> = this.execute(
(buf: Uint8Array): Map<string, string> | Error => {
const decoded = decode<string>(buf, protocol.decodeCommandOutcomeWithString);
if (decoded instanceof Error) {
return decoded;
}
try {
const unparsed: { [key: string]: string } = JSON.parse(decoded);
const envvars: Map<string, string> = new Map();
if (
unparsed === undefined ||
unparsed === null ||
typeof unparsed !== 'object'
) {
return new Error(`Fail to parse envvars string: ${unparsed}`);
}
Object.keys(unparsed).forEach((key) => {
envvars.set(key, unparsed[key]);
});
return envvars;
} catch (e) {
return new Error(error(e));
}
const decoded = decode<MapKeyValue>(
buf,
protocol.decodeCommandOutcomeWithMapKeyValue,
);
return decoded;
},
this.native.getContextEnvvars(sequence),
sequence,
Expand Down
21 changes: 9 additions & 12 deletions application/client/src/app/service/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { services } from '@register/services';
import { File, Entity } from '@platform/types/files';
import { FolderEntity } from '@platform/types/bindings';
import { FileType } from '@platform/types/observe/types/file';
import { ShellProfile } from '@platform/types/shells';
import { StatisticInfo } from '@platform/types/observe/parser/dlt';
import { DltStatisticInfo, Profile } from '@platform/types/bindings';
import { Entry } from '@platform/types/storage/entry';
import { error } from '@platform/log/utils';

Expand All @@ -13,7 +12,7 @@ import * as Requests from '@platform/ipc/request/index';
@SetupService(services['bridge'])
export class Service extends Implementation {
protected cache: {
shells: ShellProfile[] | undefined;
shells: Profile[] | undefined;
files: Map<string, File>;
checksums: Map<string, string>;
} = {
Expand All @@ -23,7 +22,7 @@ export class Service extends Implementation {
};
protected queue: {
shells: Array<{
resolve: (profiles: ShellProfile[]) => void;
resolve: (profiles: Profile[]) => void;
reject: (err: Error) => void;
}>;
} = {
Expand Down Expand Up @@ -400,10 +399,10 @@ export class Service extends Implementation {
}

public dlt(): {
stat(files: string[]): Promise<StatisticInfo>;
stat(files: string[]): Promise<DltStatisticInfo>;
} {
return {
stat: (files: string[]): Promise<StatisticInfo> => {
stat: (files: string[]): Promise<DltStatisticInfo> => {
return new Promise((resolve, reject) => {
Requests.IpcRequest.send(
Requests.Dlt.Stat.Response,
Expand Down Expand Up @@ -537,7 +536,7 @@ export class Service extends Implementation {

public os(): {
homedir(): Promise<string>;
shells(): Promise<ShellProfile[]>;
shells(): Promise<Profile[]>;
envvars(): Promise<Map<string, string>>;
} {
return {
Expand All @@ -553,7 +552,7 @@ export class Service extends Implementation {
.catch(reject);
});
},
shells: (): Promise<ShellProfile[]> => {
shells: (): Promise<Profile[]> => {
return new Promise((resolve, reject) => {
if (this.cache.shells !== undefined) {
resolve(this.cache.shells);
Expand All @@ -565,12 +564,10 @@ export class Service extends Implementation {
new Requests.Os.Shells.Request(),
)
.then((response) => {
this.cache.shells = response.profiles
.map((p) => ShellProfile.fromObj(p))
.filter((p) => p instanceof ShellProfile) as ShellProfile[];
this.cache.shells = response.profiles;
this.queue.shells
.map((h) => h.resolve)
.forEach((r) => r(this.cache.shells as ShellProfile[]));
.forEach((r) => r(this.cache.shells as Profile[]));
})
.catch((err: Error) => {
this.queue.shells.map((h) => h.reject).forEach((r) => r(err));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Ilc, IlcInterface } from '@env/decorators/component';
import { State } from '../../states/process';
import { components } from '@env/decorators/initial';
import { ShellProfile } from '@platform/types/shells';
import { Profile } from '@platform/types/bindings';
import { Action } from '@ui/tabs/observe/action';
import { Session } from '@service/session';

Expand Down Expand Up @@ -196,7 +196,7 @@ export class SetupBase
});
}

public importEnvVars(profile: ShellProfile | undefined) {
public importEnvVars(profile: Profile | undefined) {
this.state.importEnvvarsFromShell(profile).catch((err: Error) => {
this.log().error(`Fail to save selected profile: ${err.message}`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Options as FoldersOptions } from '@elements/folderinput/component';
import { Subject } from '@platform/env/subscription';
import { CmdErrorState } from '../../bases/process/error';
import { SetupBase } from '../../bases/process/component';
import { Profile } from '@platform/types/bindings';

@Component({
selector: 'app-transport-process',
Expand Down Expand Up @@ -60,5 +61,9 @@ export class Setup extends SetupBase implements AfterContentInit, AfterViewInit,
);
super.ngAfterContentInit();
}

public getEnvvarsCount(profile: Profile) {
return profile.envvars ? profile.envvars.size : 0;
}
}
export interface Setup extends IlcInterface {}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<div class="command">
<app-autocomplete-input #cmd [options]="inputs.cmd"
<app-autocomplete-input
#cmd
[options]="inputs.cmd"
(edit)="edit('cmd', $event)"
(enter)="enter('cmd')"
(panel)="panel()"></app-autocomplete-input>
(panel)="panel()"
></app-autocomplete-input>
<button tabindex="-1" class="flat-codicon-button" [matMenuTriggerFor]="menu">
<ng-container *ngIf="state.isProfilesLoaded()">
<span class="codicon codicon-terminal"></span>
Expand All @@ -14,19 +17,29 @@
</ng-container>
</button>
</div>
<app-folderinput-input #cwd [options]="inputs.cwd"
<app-folderinput-input
#cwd
[options]="inputs.cwd"
(edit)="edit('cwd', $event)"
(enter)="enter('cwd')"
(panel)="panel()"></app-folderinput-input>
(panel)="panel()"
></app-folderinput-input>
<mat-menu #menu="matMenu" class="app-transport-process-menu">
<button mat-menu-item (click)="importEnvVars(undefined)">Use default environment</button>
<mat-divider></mat-divider>
<ng-container *ngIf="state.isProfilesLoaded()">
<p class="material-menu-label">Import variables from:</p>
<button *ngFor="let profile of state.profiles.valid" [attr.data-selected]="state.isShellSelected(profile)" mat-menu-item (click)="importEnvVars(profile)">
<button
*ngFor="let profile of state.profiles.valid"
[attr.data-selected]="state.isShellSelected(profile)"
mat-menu-item
(click)="importEnvVars(profile)"
>
<div class="shell-profile">
<span class="shell-name">{{profile.name}}</span>
<span class="envvars-count">{{(' (has ' + profile.getEnvvarsCount() + ' vars)')}}</span>
<span class="envvars-count"
>{{(' (has ' + getEnvvarsCount(profile) + ' vars)')}}</span
>
<span class="shell-path">{{profile.path}}</span>
</div>
</button>
Expand All @@ -37,4 +50,4 @@
</ng-container>
<mat-divider></mat-divider>
<button mat-menu-item (click)="showEnvVars()">Show current variables</button>
</mat-menu>
</mat-menu>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Options as FoldersOptions } from '@elements/folderinput/component';
import { Subject } from '@platform/env/subscription';
import { CmdErrorState } from '../../bases/process/error';
import { SetupBase } from '../../bases/process/component';
import { Profile } from '@platform/types/bindings';

@Component({
selector: 'app-process-quicksetup',
Expand Down Expand Up @@ -46,6 +47,10 @@ export class QuickSetup extends SetupBase implements AfterContentInit, OnDestroy
this.setInputs(this.inputs);
}

public getEnvvarsCount(profile: Profile) {
return profile.envvars ? profile.envvars.size : 0;
}

public destroy(): Promise<void> {
return Promise.resolve();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<div class="command">
<app-autocomplete-input #cmd [options]="inputs.cmd"
<app-autocomplete-input
#cmd
[options]="inputs.cmd"
(edit)="edit('cmd', $event)"
(enter)="enter('cmd')"
(panel)="panel()"></app-autocomplete-input>
(panel)="panel()"
></app-autocomplete-input>
<button tabindex="-1" class="flat-codicon-button" [matMenuTriggerFor]="menu">
<ng-container *ngIf="state.isProfilesLoaded()">
<span class="codicon codicon-terminal"></span>
Expand All @@ -14,19 +17,29 @@
</ng-container>
</button>
</div>
<app-folderinput-input #cwd [options]="inputs.cwd"
<app-folderinput-input
#cwd
[options]="inputs.cwd"
(edit)="edit('cwd', $event)"
(enter)="enter('cwd')"
(panel)="panel()"></app-folderinput-input>
(panel)="panel()"
></app-folderinput-input>
<mat-menu #menu="matMenu" class="app-transport-process-menu">
<button mat-menu-item (click)="importEnvVars(undefined)">Use default environment</button>
<mat-divider></mat-divider>
<ng-container *ngIf="state.isProfilesLoaded()">
<p class="material-menu-label">Import variables from:</p>
<button *ngFor="let profile of state.profiles.valid" [attr.data-selected]="state.isShellSelected(profile)" mat-menu-item (click)="importEnvVars(profile)">
<button
*ngFor="let profile of state.profiles.valid"
[attr.data-selected]="state.isShellSelected(profile)"
mat-menu-item
(click)="importEnvVars(profile)"
>
<div class="shell-profile">
<span class="shell-name">{{profile.name}}</span>
<span class="envvars-count">{{(' (has ' + profile.getEnvvarsCount() + ' vars)')}}</span>
<span class="envvars-count"
>{{(' (has ' + getEnvvarsCount(profile) + ' vars)')}}</span
>
<span class="shell-path">{{profile.path}}</span>
</div>
</button>
Expand All @@ -37,4 +50,4 @@
</ng-container>
<mat-divider></mat-divider>
<button mat-menu-item (click)="showEnvVars()">Show current variables</button>
</mat-menu>
</mat-menu>
Loading

0 comments on commit 6396d4b

Please sign in to comment.