diff --git a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts index 82df67227..7e05871f2 100644 --- a/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts +++ b/arduino-ide-extension/src/electron-main/theia/electron-main-application.ts @@ -23,9 +23,40 @@ export class ElectronMainApplication extends TheiaElectronMainApplication { // See: https://github.com/electron-userland/electron-builder/issues/2468 // Regression in Theia: https://github.com/eclipse-theia/theia/issues/8701 app.on('ready', () => app.setName(config.applicationName)); + + // Add file associations to the app + this.attachFileAssociations(); + return super.start(config); } + attachFileAssociations() { + + // OSX: register open-file event + if (process.platform === 'darwin') { + app.on('open-file', (event, uri) => { + event.preventDefault(); + // TODO: check if the URI is a .ino file + // should I call openSketchFiles(uri) ? + }); + } + + // WIN: read file(s) uri from executable args + if (process.platform === 'win32') { + if (app.isPackaged) { + // workaround for missing executable argument when app is packaged + process.argv.unshift('packaged'); + } + // parameters is an array containing any files/folders that your OS will pass to your application + const uri = process.argv.slice(2) || null; + if (uri) { + // TODO: filter out only the first .ino file in the array + // should I call openSketchFiles(uri) ? + } + } + + } + /** * Use this rather than creating `BrowserWindow` instances from scratch, since some security parameters need to be set, this method will do it. * diff --git a/electron/build/template-package.json b/electron/build/template-package.json index d4eac56df..e53e2e24d 100644 --- a/electron/build/template-package.json +++ b/electron/build/template-package.json @@ -53,6 +53,12 @@ "directories": { "buildResources": "resources" }, + "fileAssociations": [ + { + "ext": ["ino"], + "role": "Editor" + } + ], "files": [ "src-gen", "lib",