Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a02db45

Browse files
author
Akos Kitta
committed
feat: update editor toolbar on cloud status change
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 23906d9 commit a02db45

File tree

3 files changed

+99
-56
lines changed

3 files changed

+99
-56
lines changed

‎arduino-ide-extension/src/browser/contributions/cloud-contribution.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export abstract class CloudSketchContribution extends SketchContribution {
9393
);
9494
}
9595
try {
96-
await treeModel.sketchbookTree().pull({ node });
96+
await treeModel.sketchbookTree().pull({ node },true);
9797
return node;
9898
} catch (err) {
9999
if (isNotFound(err)) {

‎arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-contributions.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Disposable,
1515
DisposableCollection,
1616
} from '@theia/core/lib/common/disposable';
17+
import { Emitter, Event } from '@theia/core/lib/common/event';
1718
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
1819
import { nls } from '@theia/core/lib/common/nls';
1920
import { Widget } from '@theia/core/shared/@phosphor/widgets';
@@ -60,11 +61,29 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
6061
@inject(ApplicationConnectionStatusContribution)
6162
private readonly connectionStatus: ApplicationConnectionStatusContribution;
6263

64+
private readonly onDidChangeToolbarEmitter = new Emitter<void>();
6365
private readonly toDisposeBeforeNewContextMenu = new DisposableCollection();
66+
private readonly toDisposeOnStop = new DisposableCollection(
67+
this.onDidChangeToolbarEmitter,
68+
this.toDisposeBeforeNewContextMenu
69+
);
6470
private shell: ApplicationShell | undefined;
6571

6672
override onStart(app: FrontendApplication): void {
6773
this.shell = app.shell;
74+
this.toDisposeOnStop.pushAll([
75+
this.connectionStatus.onOfflineStatusDidChange((offlineStatus) => {
76+
if (!offlineStatus || offlineStatus === 'internet') {
77+
this.fireToolbarChange();
78+
}
79+
}),
80+
this.createFeatures.onDidChangeSession(() => this.fireToolbarChange()),
81+
this.createFeatures.onDidChangeEnabled(() => this.fireToolbarChange()),
82+
]);
83+
}
84+
85+
onStop(): void {
86+
this.toDisposeOnStop.dispose();
6887
}
6988

7089
override registerMenus(menus: MenuModelRegistry): void {
@@ -81,12 +100,14 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
81100
command: CloudSketchbookCommands.PULL_SKETCH__TOOLBAR.id,
82101
tooltip: CloudSketchbookCommands.PULL_SKETCH__TOOLBAR.label,
83102
priority: -2,
103+
onDidChange: this.onDidChangeToolbar,
84104
});
85105
registry.registerItem({
86106
id: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.id,
87107
command: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.id,
88108
tooltip: CloudSketchbookCommands.PUSH_SKETCH__TOOLBAR.label,
89109
priority: -1,
110+
onDidChange: this.onDidChangeToolbar,
90111
});
91112
}
92113

@@ -353,4 +374,12 @@ export class CloudSketchbookContribution extends CloudSketchContribution {
353374
}
354375
return this.commandRegistry.executeCommand(id, arg);
355376
}
377+
378+
private fireToolbarChange(): void {
379+
this.onDidChangeToolbarEmitter.fire();
380+
}
381+
382+
private get onDidChangeToolbar(): Event<void> {
383+
return this.onDidChangeToolbarEmitter.event;
384+
}
356385
}

‎arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-tree.ts‎

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { nls } from '@theia/core/lib/common';
3434
import { ApplicationConnectionStatusContribution } from '../../theia/core/connection-status-service';
3535
import { ExecuteWithProgress } from '../../../common/protocol/progressible';
3636
import {
37-
synchronizingSketchbook,
3837
pullingSketch,
3938
pushingSketch,
4039
} from '../../contributions/cloud-contribution';
@@ -101,7 +100,7 @@ export class CloudSketchbookTree extends SketchbookTree {
101100
}
102101

103102
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
104-
async pull(arg: any): Promise<void> {
103+
async pull(arg: any,noProgress=false): Promise<void> {
105104
const {
106105
// model,
107106
node,
@@ -135,32 +134,40 @@ export class CloudSketchbookTree extends SketchbookTree {
135134
return;
136135
}
137136
}
138-
return this.runWithState(node, 'pulling', async (node) => {
139-
const commandsCopy = node.commands;
140-
node.commands = [];
137+
return this.runWithState(
138+
node,
139+
'pulling',
140+
async (node) => {
141+
const commandsCopy = node.commands;
142+
node.commands = [];
141143

142-
const localUri = await this.fileService.toUnderlyingResource(
143-
LocalCacheUri.root.resolve(node.remoteUri.path)
144-
);
145-
await this.sync(node.remoteUri, localUri);
144+
const localUri = await this.fileService.toUnderlyingResource(
145+
LocalCacheUri.root.resolve(node.remoteUri.path)
146+
);
147+
await this.sync(node.remoteUri, localUri);
146148

147-
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
149+
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
148150

149-
node.commands = commandsCopy;
150-
this.messageService.info(
151-
nls.localize(
152-
'arduino/cloud/donePulling',
153-
"Done pulling '{0}'.",
154-
node.fileStat.name
155-
),
156-
{
157-
timeout: MESSAGE_TIMEOUT,
158-
}
159-
);
160-
});
151+
node.commands = commandsCopy;
152+
this.messageService.info(
153+
nls.localize(
154+
'arduino/cloud/donePulling',
155+
"Done pulling '{0}'.",
156+
node.fileStat.name
157+
),
158+
{
159+
timeout: MESSAGE_TIMEOUT,
160+
}
161+
);
162+
},
163+
noProgress
164+
);
161165
}
162166

163-
async push(node: CloudSketchbookTree.CloudSketchDirNode): Promise<void> {
167+
async push(
168+
node: CloudSketchbookTree.CloudSketchDirNode,
169+
noProgress = false
170+
): Promise<void> {
164171
if (!CloudSketchbookTree.CloudSketchTreeNode.isSynced(node)) {
165172
throw new Error(
166173
nls.localize(
@@ -195,37 +202,42 @@ export class CloudSketchbookTree extends SketchbookTree {
195202
return;
196203
}
197204
}
198-
return this.runWithState(node, 'pushing', async (node) => {
199-
if (!CloudSketchbookTree.CloudSketchTreeNode.isSynced(node)) {
200-
throw new Error(
201-
nls.localize(
202-
'arduino/cloud/pullFirst',
203-
'You have to pull first to be able to push to the Cloud.'
204-
)
205-
);
206-
}
207-
const commandsCopy = node.commands;
208-
node.commands = [];
205+
return this.runWithState(
206+
node,
207+
'pushing',
208+
async (node) => {
209+
if (!CloudSketchbookTree.CloudSketchTreeNode.isSynced(node)) {
210+
throw new Error(
211+
nls.localize(
212+
'arduino/cloud/pullFirst',
213+
'You have to pull first to be able to push to the Cloud.'
214+
)
215+
);
216+
}
217+
const commandsCopy = node.commands;
218+
node.commands = [];
209219

210-
const localUri = await this.fileService.toUnderlyingResource(
211-
LocalCacheUri.root.resolve(node.remoteUri.path)
212-
);
213-
await this.sync(localUri, node.remoteUri);
220+
const localUri = await this.fileService.toUnderlyingResource(
221+
LocalCacheUri.root.resolve(node.remoteUri.path)
222+
);
223+
await this.sync(localUri, node.remoteUri);
214224

215-
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
225+
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
216226

217-
node.commands = commandsCopy;
218-
this.messageService.info(
219-
nls.localize(
220-
'arduino/cloud/donePushing',
221-
"Done pushing '{0}'.",
222-
node.fileStat.name
223-
),
224-
{
225-
timeout: MESSAGE_TIMEOUT,
226-
}
227-
);
228-
});
227+
node.commands = commandsCopy;
228+
this.messageService.info(
229+
nls.localize(
230+
'arduino/cloud/donePushing',
231+
"Done pushing '{0}'.",
232+
node.fileStat.name
233+
),
234+
{
235+
timeout: MESSAGE_TIMEOUT,
236+
}
237+
);
238+
},
239+
noProgress
240+
);
229241
}
230242

231243
private async recursiveURIs(uri: URI): Promise<URI[]> {
@@ -328,8 +340,12 @@ export class CloudSketchbookTree extends SketchbookTree {
328340
private async runWithState<T>(
329341
node: CloudSketchbookTree.CloudSketchDirNode & Partial<DecoratedTreeNode>,
330342
state: CloudSketchbookTree.CloudSketchDirNode.State,
331-
task: (node: CloudSketchbookTree.CloudSketchDirNode) => MaybePromise<T>
343+
task: (node: CloudSketchbookTree.CloudSketchDirNode) => MaybePromise<T>,
344+
noProgress = false
332345
): Promise<T> {
346+
if (noProgress) {
347+
return task(node);
348+
}
333349
const name = node.uri.path.name;
334350
return ExecuteWithProgress.withProgress(
335351
this.taskMessage(state, name),
@@ -346,8 +362,6 @@ export class CloudSketchbookTree extends SketchbookTree {
346362
input: string
347363
): string {
348364
switch (state) {
349-
case 'syncing':
350-
return synchronizingSketchbook;
351365
case 'pulling':
352366
return pullingSketch(input);
353367
case 'pushing':
@@ -678,6 +692,6 @@ export namespace CloudSketchbookTree {
678692
return SketchbookTree.SketchDirNode.is(node);
679693
}
680694

681-
export type State = 'syncing'|'pulling' | 'pushing';
695+
export type State = 'pulling' | 'pushing';
682696
}
683697
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /