mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-16 00:56:33 +00:00

- Updated `@theia/*` to `1.37.0`. - Fixed all `yarn audit` security vulnerabilities. - Updated to `electron@23.2.4`: - `contextIsolation` is `true`, - `nodeIntegration` is `false`, and the - `webpack` target is moved from `electron-renderer` to `web`. - Updated to `typescript@4.9.3`. - Updated the `eslint` plugins. - Added the new `Light High Contrast` theme to the IDE2. - High contrast themes use Theia APIs for style adjustments. - Support for ESM modules: `"moduleResolution": "node16"`. - Node.js >= 16.14 is required. - VISX langage packs were bumped to `1.70.0`. - Removed undesired editor context menu items. (Closes #1394) Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
|
|
import { FileUri } from '@theia/core/lib/node/file-uri';
|
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
import { promises as fs } from 'node:fs';
|
|
import {
|
|
parse as parseJsonc,
|
|
ParseError,
|
|
printParseErrorCode,
|
|
} from 'jsonc-parser';
|
|
import { join } from 'node:path';
|
|
import { ErrnoException } from './utils/errors';
|
|
|
|
// Poor man's preferences on the backend. (https://github.com/arduino/arduino-ide/issues/1056#issuecomment-1153975064)
|
|
@injectable()
|
|
export class SettingsReader {
|
|
@inject(EnvVariablesServer)
|
|
private readonly envVariableServer: EnvVariablesServer;
|
|
|
|
async read(): Promise<Record<string, unknown> | undefined> {
|
|
const configDirUri = await this.envVariableServer.getConfigDirUri();
|
|
const configDirPath = FileUri.fsPath(configDirUri);
|
|
const settingsPath = join(configDirPath, 'settings.json');
|
|
try {
|
|
const raw = await fs.readFile(settingsPath, { encoding: 'utf8' });
|
|
return parse(raw);
|
|
} catch (err) {
|
|
if (ErrnoException.isENOENT(err)) {
|
|
return undefined;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
export function parse(raw: string): Record<string, unknown> | undefined {
|
|
const errors: ParseError[] = [];
|
|
const settings =
|
|
parseJsonc(raw, errors, {
|
|
allowEmptyContent: true,
|
|
allowTrailingComma: true,
|
|
disallowComments: false,
|
|
}) ?? {};
|
|
if (errors.length) {
|
|
console.error('Detected JSONC parser errors:');
|
|
console.error('----- CONTENT START -----');
|
|
console.error(raw);
|
|
console.error('----- CONTENT END -----');
|
|
errors.forEach(({ error, offset }) =>
|
|
console.error(` - ${printParseErrorCode(error)} at ${offset}`)
|
|
);
|
|
return undefined;
|
|
}
|
|
return typeof settings === 'object' ? settings : undefined;
|
|
}
|