Skip to content

Enable opening the IDE from finder/explorer #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 23, 2022
Merged

Conversation

msujew
Copy link
Contributor

@msujew msujew commented Feb 14, 2022

Closes #72
Closes #370
Closes #293

I needed a workaround to make MacOS wait for the open-file event, which is accomplished using the openFilePromise. However, I can't test this on Mac currently, so please get back to me if does not work correctly on Mac :)

@msujew msujew added topic: code Related to content of the project itself os: windows Specific to Windows operating system os: macos Specific to macOS operating system labels Feb 14, 2022
@kittaakos
Copy link
Contributor

@msujew, I am happy to try it out. Can you please rebase? Currently, the app does not start. Thank you! See #836

/Applications/Arduino\ IDE.app/Contents/MacOS/Arduino\ IDE ; exit;
Starting backend process. PID: 10570
Failed to start the backend application:
Error: Cannot find module 'electron'
Require stack:
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/core-client-provider.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/library-service-server-impl.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/arduino-ide-backend-module.js
- /Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/server.js
- /Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:934:15)
    at Module._load (node:internal/modules/cjs/loader:779:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
    at Module.require (node:internal/modules/cjs/loader:1006:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js:14:20)
    at Module._compile (node:internal/modules/cjs/loader:1110:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1140:10)
    at Module.load (node:internal/modules/cjs/loader:982:32)
    at Module._load (node:internal/modules/cjs/loader:823:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/core-client-provider.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/library-service-server-impl.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/arduino-ide-backend-module.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/server.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/main.js'
  ]
}
/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/@theia/core/lib/node/main.js:22
    throw reason;
    ^

Error: Cannot find module 'electron'
Require stack:
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/core-client-provider.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/library-service-server-impl.js
- /Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/arduino-ide-backend-module.js
- /Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/server.js
- /Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/main.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:934:15)
    at Module._load (node:internal/modules/cjs/loader:779:27)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13331)
    at Module.require (node:internal/modules/cjs/loader:1006:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js:14:20)
    at Module._compile (node:internal/modules/cjs/loader:1110:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1140:10)
    at Module.load (node:internal/modules/cjs/loader:982:32)
    at Module._load (node:internal/modules/cjs/loader:823:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/grpc-client-provider.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/core-client-provider.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/library-service-server-impl.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/node_modules/arduino-ide-extension/lib/node/arduino-ide-backend-module.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/server.js',
    '/Applications/Arduino IDE.app/Contents/Resources/app/src-gen/backend/main.js'
  ]
}

@msujew msujew force-pushed the msujew/open-from-finder branch 2 times, most recently from 7db4792 to 2ede39e Compare February 17, 2022 12:32
Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, it does "Enable opening the IDE from finder/explorer" for me. However, it does not provide the full functionality that I, and I'm certain the users as well expect. So I don't think it can be considered as a fix for #370

  1. Close any Arduino IDE windows that are already open.
  2. Run the following command from PowerShell:
    & ".\Arduino IDE" "c:\Users\per\Documents\Arduino\SketchA\SketchA.ino"
    
    🙂 The IDE starts up with the "SketchA" sketch open.
  3. Run the following command from PowerShell:
    & ".\Arduino IDE" "c:\Users\per\Documents\Arduino\SketchB\SketchB.ino"
    
    🙁 The existing Arduino IDE window with the "SketchA" sketch open is switched to.

My expected result from step (3) is that a new IDE window will open with the "SketchB" sketch open.

This expectation is how Arduino IDE 1.x works.


On Linux, running the equivalent of step 2 doesn't open "SketchA". It just starts the IDE with the most recent sketch, the same as running ./arduino-ide.

Arduino IDE 1.x works the same on Linux as on Windows, in that you can pass sketch paths as an argument and open as many sketches in IDE windows as you like this way.

@msujew msujew force-pushed the msujew/open-from-finder branch from 2ede39e to 38585e8 Compare February 17, 2022 15:09
@msujew
Copy link
Contributor Author

msujew commented Feb 22, 2022

@per1234 @kittaakos Thanks for the comments. I pushed some changes already a few days ago that should've addressed them.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @msujew. Unfortunately, when using the build from 38585e8 (2.0.0-rc4-snapshot.7b5c9d7-snapshot-7b5c9d7), it is not working at all for me.

Set a known baseline state for the IDE

  1. Start the Arduino IDE directly.
  2. Select File > Open... from the Arduino IDE menus.
  3. Open c:\Users\per\Documents\Arduino\SketchA\SketchA.ino
  4. Close all IDE windows other than the one that has "SketchA" open.
  5. Close the IDE window with "SketchA" open.

We now know that when the IDE is started without any file association, it should have "SketchA" open.

Test file association

  1. Run the following command from PowerShell:
    & ".\Arduino IDE" "c:\Users\per\Documents\Arduino\SketchB\SketchB.ino"
    
    🙁 The Arduino IDE starts with the "SketchA" sketch open rather than the expected "SketchB".

Notes

  • I only tested using Windows 10

@per1234
Copy link
Contributor

per1234 commented Feb 23, 2022

Hi @msujew. I have a question: is this intended to provide any support for Linux?

The reason I ask is because the addressed issues are for Windows and macOS and you didn't mention anything about Linux (perhaps even implicitly excluding it from the scope via the labels and mention only of "finder/explorer").

Although I would eventually like to see feature parity with Arduino IDE 1.x achieved in this respect for Linux as well, there is no reason that must be within the scope of this PR. I mentioned my Linux results in my first review only because I had tried it out of curiosity.

If this PR is intended to affect Linux, I'm happy to test on that OS as well. macOS is not so accessible to me so hopefully someone else can help with that.

@msujew
Copy link
Contributor Author

msujew commented Feb 23, 2022

@per1234 Previously I used platform === 'darwin or platform === 'win32' to switch the behavior. I now use isOSX (or !isOSX) for that, so Windows and Linux behavior should be the same now.

I also pushed some changes which made parsing the arguments a bit more lenient, I think it was too strict when going through the arguments, so it rejected some valid *.ino paths. I downloaded the latest artifact from GH Actions and the feature works well for me now.

Copy link
Contributor

@per1234 per1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried both of the previously failing test cases out using the latest build, on both Windows 10 and Ubuntu 20.04. Everything is working perfectly for me now.

Thanks @msujew!

@msujew
Copy link
Contributor Author

msujew commented Feb 23, 2022

@per1234 Great :)

@fstasi @AlbyIanna @kittaakos someone up for a review of the Mac related changes?

@fstasi
Copy link
Contributor

fstasi commented Feb 23, 2022

@per1234 Great :)

@fstasi @AlbyIanna @kittaakos someone up for a review of the Mac related changes?

both @ubidefeo and I tested it on mac. Works as expected. Merging :)

@fstasi fstasi merged commit 0207778 into main Feb 23, 2022
@fstasi fstasi deleted the msujew/open-from-finder branch February 23, 2022 15:39
@fstasi fstasi self-requested a review February 23, 2022 15:51
@dongwanpianist
Copy link

dongwanpianist commented Sep 9, 2023

Hello!
I have both Windows PC and Macbook for a long time, I used to be a long fan of Arduino IDE for Windows,
and today is my second day of using Arduino IDE for MacOS (Monterey 12.6.8) by downloading and installing arduino-ide_2.2.1_macOS_64bit.dmg from https://www.arduino.cc/en/software yesterday,
and I have encountered the problem on MacOS. (as of September 8th, 2023)

We are all developers, and I know how to report bug, so, here we go:

  1. When the app is NOT running, when I open Arduino IDE.app from ~/Application or Dock: ✅
    • It behaves well—of course, it is the basic initializer of the app instance...
    • as soon as the app is initialized, it shows a new window that opens the recently closed workspace folder (or a new file, if recent workspace is missing)
    • The MacOS menubar shows the menus linked with the current window, like this:
      image
  2. When the app is NOT running, when I double-click an .ino file from Finder: ❌
    • The app is initialized, but window is not showing forever. By this initialization, I cannot even make a new file or open a file. I don't have anything to do.
    • The MacOS menubar's File menu only has a disabled "Close Window" submenu, like this:
      image
    • Including above, any notable behavior of the menu is described below.
      • working menu:
        1. Arduino IDE > About arduino-ide (of course, this "Arduino IDE" menu has the events between OS and App instance)
        2. Arduino IDE > Quit arduino-ide
      • not working menu:
        1. Everything in File (disabled Close Window is the only visible submenu)
        2. Everything in View (the submenus are enabled, but doesn't change anything on click)
          image
        3. Everything in Window (its submenus are all disabled and visible)
        4. Help (provided by the OS, not useful except typing about or quit)
  3. When the app is NOT running, when I drag an .ino file to the Arduino IDE.app : ❌
    • Similar symptoms of 2.
  4. When the app is ALREADY running by the method 1., the additional method of 2. and 3. indeed behave well. The app creates the second window showing the clicked file. ✅
  5. Once 2. or 3. happened and the app is initialized without showing anything, I try 2. or 3. again. Guess what: it behaves well. Because the app is once initialized and it is now the case of 4. ✅ surprise!

So, with comparison of 2. and 4., I guess there is something wrong during openFilePromise or open-file upon the app's initialization. This issue is both critical and non-critical at the same time. I am keeping the app icon on my Dock, therefore I can still use the app easily by running like 1. However, this issue still needs to be fixed because the file extension .ino is linked to the app by default, at the point of installation. With my symptom test of 5., it became comic: From the OS-level event, I have to open a specific file twice(open-wait-open) in order to open it once.

Could any of you have a chance to take a look at the problem? Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os: macos Specific to macOS operating system os: windows Specific to Windows operating system topic: code Related to content of the project itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behaviour of "Open with....Arduino IDE" macOS, cannot open a file directly from Finder
5 participants