feat: no remote fetch when IDE gets CLI version

the CLI version is retrieved from the `package.json` of the extension:
`arduino.cli.version`

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2023-01-06 10:26:21 +01:00 committed by Akos Kitta
parent 76f9f635d8
commit da0fecfd0f
5 changed files with 7 additions and 39 deletions

View File

@ -41,22 +41,16 @@ export class About extends Contribution {
} }
async showAbout(): Promise<void> { async showAbout(): Promise<void> {
const { const version = await this.configService.getVersion();
version,
commit,
status: cliStatus,
} = await this.configService.getVersion();
const buildDate = this.buildDate; const buildDate = this.buildDate;
const detail = (showAll: boolean) => const detail = (showAll: boolean) =>
nls.localize( nls.localize(
'arduino/about/detail', 'arduino/about/detail',
'Version: {0}\nDate: {1}{2}\nCLI Version: {3}{4} [{5}]\n\n{6}', 'Version: {0}\nDate: {1}{2}\nCLI Version: {3}\n\n{4}',
remote.app.getVersion(), remote.app.getVersion(),
buildDate ? buildDate : nls.localize('', 'dev build'), buildDate ? buildDate : nls.localize('', 'dev build'),
buildDate && showAll ? ` (${this.ago(buildDate)})` : '', buildDate && showAll ? ` (${this.ago(buildDate)})` : '',
version, version,
cliStatus ? ` ${cliStatus}` : '',
commit,
nls.localize( nls.localize(
'arduino/about/copyright', 'arduino/about/copyright',
'Copyright © {0} Arduino SA', 'Copyright © {0} Arduino SA',

View File

@ -3,9 +3,7 @@ import { RecursivePartial } from '@theia/core/lib/common/types';
export const ConfigServicePath = '/services/config-service'; export const ConfigServicePath = '/services/config-service';
export const ConfigService = Symbol('ConfigService'); export const ConfigService = Symbol('ConfigService');
export interface ConfigService { export interface ConfigService {
getVersion(): Promise< getVersion(): Promise<Readonly<string>>;
Readonly<{ version: string; commit: string; status?: string }>
>;
getConfiguration(): Promise<ConfigState>; getConfiguration(): Promise<ConfigState>;
setConfiguration(config: Config): Promise<void>; setConfiguration(config: Config): Promise<void>;
} }

View File

@ -15,7 +15,7 @@ import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
import { ArduinoDaemon, NotificationServiceServer } from '../common/protocol'; import { ArduinoDaemon, NotificationServiceServer } from '../common/protocol';
import { CLI_CONFIG } from './cli-config'; import { CLI_CONFIG } from './cli-config';
import { getExecPath, spawnCommand } from './exec-util'; import { getExecPath } from './exec-util';
import { ErrnoException } from './utils/errors'; import { ErrnoException } from './utils/errors';
@injectable() @injectable()
@ -126,28 +126,6 @@ export class ArduinoDaemonImpl
return this._execPath; return this._execPath;
} }
async getVersion(): Promise<
Readonly<{ version: string; commit: string; status?: string }>
> {
const execPath = await this.getExecPath();
const raw = await spawnCommand(
`"${execPath}"`,
['version', '--format', 'json'],
this.onError.bind(this)
);
try {
// The CLI `Info` object: https://github.com/arduino/arduino-cli/blob/17d24eb901b1fdaa5a4ec7da3417e9e460f84007/version/version.go#L31-L34
const { VersionString, Commit, Status } = JSON.parse(raw);
return {
version: VersionString,
commit: Commit,
status: Status,
};
} catch {
return { version: raw, commit: raw };
}
}
protected async getSpawnArgs(): Promise<string[]> { protected async getSpawnArgs(): Promise<string[]> {
const [configDirUri, debug] = await Promise.all([ const [configDirUri, debug] = await Promise.all([
this.envVariablesServer.getConfigDirUri(), this.envVariablesServer.getConfigDirUri(),

View File

@ -131,10 +131,8 @@ export class ConfigServiceImpl
return this.configChangeEmitter.event; return this.configChangeEmitter.event;
} }
async getVersion(): Promise< async getVersion(): Promise<string> {
Readonly<{ version: string; commit: string; status?: string }> return require('../../package.json').arduino?.cli?.version || '';
> {
return this.daemon.getVersion();
} }
private async initConfig(): Promise<void> { private async initConfig(): Promise<void> {

View File

@ -1,7 +1,7 @@
{ {
"arduino": { "arduino": {
"about": { "about": {
"detail": "Version: {0}\nDate: {1}{2}\nCLI Version: {3}{4} [{5}]\n\n{6}", "detail": "Version: {0}\nDate: {1}{2}\nCLI Version: {3}\n\n{4}",
"label": "About {0}" "label": "About {0}"
}, },
"board": { "board": {