MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / reloadDevices

Method reloadDevices

tools/mcsim/main.js:271–319  ·  view source on GitHub ↗
(application, flag)

Source from the content-addressed store, hash-verified

269 system.deleteFile(this.localLibraryPath);
270 }
271 reloadDevices(application, flag) {
272 let devices = this.devices = [];
273 let index = this.deviceIndex;
274
275 this.selectDevice(application, -1);
276
277 application.purge();
278 let iterator = new system.DirectoryIterator(this.devicesPath);
279 let info = iterator.next();
280 while (info) {
281 if (!info.directory) {
282 if (info.name.endsWith(".js")) {
283 try {
284 let compartment = new Compartment(this.compartmentOptions);
285 let device = compartment.importNow(info.path).default;
286 if (device && (("DeviceTemplate" in device) || ("DeviceTemplates" in device))) {
287 device.compartment = compartment;
288 device.default = device;
289 if (!device.sortingTitle)
290 device.sortingTitle = device.title;
291 devices.push(device);
292 let name = device.applicationName;
293 if (name) {
294 if (system.platform == "win") {
295 name = name.replaceAll("/", "\\\\");
296 name += "\\\\mc.dll";
297 }
298 else
299 name += "/mc.so";
300 device.applicationFilter = new RegExp(name);
301 }
302 }
303 }
304 catch (e) {
305 }
306 }
307 }
308 info = iterator.next();
309 }
310 let length = devices.length;
311 if (length > 0) {
312 devices.sort((a, b) => a.sortingTitle.localeCompare(b.sortingTitle));
313 if (index < 0)
314 index = 0;
315 else if (index >= length)
316 index = length - 1;
317 this.selectDevice(application, index);
318 }
319 }
320 selectDevice(application, index) {
321 application.distribute("onDeviceUnselected");
322

Callers 3

onAppearanceChangedMethod · 0.95
onColorsChangedMethod · 0.95
doReloadSimulatorsMethod · 0.95

Calls 5

selectDeviceMethod · 0.95
nextMethod · 0.95
importNowMethod · 0.80
purgeMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected