Skip to content

Commit f6eef5f

Browse files
author
Akos Kitta
committed
fix: extract push/pull node to their functions
Signed-off-by: Akos Kitta <[email protected]>
1 parent 75f5b83 commit f6eef5f

File tree

1 file changed

+56
-48
lines changed

1 file changed

+56
-48
lines changed

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

+56-48
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,33 @@ export class CloudSketchbookTree extends SketchbookTree {
142142
node,
143143
'pull',
144144
async (node) => {
145-
const commandsCopy = node.commands;
146-
node.commands = [];
145+
await this.pullNode(node);
146+
},
147+
noProgress
148+
);
149+
}
147150

148-
const localUri = await this.fileService.toUnderlyingResource(
149-
LocalCacheUri.root.resolve(node.remoteUri.path)
150-
);
151-
await this.sync(node.remoteUri, localUri);
151+
private async pullNode(node: CloudSketchbookTree.CloudSketchDirNode) {
152+
const commandsCopy = node.commands;
153+
node.commands = [];
152154

153-
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
155+
const localUri = await this.fileService.toUnderlyingResource(
156+
LocalCacheUri.root.resolve(node.remoteUri.path)
157+
);
158+
await this.sync(node.remoteUri, localUri);
154159

155-
node.commands = commandsCopy;
156-
this.messageService.info(
157-
nls.localize(
158-
'arduino/cloud/donePulling',
159-
"Done pulling '{0}'.",
160-
node.fileStat.name
161-
),
162-
{
163-
timeout: MESSAGE_TIMEOUT,
164-
}
165-
);
166-
},
167-
noProgress
160+
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
161+
162+
node.commands = commandsCopy;
163+
this.messageService.info(
164+
nls.localize(
165+
'arduino/cloud/donePulling',
166+
"Done pulling '{0}'.",
167+
node.fileStat.name
168+
),
169+
{
170+
timeout: MESSAGE_TIMEOUT,
171+
}
168172
);
169173
}
170174

@@ -210,37 +214,41 @@ export class CloudSketchbookTree extends SketchbookTree {
210214
node,
211215
'push',
212216
async (node) => {
213-
if (!CloudSketchbookTree.CloudSketchTreeNode.isSynced(node)) {
214-
throw new Error(
215-
nls.localize(
216-
'arduino/cloud/pullFirst',
217-
'You have to pull first to be able to push to the Cloud.'
218-
)
219-
);
220-
}
221-
const commandsCopy = node.commands;
222-
node.commands = [];
217+
await this.pushNode(node);
218+
},
219+
noProgress
220+
);
221+
}
223222

224-
const localUri = await this.fileService.toUnderlyingResource(
225-
LocalCacheUri.root.resolve(node.remoteUri.path)
226-
);
227-
await this.sync(localUri, node.remoteUri);
223+
private async pushNode(node: CloudSketchbookTree.CloudSketchDirNode) {
224+
if (!CloudSketchbookTree.CloudSketchTreeNode.isSynced(node)) {
225+
throw new Error(
226+
nls.localize(
227+
'arduino/cloud/pullFirst',
228+
'You have to pull first to be able to push to the Cloud.'
229+
)
230+
);
231+
}
232+
const commandsCopy = node.commands;
233+
node.commands = [];
228234

229-
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
235+
const localUri = await this.fileService.toUnderlyingResource(
236+
LocalCacheUri.root.resolve(node.remoteUri.path)
237+
);
238+
await this.sync(localUri, node.remoteUri);
230239

231-
node.commands = commandsCopy;
232-
this.messageService.info(
233-
nls.localize(
234-
'arduino/cloud/donePushing',
235-
"Done pushing '{0}'.",
236-
node.fileStat.name
237-
),
238-
{
239-
timeout: MESSAGE_TIMEOUT,
240-
}
241-
);
242-
},
243-
noProgress
240+
this.createApi.sketchCache.purgeByPath(node.remoteUri.path.toString());
241+
242+
node.commands = commandsCopy;
243+
this.messageService.info(
244+
nls.localize(
245+
'arduino/cloud/donePushing',
246+
"Done pushing '{0}'.",
247+
node.fileStat.name
248+
),
249+
{
250+
timeout: MESSAGE_TIMEOUT,
251+
}
244252
);
245253
}
246254

0 commit comments

Comments
 (0)