mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-18 16:56:33 +00:00
refactor monitor settings interfaces
This commit is contained in:
parent
80ade4c37e
commit
0427759fdb
@ -6,7 +6,10 @@ import {
|
|||||||
MonitorManagerProxyClient,
|
MonitorManagerProxyClient,
|
||||||
MonitorManagerProxyFactory,
|
MonitorManagerProxyFactory,
|
||||||
} from '../common/protocol/monitor-service';
|
} from '../common/protocol/monitor-service';
|
||||||
import { MonitorSettings } from '../node/monitor-settings/monitor-settings-provider';
|
import {
|
||||||
|
PluggableMonitorSettings,
|
||||||
|
MonitorSettings,
|
||||||
|
} from '../node/monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorManagerProxyClientImpl
|
export class MonitorManagerProxyClientImpl
|
||||||
@ -85,7 +88,7 @@ export class MonitorManagerProxyClientImpl
|
|||||||
async startMonitor(
|
async startMonitor(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings?: MonitorSettings
|
settings?: PluggableMonitorSettings
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return this.server().startMonitor(board, port, settings);
|
return this.server().startMonitor(board, port, settings);
|
||||||
}
|
}
|
||||||
@ -116,6 +119,7 @@ export class MonitorManagerProxyClientImpl
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command: Monitor.Command.CHANGE_SETTINGS,
|
command: Monitor.Command.CHANGE_SETTINGS,
|
||||||
// TODO: This might be wrong, verify if it works
|
// TODO: This might be wrong, verify if it works
|
||||||
|
// SPOILER: It doesn't
|
||||||
data: settings,
|
data: settings,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -118,6 +118,7 @@ export class MonitorModel implements FrontendApplicationContribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move this to /common
|
||||||
export namespace MonitorModel {
|
export namespace MonitorModel {
|
||||||
export interface State {
|
export interface State {
|
||||||
autoscroll: boolean;
|
autoscroll: boolean;
|
||||||
|
@ -182,20 +182,22 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
// This breaks if the user tries to open a monitor that
|
// This breaks if the user tries to open a monitor that
|
||||||
// doesn't support the baudrate setting.
|
// doesn't support the baudrate setting.
|
||||||
protected get baudRates(): string[] {
|
protected get baudRates(): string[] {
|
||||||
const settings = this.getCurrentSettings();
|
const { pluggableMonitorSettings } = this.getCurrentSettings();
|
||||||
const baudRateSettings = settings['baudrate'];
|
if (!pluggableMonitorSettings || !pluggableMonitorSettings['baudrate']) {
|
||||||
if (!baudRateSettings) {
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baudRateSettings = pluggableMonitorSettings['baudrate'];
|
||||||
|
|
||||||
return baudRateSettings.values;
|
return baudRateSettings.values;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get selectedBaudRate(): string {
|
protected get selectedBaudRate(): string {
|
||||||
const settings = this.getCurrentSettings();
|
const { pluggableMonitorSettings } = this.getCurrentSettings();
|
||||||
const baudRateSettings = settings['baudrate'];
|
if (!pluggableMonitorSettings || !pluggableMonitorSettings['baudrate']) {
|
||||||
if (!baudRateSettings) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
const baudRateSettings = pluggableMonitorSettings['baudrate'];
|
||||||
return baudRateSettings.selectedValue;
|
return baudRateSettings.selectedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +262,11 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
protected readonly onChangeBaudRate = (value: string) => {
|
protected readonly onChangeBaudRate = (value: string) => {
|
||||||
const settings = this.getCurrentSettings();
|
const { pluggableMonitorSettings } = this.getCurrentSettings();
|
||||||
settings['baudrate'].selectedValue = value;
|
if (!pluggableMonitorSettings || !pluggableMonitorSettings['baudrate'])
|
||||||
this.monitorManagerProxy.changeSettings(settings);
|
return;
|
||||||
|
const baudRateSettings = pluggableMonitorSettings['baudrate'];
|
||||||
|
baudRateSettings.selectedValue = value;
|
||||||
|
this.monitorManagerProxy.changeSettings(pluggableMonitorSettings);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,12 @@ export class PlotterFrontendContribution extends Contribution {
|
|||||||
let baudrates: number[] = [];
|
let baudrates: number[] = [];
|
||||||
let currentBaudrate = -1;
|
let currentBaudrate = -1;
|
||||||
if (board && port) {
|
if (board && port) {
|
||||||
const settings = this.monitorManagerProxy.getCurrentSettings(board, port);
|
const { pluggableMonitorSettings } =
|
||||||
if ('baudrate' in settings) {
|
this.monitorManagerProxy.getCurrentSettings(board, port);
|
||||||
|
if (pluggableMonitorSettings && 'baudrate' in pluggableMonitorSettings) {
|
||||||
// Convert from string to numbers
|
// Convert from string to numbers
|
||||||
baudrates = settings['baudrate'].values.map((b) => +b);
|
baudrates = pluggableMonitorSettings['baudrate'].values.map((b) => +b);
|
||||||
currentBaudrate = +settings['baudrate'].selectedValue;
|
currentBaudrate = +pluggableMonitorSettings['baudrate'].selectedValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import { Event, JsonRpcServer } from '@theia/core';
|
import { Event, JsonRpcServer } from '@theia/core';
|
||||||
import { MonitorSettings } from '../../node/monitor-settings/monitor-settings-provider';
|
import {
|
||||||
|
PluggableMonitorSettings,
|
||||||
|
MonitorSettings,
|
||||||
|
} from '../../node/monitor-settings/monitor-settings-provider';
|
||||||
import { Board, Port } from './boards-service';
|
import { Board, Port } from './boards-service';
|
||||||
|
|
||||||
export const MonitorManagerProxyFactory = Symbol('MonitorManagerProxyFactory');
|
export const MonitorManagerProxyFactory = Symbol('MonitorManagerProxyFactory');
|
||||||
@ -12,15 +15,15 @@ export interface MonitorManagerProxy
|
|||||||
startMonitor(
|
startMonitor(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings?: MonitorSettings
|
settings?: PluggableMonitorSettings
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
changeMonitorSettings(
|
changeMonitorSettings(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings: MonitorSettings
|
settings: PluggableMonitorSettings
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
stopMonitor(board: Board, port: Port): Promise<void>;
|
stopMonitor(board: Board, port: Port): Promise<void>;
|
||||||
getCurrentSettings(board: Board, port: Port): MonitorSettings;
|
getCurrentSettings(board: Board, port: Port): PluggableMonitorSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MonitorManagerProxyClient = Symbol('MonitorManagerProxyClient');
|
export const MonitorManagerProxyClient = Symbol('MonitorManagerProxyClient');
|
||||||
@ -34,14 +37,14 @@ export interface MonitorManagerProxyClient {
|
|||||||
startMonitor(
|
startMonitor(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings?: MonitorSettings
|
settings?: PluggableMonitorSettings
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
getCurrentSettings(board: Board, port: Port): MonitorSettings;
|
getCurrentSettings(board: Board, port: Port): MonitorSettings;
|
||||||
send(message: string): void;
|
send(message: string): void;
|
||||||
changeSettings(settings: MonitorSettings): void;
|
changeSettings(settings: MonitorSettings): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MonitorSetting {
|
export interface PluggableMonitorSetting {
|
||||||
// The setting identifier
|
// The setting identifier
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
// A human-readable label of the setting (to be displayed on the GUI)
|
// A human-readable label of the setting (to be displayed on the GUI)
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
} from '../common/protocol';
|
} from '../common/protocol';
|
||||||
import { Board, Port } from '../common/protocol';
|
import { Board, Port } from '../common/protocol';
|
||||||
import { MonitorManager } from './monitor-manager';
|
import { MonitorManager } from './monitor-manager';
|
||||||
import { MonitorSettings } from './monitor-settings/monitor-settings-provider';
|
import { PluggableMonitorSettings } from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
||||||
@ -32,7 +32,7 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
async startMonitor(
|
async startMonitor(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings?: MonitorSettings
|
settings?: PluggableMonitorSettings
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (settings) {
|
if (settings) {
|
||||||
await this.changeMonitorSettings(board, port, settings);
|
await this.changeMonitorSettings(board, port, settings);
|
||||||
@ -54,7 +54,7 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
async changeMonitorSettings(
|
async changeMonitorSettings(
|
||||||
board: Board,
|
board: Board,
|
||||||
port: Port,
|
port: Port,
|
||||||
settings: MonitorSettings
|
settings: PluggableMonitorSettings
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!this.manager.isStarted(board, port)) {
|
if (!this.manager.isStarted(board, port)) {
|
||||||
// Monitor is not running, no need to change settings
|
// Monitor is not running, no need to change settings
|
||||||
@ -79,7 +79,7 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
* @param port port monitored
|
* @param port port monitored
|
||||||
* @returns a map of MonitorSetting
|
* @returns a map of MonitorSetting
|
||||||
*/
|
*/
|
||||||
getCurrentSettings(board: Board, port: Port): MonitorSettings {
|
getCurrentSettings(board: Board, port: Port): PluggableMonitorSettings {
|
||||||
return this.manager.currentMonitorSettings(board, port);
|
return this.manager.currentMonitorSettings(board, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|||||||
import { Board, Port, Status } from '../common/protocol';
|
import { Board, Port, Status } from '../common/protocol';
|
||||||
import { CoreClientAware } from './core-client-provider';
|
import { CoreClientAware } from './core-client-provider';
|
||||||
import { MonitorService } from './monitor-service';
|
import { MonitorService } from './monitor-service';
|
||||||
import { MonitorSettings } from './monitor-settings/monitor-settings-provider';
|
import { PluggableMonitorSettings } from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
type MonitorID = string;
|
type MonitorID = string;
|
||||||
|
|
||||||
@ -145,7 +145,11 @@ export class MonitorManager extends CoreClientAware {
|
|||||||
* @param port port to monitor
|
* @param port port to monitor
|
||||||
* @param settings monitor settings to change
|
* @param settings monitor settings to change
|
||||||
*/
|
*/
|
||||||
changeMonitorSettings(board: Board, port: Port, settings: MonitorSettings) {
|
changeMonitorSettings(
|
||||||
|
board: Board,
|
||||||
|
port: Port,
|
||||||
|
settings: PluggableMonitorSettings
|
||||||
|
) {
|
||||||
const monitorID = this.monitorID(board, port);
|
const monitorID = this.monitorID(board, port);
|
||||||
let monitor = this.monitorServices.get(monitorID);
|
let monitor = this.monitorServices.get(monitorID);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
@ -161,7 +165,7 @@ export class MonitorManager extends CoreClientAware {
|
|||||||
* @param port port monitored
|
* @param port port monitored
|
||||||
* @returns map of current monitor settings
|
* @returns map of current monitor settings
|
||||||
*/
|
*/
|
||||||
currentMonitorSettings(board: Board, port: Port): MonitorSettings {
|
currentMonitorSettings(board: Board, port: Port): PluggableMonitorSettings {
|
||||||
const monitorID = this.monitorID(board, port);
|
const monitorID = this.monitorID(board, port);
|
||||||
const monitor = this.monitorServices.get(monitorID);
|
const monitor = this.monitorServices.get(monitorID);
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
|
@ -15,7 +15,7 @@ import { WebSocketProvider } from './web-socket/web-socket-provider';
|
|||||||
import { Port as gRPCPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
|
import { Port as gRPCPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
|
||||||
import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
|
import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
|
||||||
import {
|
import {
|
||||||
MonitorSettings,
|
PluggableMonitorSettings,
|
||||||
MonitorSettingsProvider,
|
MonitorSettingsProvider,
|
||||||
} from './monitor-settings/monitor-settings-provider';
|
} from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
|
|
||||||
// Settings used by the currently running pluggable monitor.
|
// Settings used by the currently running pluggable monitor.
|
||||||
// They can be freely modified while running.
|
// They can be freely modified while running.
|
||||||
protected settings: MonitorSettings;
|
protected settings: PluggableMonitorSettings;
|
||||||
|
|
||||||
// List of messages received from the running pluggable monitor.
|
// List of messages received from the running pluggable monitor.
|
||||||
// These are flushed from time to time to the frontend.
|
// These are flushed from time to time to the frontend.
|
||||||
@ -279,7 +279,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
*
|
*
|
||||||
* @returns map of current monitor settings
|
* @returns map of current monitor settings
|
||||||
*/
|
*/
|
||||||
currentSettings(): MonitorSettings {
|
currentSettings(): PluggableMonitorSettings {
|
||||||
return this.settings;
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
private async portMonitorSettings(
|
private async portMonitorSettings(
|
||||||
protocol: string,
|
protocol: string,
|
||||||
fqbn: string
|
fqbn: string
|
||||||
): Promise<MonitorSettings> {
|
): Promise<PluggableMonitorSettings> {
|
||||||
await this.coreClientProvider.initialized;
|
await this.coreClientProvider.initialized;
|
||||||
const coreClient = await this.coreClient();
|
const coreClient = await this.coreClient();
|
||||||
const { client, instance } = coreClient;
|
const { client, instance } = coreClient;
|
||||||
@ -314,7 +314,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const settings: MonitorSettings = {};
|
const settings: PluggableMonitorSettings = {};
|
||||||
for (const iterator of res.getSettingsList()) {
|
for (const iterator of res.getSettingsList()) {
|
||||||
settings[iterator.getSettingId()] = {
|
settings[iterator.getSettingId()] = {
|
||||||
id: iterator.getSettingId(),
|
id: iterator.getSettingId(),
|
||||||
@ -335,7 +335,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
* @param settings map of monitor settings to change
|
* @param settings map of monitor settings to change
|
||||||
* @returns a status to verify settings have been sent.
|
* @returns a status to verify settings have been sent.
|
||||||
*/
|
*/
|
||||||
async changeSettings(settings: MonitorSettings): Promise<Status> {
|
async changeSettings(settings: PluggableMonitorSettings): Promise<Status> {
|
||||||
const config = new MonitorPortConfiguration();
|
const config = new MonitorPortConfiguration();
|
||||||
for (const id in settings) {
|
for (const id in settings) {
|
||||||
const s = new MonitorPortSetting();
|
const s = new MonitorPortSetting();
|
||||||
@ -384,7 +384,9 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
this.send(message.data);
|
this.send(message.data);
|
||||||
break;
|
break;
|
||||||
case Monitor.Command.CHANGE_SETTINGS:
|
case Monitor.Command.CHANGE_SETTINGS:
|
||||||
const settings: MonitorSettings = JSON.parse(message.data);
|
const settings: PluggableMonitorSettings = JSON.parse(
|
||||||
|
message.data
|
||||||
|
);
|
||||||
this.changeSettings(settings);
|
this.changeSettings(settings);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { CoreClientProvider } from '../core-client-provider';
|
import { CoreClientProvider } from '../core-client-provider';
|
||||||
import {
|
import {
|
||||||
MonitorSettings,
|
PluggableMonitorSettings,
|
||||||
MonitorSettingsProvider,
|
MonitorSettingsProvider,
|
||||||
|
MonitorSettings,
|
||||||
} from './monitor-settings-provider';
|
} from './monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
@ -18,7 +19,7 @@ export class MonitorSettingsProviderImpl implements MonitorSettingsProvider {
|
|||||||
init(
|
init(
|
||||||
id: string,
|
id: string,
|
||||||
coreClientProvider: CoreClientProvider
|
coreClientProvider: CoreClientProvider
|
||||||
): Promise<MonitorSettings> {
|
): Promise<PluggableMonitorSettings> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
|
|
||||||
// 1. query the CLI (via coreClientProvider) and return all available settings for the pluggable monitor.
|
// 1. query the CLI (via coreClientProvider) and return all available settings for the pluggable monitor.
|
||||||
@ -33,10 +34,10 @@ export class MonitorSettingsProviderImpl implements MonitorSettingsProvider {
|
|||||||
// and adding those that are missing
|
// and adding those that are missing
|
||||||
// ii. save the `monitorSettingsValues` in the file, using the id as the key
|
// ii. save the `monitorSettingsValues` in the file, using the id as the key
|
||||||
}
|
}
|
||||||
get(): Promise<MonitorSettings> {
|
get(): Promise<PluggableMonitorSettings> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
}
|
}
|
||||||
set(settings: MonitorSettings): Promise<MonitorSettings> {
|
set(settings: PluggableMonitorSettings): Promise<PluggableMonitorSettings> {
|
||||||
throw new Error('Method not implemented.');
|
throw new Error('Method not implemented.');
|
||||||
|
|
||||||
// 1. parse the settings parameter and remove any setting that is not defined in `monitorSettings`
|
// 1. parse the settings parameter and remove any setting that is not defined in `monitorSettings`
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import { MonitorSetting } from '../../common/protocol';
|
import { MonitorModel } from '../../browser/monitor-model';
|
||||||
|
import { PluggableMonitorSetting } from '../../common/protocol';
|
||||||
import { CoreClientProvider } from '../core-client-provider';
|
import { CoreClientProvider } from '../core-client-provider';
|
||||||
|
|
||||||
export type MonitorSettings = Record<string, MonitorSetting>;
|
export type PluggableMonitorSettings = Record<string, PluggableMonitorSetting>;
|
||||||
|
export interface MonitorSettings {
|
||||||
|
pluggableMonitorSettings?: PluggableMonitorSettings;
|
||||||
|
monitorUISettings?: Partial<MonitorModel.State>;
|
||||||
|
}
|
||||||
|
|
||||||
export const MonitorSettingsProvider = Symbol('MonitorSettingsProvider');
|
export const MonitorSettingsProvider = Symbol('MonitorSettingsProvider');
|
||||||
export interface MonitorSettingsProvider {
|
export interface MonitorSettingsProvider {
|
||||||
init(
|
init(
|
||||||
id: string,
|
id: string,
|
||||||
coreClientProvider: CoreClientProvider
|
coreClientProvider: CoreClientProvider
|
||||||
): Promise<MonitorSettings>;
|
): Promise<PluggableMonitorSettings>;
|
||||||
get(): Promise<MonitorSettings>;
|
get(): Promise<PluggableMonitorSettings>;
|
||||||
set(settings: MonitorSettings): Promise<MonitorSettings>;
|
set(settings: PluggableMonitorSettings): Promise<PluggableMonitorSettings>;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user