Skip to content

Commit 4a0e0cf

Browse files
avoid multiple notifications in different windows
1 parent ae828a5 commit 4a0e0cf

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+13
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ import { PreferenceTreeGenerator } from './theia/preferences/preference-tree-gen
292292
import { PreferenceTreeGenerator as TheiaPreferenceTreeGenerator } from '@theia/preferences/lib/browser/util/preference-tree-generator';
293293
import { AboutDialog } from './theia/core/about-dialog';
294294
import { AboutDialog as TheiaAboutDialog } from '@theia/core/lib/browser/about-dialog';
295+
import {
296+
SurveyNotificationService,
297+
SurveyNotificationServicePath,
298+
} from '../common/protocol/survey-service';
295299

296300
MonacoThemingService.register({
297301
id: 'arduino-theme',
@@ -480,6 +484,15 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
480484
bind(SurveyNotification).toSelf().inSingletonScope();
481485
bind(FrontendApplicationContribution).toService(SurveyNotification);
482486

487+
bind(SurveyNotificationService)
488+
.toDynamicValue((context) => {
489+
return ElectronIpcConnectionProvider.createProxy(
490+
context.container,
491+
SurveyNotificationServicePath
492+
);
493+
})
494+
.inSingletonScope();
495+
483496
// Layout and shell customizations.
484497
rebind(TheiaOutlineViewContribution)
485498
.to(OutlineViewContribution)

Diff for: arduino-ide-extension/src/browser/contributions/survey-notification.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { LocalStorageService } from '@theia/core/lib/browser';
55
import { nls } from '@theia/core/lib/common';
66
import { WindowService } from '@theia/core/lib/browser/window/window-service';
77
import { ArduinoPreferences } from '../arduino-preferences';
8+
import { SurveyNotificationService } from '../../common/protocol/survey-service';
89

910
const SURVEY_MESSAGE = nls.localize(
1011
'arduino/survey/surveyMessage',
@@ -36,9 +37,15 @@ export class SurveyNotification implements FrontendApplicationContribution {
3637
@inject(ArduinoPreferences)
3738
private readonly arduinoPreferences: ArduinoPreferences;
3839

40+
@inject(SurveyNotificationService)
41+
private readonly surveyNotificationService: SurveyNotificationService;
42+
3943
onStart(): void {
4044
this.arduinoPreferences.ready.then(async () => {
41-
if (this.arduinoPreferences.get('arduino.survey.notification')) {
45+
if (
46+
(await this.surveyNotificationService.isFirstInstance()) &&
47+
this.arduinoPreferences.get('arduino.survey.notification')
48+
) {
4249
const surveyAnswered = await this.localStorageService.getData(
4350
this.surveyKey(surveyId)
4451
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const SurveyNotificationServicePath =
2+
'/services/survey-notification-service';
3+
export const SurveyNotificationService = Symbol('SurveyNotificationService');
4+
5+
export interface SurveyNotificationService {
6+
isFirstInstance(): Promise<boolean>;
7+
}

Diff for: arduino-ide-extension/src/electron-main/arduino-electron-main-module.ts

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import {
2121
import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
2222
import { TheiaElectronWindow } from './theia/theia-electron-window';
2323
import { TheiaElectronWindow as DefaultTheiaElectronWindow } from '@theia/core/lib/electron-main/theia-electron-window';
24+
import { SurveyNotificationServiceImpl } from '../node/survey-service-impl';
25+
import {
26+
SurveyNotificationService,
27+
SurveyNotificationServicePath,
28+
} from '../common/protocol/survey-service';
2429

2530
export default new ContainerModule((bind, unbind, isBound, rebind) => {
2631
bind(ElectronMainApplication).toSelf().inSingletonScope();
@@ -61,4 +66,21 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
6166

6267
bind(TheiaElectronWindow).toSelf();
6368
rebind(DefaultTheiaElectronWindow).toService(TheiaElectronWindow);
69+
70+
// Survey notification bindings
71+
bind(SurveyNotificationServiceImpl).toSelf().inSingletonScope();
72+
bind(SurveyNotificationService).toService(SurveyNotificationServiceImpl);
73+
bind(ElectronMainApplicationContribution).toService(
74+
SurveyNotificationService
75+
);
76+
bind(ElectronConnectionHandler)
77+
.toDynamicValue(
78+
(context) =>
79+
new JsonRpcConnectionHandler(SurveyNotificationServicePath, () =>
80+
context.container.get<SurveyNotificationService>(
81+
SurveyNotificationService
82+
)
83+
)
84+
)
85+
.inSingletonScope();
6486
});
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { injectable } from '@theia/core/shared/inversify';
2+
import { SurveyNotificationService } from '../common/protocol/survey-service';
3+
4+
@injectable()
5+
export class SurveyNotificationServiceImpl
6+
implements SurveyNotificationService
7+
{
8+
private isSurveyShown = false;
9+
async isFirstInstance(): Promise<boolean> {
10+
if (this.isSurveyShown) {
11+
return false;
12+
}
13+
return (this.isSurveyShown = true);
14+
}
15+
}

0 commit comments

Comments
 (0)