got it working

This commit is contained in:
Giacomo Cusinato 2025-03-28 23:13:51 +09:00
parent f343c7ffc5
commit a8885945b4
12 changed files with 144 additions and 119 deletions

View File

@ -160,16 +160,6 @@
{
"frontend": "lib/browser/theia/core/browser-menu-module",
"frontendElectron": "lib/electron-browser/theia/core/electron-menu-module"
},
{
"frontend": "lib/browser/theia/core/browser-window-module",
"frontendElectron": "lib/electron-browser/theia/core/electron-window-module"
},
{
"frontendElectron": "lib/electron-browser/electron-arduino-module"
},
{
"electronMain": "lib/electron-main/arduino-electron-main-module"
}
],
"arduino": {

View File

@ -2,7 +2,6 @@ import { ColorContribution } from '@theia/core/lib/browser/color-application-con
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import {
TabBarToolbarContribution,
TabBarToolbarRegistry,
@ -24,7 +23,6 @@ import {
import { MessageService } from '@theia/core/lib/common/message-service';
import { nls } from '@theia/core/lib/common/nls';
import { isHighContrast } from '@theia/core/lib/common/theme';
import { ElectronWindowPreferences } from '@theia/core/lib/electron-browser/window/electron-window-preferences';
import {
inject,
injectable,
@ -62,11 +60,11 @@ export class ArduinoFrontendContribution
@inject(CommandRegistry)
private readonly commandRegistry: CommandRegistry;
@inject(ElectronWindowPreferences)
private readonly electronWindowPreferences: ElectronWindowPreferences;
// @inject(ElectronWindowPreferences)
// private readonly electronWindowPreferences: ElectronWindowPreferences;
@inject(FrontendApplicationStateService)
private readonly appStateService: FrontendApplicationStateService;
// @inject(FrontendApplicationStateService)
// private readonly appStateService: FrontendApplicationStateService;
@postConstruct()
protected init(): void {
@ -82,24 +80,24 @@ export class ArduinoFrontendContribution
}
onStart(): void {
this.electronWindowPreferences.onPreferenceChanged((event) => {
if (event.newValue !== event.oldValue) {
switch (event.preferenceName) {
case 'window.zoomLevel':
if (typeof event.newValue === 'number') {
window.electronTheiaCore.setZoomLevel(event.newValue || 0);
}
break;
}
}
});
this.appStateService.reachedState('ready').then(() =>
this.electronWindowPreferences.ready.then(() => {
const zoomLevel =
this.electronWindowPreferences.get('window.zoomLevel');
window.electronTheiaCore.setZoomLevel(zoomLevel);
})
);
// this.electronWindowPreferences.onPreferenceChanged((event) => {
// if (event.newValue !== event.oldValue) {
// switch (event.preferenceName) {
// case 'window.zoomLevel':
// if (typeof event.newValue === 'number') {
// window.electronTheiaCore.setZoomLevel(event.newValue || 0);
// }
// break;
// }
// }
// });
// this.appStateService.reachedState('ready').then(() =>
// this.electronWindowPreferences.ready.then(() => {
// const zoomLevel =
// this.electronWindowPreferences.get('window.zoomLevel');
// window.electronTheiaCore.setZoomLevel(zoomLevel);
// })
// );
}
registerToolbarItems(registry: TabBarToolbarRegistry): void {

View File

@ -265,17 +265,12 @@ import {
} from './dialogs/user-fields/user-fields-dialog';
import { nls } from '@theia/core/lib/common';
import { IDEUpdaterCommands } from './ide-updater/ide-updater-commands';
import {
IDEUpdater,
IDEUpdaterClient,
IDEUpdaterPath,
} from '../common/protocol/ide-updater';
import { IDEUpdater, IDEUpdaterClient } from '../common/protocol/ide-updater';
import { IDEUpdaterClientImpl } from './ide-updater/ide-updater-client-impl';
import {
IDEUpdaterDialog,
IDEUpdaterDialogProps,
} from './dialogs/ide-updater/ide-updater-dialog';
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
import { MonitorModel } from './monitor-model';
import { MonitorManagerProxyClientImpl } from './monitor-manager-proxy-client-impl';
import { EditorManager as TheiaEditorManager } from '@theia/editor/lib/browser/editor-manager';
@ -295,10 +290,7 @@ import { PreferenceTreeGenerator } from './theia/preferences/preference-tree-gen
import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from '@theia/preferences/lib/browser/util/preference-tree-generator';
import { AboutDialog } from './theia/core/about-dialog';
import { AboutDialog as TheiaAboutDialog } from '@theia/core/lib/browser/about-dialog';
import {
SurveyNotificationService,
SurveyNotificationServicePath,
} from '../common/protocol/survey-service';
import { SurveyNotificationService } from '../common/protocol/survey-service';
import { WindowContribution } from './theia/core/window-contribution';
import { WindowContribution as TheiaWindowContribution } from '@theia/core/lib/browser/window-contribution';
import { CoreErrorHandler } from './contributions/core-error-handler';
@ -394,6 +386,8 @@ import {
VersionWelcomeDialog,
VersionWelcomeDialogProps,
} from './dialogs/version-welcome-dialog';
import { DialogService } from './dialog-service';
import { AppInfo, AppService } from './app-service';
// Hack to fix copy/cut/paste issue after electron version update in Theia.
// https://github.com/eclipse-theia/theia/issues/12487
@ -574,14 +568,15 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
WorkspaceVariableContribution
);
bind(SurveyNotificationService)
.toDynamicValue((context) => {
return ElectronIpcConnectionProvider.createProxy(
context.container,
SurveyNotificationServicePath
);
})
.inSingletonScope();
bind(SurveyNotificationService).toConstantValue(
{} as SurveyNotificationService
);
// return ElectronIpcConnectionProvider.createProxy(
// context.container,
// SurveyNotificationServicePath
// );
// })
// .inSingletonScope();
// Layout and shell customizations.
rebind(TheiaOutlineViewContribution)
@ -1039,16 +1034,16 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
// Frontend binding for the IDE Updater service
bind(IDEUpdaterClientImpl).toSelf().inSingletonScope();
bind(IDEUpdaterClient).toService(IDEUpdaterClientImpl);
bind(IDEUpdater)
.toDynamicValue((context) => {
const client = context.container.get(IDEUpdaterClientImpl);
return ElectronIpcConnectionProvider.createProxy(
context.container,
IDEUpdaterPath,
client
);
})
.inSingletonScope();
bind(IDEUpdater).toConstantValue({} as IDEUpdater);
// .toDynamicValue((context) => {
// const client = context.container.get(IDEUpdaterClientImpl);
// return ElectronIpcConnectionProvider.createProxy(
// context.container,
// IDEUpdaterPath,
// client
// );
// })
// .inSingletonScope();
bind(HostedPluginSupportImpl).toSelf().inSingletonScope();
bind(HostedPluginSupport).toService(HostedPluginSupportImpl);
@ -1113,6 +1108,32 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
);
bindViewsWelcome_TheiaGH14309({ bind, widget: TreeViewWidget });
bind(DialogService).toConstantValue(<DialogService>{});
bind(AppService).toConstantValue(<AppService>{
quit() {
console.log('Quitting application...');
// Implement quit logic here
},
async info() {
return {
name: 'MyApp',
version: '1.0.0',
description: 'An example application',
appVersion: '1.0.0',
cliVersion: '1.0.0',
buildDate: new Date().toISOString(),
} as AppInfo;
},
registerStartupTasksHandler(_) {
console.log('registerStartupTasksHandler', _);
return { dispose: () => {} };
},
scheduleDeletion(_) {
console.log(`Scheduled deletion for sketch}`, _);
// Implement deletion logic
},
});
});
// Align the viewsWelcome rendering with VS Code (https://github.com/eclipse-theia/theia/issues/14309)

View File

@ -15,7 +15,6 @@ import { Installable } from '../../common/protocol/installable';
import { ExecuteWithProgress } from '../../common/protocol/progressible';
import { BoardsListWidgetFrontendContribution } from '../boards/boards-widget-frontend-contribution';
import { LibraryListWidgetFrontendContribution } from '../library/library-widget-frontend-contribution';
import { WindowServiceExt } from '../theia/core/window-service-ext';
import type { ListWidget } from '../widgets/component-list/list-widget';
import { Command, CommandRegistry, Contribution } from './contribution';
@ -53,8 +52,8 @@ const Updatable = { type: 'Updatable' } as const;
@injectable()
export class CheckForUpdates extends Contribution {
@inject(WindowServiceExt)
private readonly windowService: WindowServiceExt;
// @inject(WindowServiceExt)
// private readonly windowService: WindowServiceExt;
@inject(ResponseServiceClient)
private readonly responseService: ResponseServiceClient;
@inject(BoardsService)
@ -72,16 +71,16 @@ export class CheckForUpdates extends Contribution {
});
}
override async onReady(): Promise<void> {
const checkForUpdates = this.preferences['arduino.checkForUpdates'];
if (checkForUpdates) {
this.windowService.isFirstWindow().then((firstWindow) => {
if (firstWindow) {
this.checkForUpdates();
}
});
}
}
// override async onReady(): Promise<void> {
// const checkForUpdates = this.preferences['arduino.checkForUpdates'];
// if (checkForUpdates) {
// this.windowService.isFirstWindow().then((firstWindow) => {
// if (firstWindow) {
// this.checkForUpdates();
// }
// });
// }
// }
private async checkForUpdates(silent = true) {
const [boardsPackages, libraryPackages] = await Promise.all([

View File

@ -7,11 +7,10 @@ import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shel
import { nls } from '@theia/core/lib/common/nls';
import type { MaybePromise } from '@theia/core/lib/common/types';
import { toArray } from '@theia/core/shared/@phosphor/algorithm';
import { inject, injectable } from '@theia/core/shared/inversify';
import { injectable } from '@theia/core/shared/inversify';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { ArduinoMenus } from '../menu/arduino-menus';
import { CurrentSketch } from '../sketches-service-client-impl';
import { WindowServiceExt } from '../theia/core/window-service-ext';
import {
Command,
CommandRegistry,
@ -28,8 +27,8 @@ import { SaveAsSketch } from './save-as-sketch';
*/
@injectable()
export class Close extends SketchContribution {
@inject(WindowServiceExt)
private readonly windowServiceExt: WindowServiceExt;
// @inject(WindowServiceExt)
// private readonly windowServiceExt: WindowServiceExt;
private shell: ApplicationShell | undefined;
@ -59,7 +58,7 @@ export class Close extends SketchContribution {
}
}
}
return this.windowServiceExt.close();
// return this.windowServiceExt.close();
},
});
}

View File

@ -3,13 +3,12 @@ import { nls } from '@theia/core/lib/common/nls';
import { inject, injectable } from '@theia/core/shared/inversify';
import { CoreService, IndexType } from '../../common/protocol';
import { NotificationCenter } from '../notification-center';
import { WindowServiceExt } from '../theia/core/window-service-ext';
import { Command, CommandRegistry, Contribution } from './contribution';
@injectable()
export class UpdateIndexes extends Contribution {
@inject(WindowServiceExt)
private readonly windowService: WindowServiceExt;
// @inject(WindowServiceExt)
// private readonly windowService: WindowServiceExt;
@inject(LocalStorageService)
private readonly localStorage: LocalStorageService;
@inject(CoreService)
@ -53,30 +52,28 @@ export class UpdateIndexes extends Contribution {
return;
}
if (await this.windowService.isFirstWindow()) {
const summary = await this.coreService.indexUpdateSummaryBeforeInit();
if (summary.message) {
this.messageService.error(summary.message);
}
const typesToCheck = IndexType.All.filter((type) => !(type in summary));
if (Object.keys(summary).length) {
console.debug(
`[update-indexes]: Detected an index update summary before the core gRPC client initialization. Updating local storage with ${JSON.stringify(
summary
)}`
);
} else {
console.debug(
'[update-indexes]: No index update summary was available before the core gRPC client initialization. Checking the status of the all the index types.'
);
}
await Promise.allSettled([
...Object.entries(summary).map(([type, updatedAt]) =>
this.setLastUpdateDateTime(type as IndexType, updatedAt)
),
this.updateIndexes(typesToCheck),
]);
const summary = await this.coreService.indexUpdateSummaryBeforeInit();
if (summary.message) {
this.messageService.error(summary.message);
}
const typesToCheck = IndexType.All.filter((type) => !(type in summary));
if (Object.keys(summary).length) {
console.debug(
`[update-indexes]: Detected an index update summary before the core gRPC client initialization. Updating local storage with ${JSON.stringify(
summary
)}`
);
} else {
console.debug(
'[update-indexes]: No index update summary was available before the core gRPC client initialization. Checking the status of the all the index types.'
);
}
await Promise.allSettled([
...Object.entries(summary).map(([type, updatedAt]) =>
this.setLastUpdateDateTime(type as IndexType, updatedAt)
),
this.updateIndexes(typesToCheck),
]);
}
private async updateIndexes(

View File

@ -0,0 +1,20 @@
import { DefaultWindowService as TheiaDefaultWindowService } from '@theia/core/lib/browser/window/default-window-service';
import { injectable } from '@theia/core/shared/inversify';
import { WindowServiceExt } from './window-service-ext';
@injectable()
export class DefaultWindowService
extends TheiaDefaultWindowService
implements WindowServiceExt
{
close(): void {
throw new Error('Method not implemented.');
}
/**
* The default implementation always resolves to `true`.
* IDE2 does not use it. It's currently an electron-only app.
*/
async isFirstWindow(): Promise<boolean> {
return true;
}
}

View File

@ -22,7 +22,6 @@ import { MonacoThemeRegistry as TheiaMonacoThemeRegistry } from '@theia/monaco/l
import type { ThemeMix } from '@theia/monaco/lib/browser/textmate/monaco-theme-types';
import { HostedPluginSupport } from '../../hosted/hosted-plugin-support';
import { ArduinoThemes, compatibleBuiltInTheme } from '../core/theming';
import { WindowServiceExt } from '../core/window-service-ext';
type MonacoThemeRegistrationSource =
/**
@ -156,8 +155,8 @@ export class CleanupObsoleteThemes implements FrontendApplicationContribution {
private readonly themeService: ThemeService;
@inject(MessageService)
private readonly messageService: MessageService;
@inject(WindowServiceExt)
private readonly windowService: WindowServiceExt;
// @inject(WindowServiceExt)
// private readonly windowService: WindowServiceExt;
onStart(): void {
this.hostedPlugin.didStart.then(() => this.cleanupObsoleteThemes());
@ -172,7 +171,7 @@ export class CleanupObsoleteThemes implements FrontendApplicationContribution {
if (!obsoleteThemeIds.length) {
return;
}
const firstWindow = await this.windowService.isFirstWindow();
const firstWindow = true; // await this.windowService.isFirstWindow();
if (firstWindow) {
await this.removeObsoleteThemesFromIndexedDB(obsoleteThemeIds);
this.unregisterObsoleteThemes(obsoleteThemeIds);

View File

@ -19,14 +19,13 @@ import {
hasStartupTasks,
StartupTask,
} from '../../../electron-common/startup-task';
import { WindowServiceExt } from '../core/window-service-ext';
@injectable()
export class WorkspaceService extends TheiaWorkspaceService {
@inject(SketchesService)
private readonly sketchesService: SketchesService;
@inject(WindowServiceExt)
private readonly windowServiceExt: WindowServiceExt;
// @inject(WindowServiceExt)
// private readonly windowServiceExt: WindowServiceExt;
@inject(ContributionProvider)
@named(StartupTaskProvider)
private readonly providers: ContributionProvider<StartupTaskProvider>;
@ -104,7 +103,8 @@ export class WorkspaceService extends TheiaWorkspaceService {
protected override reloadWindow(options?: WorkspaceInput): void {
const tasks = this.tasks(options);
this.setURLFragment(this._workspace?.resource.path.toString() || '');
this.windowServiceExt.reload({ tasks });
console.log(tasks);
// this.windowServiceExt.reload({ tasks });
}
protected override openNewWindow(

View File

@ -1,8 +1,10 @@
export const MainMenuManager = Symbol('MainMenuManager');
export interface MainMenuManager {
// export const MainMenuManager = Symbol('MainMenuManager');
export class MainMenuManager {
/**
* Call this method if you have changed the content of the main menu (updated a toggle flag, removed/added new groups or menu items)
* and you want to re-render it from scratch. Works for electron too.
*/
update(): void;
update() {
console.warn('MainMenuManager.update() is not implemented');
}
}

View File

@ -27,7 +27,7 @@
"scripts": {
"build:dev": "theia build --config webpack.config.js --mode development",
"prepare": "theia build --mode development",
"start": "theia start --plugins=local-dir:../plugins",
"start": "theia start",
"watch": "theia build --watch --mode development"
},
"theia": {