Skip to content
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

Save dialog for closing temporary sketch and unsaved files #893

Merged
merged 6 commits into from Jun 1, 2022

Conversation

msujew
Copy link
Contributor

@msujew msujew commented Mar 8, 2022

Motivation

Closes #595
Closes #862

Change description

When closing the app, it will check whether the current sketch is temporary and ask the user to save it somewhere else.

Other information

When disabling autoSave and editing a file in a temp sketch and trying to close the app, two dialogs will appear. This is an issue in upstream Theia, see eclipse-theia/theia#10860. A PR to fix this is linked.

Reviewer checklist

  • PR addresses a single concern.
  • The PR has no duplicates (please search among the Pull Requests before creating one)
  • PR title and description are properly filled.
  • Docs have been added / updated (for bug fixes / features)

@AlbyIanna
Copy link
Contributor

This doesn't seem to solve #595.
I'm on MacOS and what's happening is this: 👇

Screen.Recording.2022-03-09.at.09.58.25.mov

As you can see, no dialog appears when closing unsaved sketches, be they temporary or permanent sketches.

@AlbyIanna
Copy link
Contributor

AlbyIanna commented Mar 9, 2022

I noticed another funny behaviour though. It appears that from the Menu bar there are 3 different ways of closing the IDE:
image
image

  1. Arduino IDE > Quit Arduino IDE
    this one closes all IDE windows, as expected, but doesn't ask to save unsaved changes.

  2. File > Close
    this seems to work properly with temporary sketches, but not with permanent sketches, as shown in the video below. Also, I noticed that this works the same in the main, then I guess it's not an effect of this PR.

Screen.Recording.2022-03-09.at.10.18.38.mov
  1. File > Close Editor
    This doesn't seem to do anything at all when clicked.

Notice that 2. File > Close and 3. File > Close Editor are bound to the same shortcut (CMD+W). When I use the shortcut CMD+W, the behaviour of 2. File > Close is performed.

Consider also that I cannot see differences between this branch and the main branch. @msujew am I missing something?

@msujew
Copy link
Contributor Author

msujew commented Mar 9, 2022

@AlbyIanna Thanks for looking into it. I'm confused, because it works as the requirements state on Windows:

2022-03-09.12-07-47.mp4

The only way I can imagine this to break is if the SketchService#isTemp method does not work correctly on MacOS? Can you try other instances where it is used? Alternatively can you debug through the following method and see were it stops?

const sketch = await this.sketchServiceClient.currentSketch();

@AlbyIanna
Copy link
Contributor

Yes, I'll give it a try. In the meanwhile, @per1234 would you please test this on Linux? I wonder if it works there at this point.

@AlbyIanna
Copy link
Contributor

AlbyIanna commented Mar 9, 2022

@msujew okay, now it gets interesting. I've just launched the IDE in debug mode and it worked (almost) perfectly. The build artifact from the CI is still broken though 🤔

@AlbyIanna
Copy link
Contributor

@msujew I would suggest you try to download the build artifact produced in the GitHub workflow and see if it works on Windows.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Mar 9, 2022
@per1234
Copy link
Contributor

per1234 commented Mar 10, 2022

From #893 (comment):

no dialog appears when closing unsaved sketches, be they temporary or permanent sketches.

This is tracked at #862


From #893 (comment)

I noticed that this works the same in the main, then I guess it's not an effect of this PR.

Correct. #862 was introduced by the last Theia bump (#791)

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.

RESOLVED!

I tested the latest CI build for this PR (Version: 2.0.0-rc4-snapshot-de6aa05) on Windows 10 and Ubuntu 20.04.

Unfortunately, it did not fix #595 for me:

  1. Select File > Preferences... from the Arduino IDE menus.
  2. Check the box next to "☐ Auto save".
  3. Click the OK button.
  4. Select File > New from the Arduino IDE menus.
  5. Make any change to the sketch.
  6. Use the standard window control (i.e., X or 🔴) to close the window.
    🐛 The window closes without the expected confirmation of close with unsaved changes (If autosave is on, user is not prompted to "save as..." when closing a newly created sketch or edited example.  #595).
  7. Select File > New from the Arduino IDE menus.
  8. Make any change to the sketch.
  9. Select File > Quit from the Arduino IDE menus.
    🐛 The window closes without the expected confirmation of close with unsaved changes (If autosave is on, user is not prompted to "save as..." when closing a newly created sketch or edited example.  #595).

@AlbyIanna
Copy link
Contributor

@msujew I downloaded the latest workflow build and now it doesn't work at all on MacOs. Have you tested the workflow build?

@msujew
Copy link
Contributor Author

msujew commented Mar 17, 2022

@AlbyIanna downloaded the workflow build and it works as expected (on Windows)

2022-03-17.13-35-12.mp4

I'll probably get to it next week, and ask some of my colleagues to test it for me.

@per1234
Copy link
Contributor

per1234 commented Mar 18, 2022

I'm happy to do another round of testing whenever you are ready for it. Just let me know.

@AlbyIanna
Copy link
Contributor

@msujew can I help somehow?

@fstasi
Copy link
Contributor

fstasi commented Mar 24, 2022

@msujew do you have any clue why this does not work on the artifact version on mac?

@msujew
Copy link
Contributor Author

msujew commented Apr 6, 2022

@AlbyIanna @fstasi I am making steady progress on it: It currently seems like the shutdown routine isn't called at all when using the MacOS artifact. I will change the build script a bit locally to leave more debug information in there, so that we can debug the final artifact. I'll keep you updated on that.

@msujew
Copy link
Contributor Author

msujew commented May 19, 2022

@per1234 @AlbyIanna I'm back from vacation and rewrote the whole feature. It should work now, even on Mac (tested with a colleague of mine). Please let me know if you find any issues with this approach.

@msujew msujew changed the title Save dialog for closing temporary sketch Save dialog for closing temporary sketch and unsaved files May 20, 2022
@per1234
Copy link
Contributor

per1234 commented May 25, 2022

Hi @msujew. There was a notarization service outage yesterday which caused a spurious failure of the build workflow.

Everything is back to normal today. Would you mind rebasing the PR on the main branch to trigger another build so that I can try out your fix?

@msujew msujew force-pushed the msujew/save-on-close branch 2 times, most recently from 9e96731 to 366a6de Compare May 25, 2022 10:30
@msujew
Copy link
Contributor Author

msujew commented May 25, 2022

@per1234 Oh, I didn't notice earlier. It took a bit (seems like GH Actions is still a bit slow), but the artifacts have finished building 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.

RESOLVED!

Describe the problem

🐛 The Arduino IDE window can not be closed.

To reproduce

  1. Click the standard window close control (i.e., X or 🔴) on the Arduino IDE window.
    🐛 The IDE window does not close.
  2. Select File > Close from the Arduino IDE menus.
    🐛 The IDE window does not close.
  3. Select File > Quit from the Arduino IDE menus.
    🐛 The IDE windows do not close.

Expected behavior

IDE window(s) close via all the standard methods.

Arduino IDE version

2.0.0-rc6-snapshot-6f1f5e2
(tester build for 366a6de)

Operating system

Windows 10, Ubuntu 20.04

Additional context

The issue does not occur when using the build from the tip of the main branch (522a5c6).


I see output like this in the terminal after attempting to close the window:

Marking workspace as a closed sketch. Workspace URI: file:///c%3A/Users/per/AppData/Local/Temp/.arduinoIDE-unsaved2022425-12916-3dhrhd.jb5c4/sketch_may25a. Date: 1653481012912.

@msujew
Copy link
Contributor Author

msujew commented May 25, 2022

@per1234 it seems like the Theia update broke the way I'm triggering the dialogs...

Back to the drawing board, hopefully I'll have something by the start of next week (next two days are public holidays in Germany).

@kittaakos
Copy link
Contributor

#862 works for me on macOS.

I did the following from the sources:

  • open IDE2,
  • my sketch from directories#user was opened,
  • disabled auto-save via the preferences, hit OK,
  • touched a file, the editor was dirty,
  • clicked on File > Close,
  • I had the confirm dialog.

Screen Shot 2022-05-31 at 11 18 56

1 similar comment
@kittaakos
Copy link
Contributor

#862 works for me on macOS.

I did the following from the sources:

  • open IDE2,
  • my sketch from directories#user was opened,
  • disabled auto-save via the preferences, hit OK,
  • touched a file, the editor was dirty,
  • clicked on File > Close,
  • I had the confirm dialog.

Screen Shot 2022-05-31 at 11 18 56

@msujew
Copy link
Contributor Author

msujew commented May 31, 2022

@kittaakos Did you confirm this with the CI build or with a local dev instance? The last time, it didn't work when running the CI build, but building from sources worked correctly (macOS)

@kittaakos
Copy link
Contributor

There is no confirmation dialog when closing a dirty sketch. The sketch is under directories#user.

  • I downloaded the IDE2,
  • Start IDE, existing sketch opens,
  • Make sure auto-save is off,
  • Touch the sketch, close the sketch with Cmd+W.
  • The sketch closes without the confirmation dialog.

@kittaakos
Copy link
Contributor

The last time, it didn't work when running the CI build, but building from sources worked correctly (macOS)

Thanks for the heads-up, yes it was from sources so I downloaded the bundled app and kept testing that. I can confirm, from the bundled app, that the IDE2 quits without asking anything. Strange indeed, I will investigate.

@msujew
Copy link
Contributor Author

msujew commented May 31, 2022

Touch the sketch, close the sketch with Cmd+W.
The sketch closes without the confirmation dialog.

Yeah, that was an oversight. Using Cmd+W triggers the CLOSE command, which is completely separately implemented (for some reason). It should be the same as closing the window using the X button now.

@kittaakos
Copy link
Contributor

kittaakos commented May 31, 2022

I found the problem; it's here:

https://github.com/eclipse-theia/theia/blob/ede3d6fa8854ffbbd409360fa143a84c10352ce5/packages/core/src/electron-main/theia-electron-window.ts#L125

On my installation, the currentUrl is file:///Applications/Arduino%20IDE.app/Contents/Resources/app/lib/index.html?port=57442#/Users/a.kitta/Documents/Arduino/sketch_may27a, and the frontendUri is /Applications/Arduino IDE.app/Contents/Resources/app/lib/index.html. Note the incorrect URL encoding/escaping problem.

The !currentUrl.includes(frontendUri) will be true, and the default logic shortcuts the boolean evaluation, and the IDE2 does not show the dialog.

The fix is to URI encode the this.globals.THEIA_FRONTEND_HTML_PATH. It seems the space in the path is causing the issue again.

@msujew
Copy link
Contributor Author

msujew commented May 31, 2022

@kittaakos Thanks! Finally, the mystery has been solved :D

I'll create an issue in the Theia repo for this 👍

@kittaakos
Copy link
Contributor

I'll create an issue in the Theia repo for this 👍

Thank you ❤️

Akos Kitta added 4 commits May 31, 2022 13:48
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Removed `electron` from the `nls-extract`. It does not contain app code.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
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.

This fixes #595 and #862 for me on my Windows and Linux machines.

Thanks for this important fix @msujew and @kittaakos!

@fstasi fstasi merged commit 5b486b1 into main Jun 1, 2022
@fstasi fstasi deleted the msujew/save-on-close branch June 1, 2022 08:55
@per1234 per1234 mentioned this pull request Jun 1, 2022
3 tasks
AlbyIanna pushed a commit that referenced this pull request Jun 3, 2022
* Use normal `OnWillStop` event

* Align `CLOSE` command to rest of app

* Fixed FS path vs encoded URL comparision when handling stop request.

Ref: eclipse-theia/theia#11226
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Fixed the translations.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Fixed the translations again.

Removed `electron` from the `nls-extract`. It does not contain app code.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Aligned the stop handler code to Theia.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

Co-authored-by: Akos Kitta <a.kitta@arduino.cc>
AlbyIanna pushed a commit that referenced this pull request Jun 7, 2022
* backend structure WIP

* Scaffold interfaces and classes for pluggable monitors

* Implement MonitorService to handle pluggable monitor lifetime

* Rename WebSocketService to WebSocketProvider and uninjected it

* Moved some interfaces

* Changed upload settings

* Enhance MonitorManager APIs

* Fixed WebSocketChange event signature

* Add monitor proxy functions for the frontend

* Moved settings to MonitorService

* Remove several unnecessary serial monitor classes

* Changed how connection is handled on upload

* Proxied more monitor methods to frontend

* WebSocketProvider is not injectable anymore

* Add generic monitor settings storaging

* More serial classes removal

* Remove unused file

* Changed plotter contribution to use new manager proxy

* Changed MonitorWidget and children to use new monitor proxy

* Updated MonitorWidget to use new monitor proxy

* Fix backend logger bindings

* Delete unnecessary Symbol

* coreClientProvider is now set when constructing MonitorService

* Add missing binding

* Fix `MonitorManagerProxy` DI issue

* fix monitor connection

* delete duplex when connection is closed

* update arduino-cli to 0.22.0

* fix upload when monitor is open

* add MonitorSettingsProvider interface

* monitor settings provider stub

* updated pseudo code

* refactor monitor settings interfaces

* monitor service provider singleton

* add unit tests

* change MonitorService providers to injectable deps

* fix monitor settings client communication

* refactor monitor commands protocol

* use monitor settings provider properly

* add settings to monitor model

* add settings to monitor model

* reset serial monitor when port changes

* fix serial plotter opening

* refine monitor connection settings

* fix hanging web socket connections

* add serial plotter reset command

* send port to web socket clients

* monitor service wait for success serial port open

* fix reset loop

* update serial plotter version

* update arduino-cli version to 0.23.0-rc1 and regenerate grpc protocol

* remove useless plotter protocol file

* localize web socket errors

* clean-up code

* update translation file

* Fix duplicated editor tabs (#1012)

* Save dialog for closing temporary sketch and unsaved files (#893)

* Use normal `OnWillStop` event

* Align `CLOSE` command to rest of app

* Fixed FS path vs encoded URL comparision when handling stop request.

Ref: eclipse-theia/theia#11226
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Fixed the translations.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Fixed the translations again.

Removed `electron` from the `nls-extract`. It does not contain app code.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* Aligned the stop handler code to Theia.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

Co-authored-by: Akos Kitta <a.kitta@arduino.cc>

* fix serial monitor send line ending

* refactor monitor-service poll for test/readability

* localize web socket errors

* update translation file

* Fix duplicated editor tabs (#1012)

* i18n:check rerun

* Speed up IDE startup time.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* override coreClientProvider in monitor-service

* cleanup merged code

Co-authored-by: Francesco Stasi <f.stasi@me.com>
Co-authored-by: Silvano Cerza <silvanocerza@gmail.com>
Co-authored-by: Mark Sujew <mark.sujew@typefox.io>
Co-authored-by: David Simpson <45690499+davegarthsimpson@users.noreply.github.com>
Co-authored-by: Akos Kitta <a.kitta@arduino.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
5 participants