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

Added ability to change windowOptions & it's defaults. Moved disallowReloadKeybinding inside electron subsection #7803

Merged
merged 2 commits into from
May 22, 2020

Conversation

owlJaeger
Copy link
Contributor

@owlJaeger owlJaeger commented May 12, 2020

What it does

Fixes #7811

My preferred alternative to #7787 with overall better handling of windowOptions.
Clients can override windowOptions by using the IPC-Event (frontend):

import { ipcRenderer } from 'electron';

ipcRenderer.send('set-window-options', {
  frame: false
});

This will add frame: false to the windowOptions. If a property is already specified by the defaults, setting it will override the default:

import { ipcRenderer } from 'electron';

ipcRenderer.send('set-window-options', {
  minWidth: 300
});

// instead of 200 (default)

This PR has the advantage, that the windowState problem described here is not existent because only changes to the default windowOptions will be stored. This PR also enables clients to change these default options through the package.json like this:

"theia": {
  "target": "electron",
  "frontend": {
    "config": {
      "applicationName": "Theia Electron Example",
      "electron": {
        "windowOptions": {
          "frame": false
        }
      }
    }
  }
},

Preferred (top to bottom):

  1. Options set through IPC-Event
  2. Options set inside package.json
  3. Built-in options.

It also moves disallowReloadKeybinding into the new electron subsection:

"theia": {
  "target": "electron",
  "frontend": {
    "config": {
      "applicationName": "Theia Electron Example",
      "electron": {
        "disallowReloadKeybinding": true
      }
    }
  }
},

How to test

Modify the electron example:

"theia": {
  "target": "electron",
  "frontend": {
    "config": {
      "applicationName": "Theia Electron Example",
      "electron": {
        "disallowReloadKeybinding": true,
        "windowOptions": {
          "frame": false
        }
      }
    }
  }
},

If the window starts without a frame and can't be reloaded by using the keybinding (Ctrl+r on windows), the changes work.

Review checklist

Reminder for reviewers

@owlJaeger
Copy link
Contributor Author

@thegecko @spoenemann @kittaakos @westbury Any thoughts about this? I prefer this implementation due to the described problems of the old PR.

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I would prefer a more generic, and extensible solution than always having to modify the generator or including new props when attempting to update electron to suit an application's needs.

@marechal-p has previously worked on #4869 which updates electron-main to make use of inversify so that extenders can potentially use dependency injection to extend the default behavior to suit their needs. He is currently planning on reworking the changes again (as discussed in our dev-meeting)

  • (Paul) Rework the Electron main process architecture to allow clients to properly customize the behavior of their desktop application. I want to discuss if anyone has any concerns about such a rework, but I would work on this right away to make it easier for extenders to customize the Electron process. e.g. to permit nicely handle CLI arguments.

I don't think adding new props and customizing the generator each time we need new functionality is the way to go or scales well long-term.

@vince-fugnitto vince-fugnitto added the electron issues related to the electron target label May 12, 2020
@owlJaeger
Copy link
Contributor Author

I would prefer a more generic, and extensible solution than always having to modify the generator or including new props when attempting to update electron to suit an application's needs.

@marechal-p has previously worked on #4869 which updates electron-main to make use of inversify so that extenders can potentially use dependency injection to extend the default behavior to suit their needs. He is currently planning on reworking the changes again (as discussed in our dev-meeting)

  • (Paul) Rework the Electron main process architecture to allow clients to properly customize the behavior of their desktop application. I want to discuss if anyone has any concerns about such a rework, but I would work on this right away to make it easier for extenders to customize the Electron process. e.g. to permit nicely handle CLI arguments.

I don't think adding new props and customizing the generator each time we need new functionality is the way to go or scales well long-term.

I am looking forward to see these changes land. @marechal-p Do you have some estimate of how long it might take to see these changes? Are you planning on doing these changes on your own?

@paul-marechal
Copy link
Member

paul-marechal commented May 12, 2020

Until I have something nice I'm fine with the changes you have here.

But I cannot predict exactly if I'll have to undo what you're doing now once I'm done, what I mean is that the API to change those options might change with the refactoring. Is that ok with you?

I'm ok with either PR being a temporary solution.

@akosyakov @thegecko @spoenemann do you have any preferences?

@owlJaeger
Copy link
Contributor Author

Until I have something nice I'm fine with the changes you have here.

But I cannot predict exactly if I'll have to undo what you're doing now once I'm done, what I mean is that the API to change those options might change with the refactoring. Is that ok with you?

I'm ok with either PR being a temporary solution.

@akosyakov @thegecko @spoenemann do you have any preferences?

I do not have any problems with you discarding these changes as soon as the new API is done. I am looking forward to using it to set the defaults etc. in the client I am working on. So yes, it's ok with me 👍

I'd prefer this PR as this offers more features, flexibility and at the same time less problems with the windowState.

@akosyakov
Copy link
Member

Generally customisations should happen via DI, package.json should be used in addition only. I understand though that right now the main electron process is not really well structured and does not have clear lifecycle, so as a temporary solution it should be fine.

@owlJaeger owlJaeger force-pushed the newPR branch 3 times, most recently from 4e456ad to a884cfd Compare May 13, 2020 14:15
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

Is it still necessary now that #7787 is merged?

@owlJaeger
Copy link
Contributor Author

Is it still necessary now that #7787 is merged?

Yes, I'll create an issue which explains why this should be merged. I had a problem with github, that's the reason I think the other one got merged in the first place. I reviewed the code myself, noting an error. Github showed me that it was visible but it simply wasn't. I noticed it after looking at the page in incognito mode after it was merged... I am sorry for that. This PR reverts the old and implements the right way to handle the windowOptions and the windowState.

@vince-fugnitto
Copy link
Member

vince-fugnitto commented May 13, 2020

Is it still necessary now that #7787 is merged?

Yes, I'll create an issue which explains why this should be merged. I had a problem with github, that's the reason I think the other one got merged in the first place. I reviewed the code myself, noting an error. Github showed me that it was visible but it simply wasn't. I noticed it after looking at the page in incognito mode after it was merged... I am sorry for that. This PR reverts the old and implements the right way to handle the windowOptions and the windowState.

Since it is a workaround until the real solution is created and merged (dependency injection), I believe the original approach is sufficient? It is not a common use-case and will probably not require additional workaround improvements.

@owlJaeger
Copy link
Contributor Author

#7811 explains that downstream projects using the next version of Theia will receive #7787 and thus won't restore the old windowState.

@owlJaeger owlJaeger force-pushed the newPR branch 2 times, most recently from 7b7d6d8 to 981e251 Compare May 13, 2020 14:50
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I've tested the pull-request as is (without performing additional modifications) and my menu (traffic lights) is completely gone. The same is true after #7787.

Can someone else on macOS confirm this is the case for them?
@akosyakov @kittaakos

Screen Shot 2020-05-13 at 11 03 44 AM

Update: I've cleared the cache and it seems to work again properly.

@owlJaeger
Copy link
Contributor Author

I've tested the pull-request as is (without performing additional modifications) and my menu (traffic lights) is completely gone. The same is true after #7787.

Can someone else on macOS confirm this is the case for them?
@akosyakov @kittaakos

Screen Shot 2020-05-13 at 11 03 44 AM

Have you tested the frameless option before? If yes, you may have to clear the cache where electron-store saves its stuff.

@vince-fugnitto
Copy link
Member

Have you tested the frameless option before? If yes, you may have to clear the cache where electron-store saves its stuff.

@owlJaeger I just cleared it and saw you posted this :)

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@owlJaeger do you mind cleaning up the commits (I don't believe such commit granularity is required for such a small change). The revert commit should be separated however (like it is already done).

Nitpick: if possible can you improve the commit descriptions, they don't accurately describe the features in enough detail nor actually mention electron.

@owlJaeger
Copy link
Contributor Author

@owlJaeger do you mind cleaning up the commits (I don't believe such commit granularity is required for such a small change). The revert commit should be separated however (like it is already done).

Nitpick: if possible can you improve the commit descriptions, they don't accurately describe the features in enough detail nor actually mention electron.

Will do👍

@akosyakov
Copy link
Member

@vince-fugnitto Could you finish the review and merge then you think it is good?

@owlJaeger
Copy link
Contributor Author

owlJaeger commented May 16, 2020

@owlJaeger do you mind cleaning up the commits (I don't believe such commit granularity is required for such a small change). The revert commit should be separated however (like it is already done).

Nitpick: if possible can you improve the commit descriptions, they don't accurately describe the features in enough detail nor actually mention electron.

@vince-fugnitto What do you think about the new description?

@owlJaeger owlJaeger force-pushed the newPR branch 2 times, most recently from bc2e9e5 to fecf655 Compare May 16, 2020 20:16
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

@owlJaeger the changes look good to me, thank you for the contribution! 👍

I confirmed that the pull-request fixes #7811 (the maximized electron state is properly stored upon reloads), and that it is possible for application-developers to configure their respective behavior for windowOptions.

@vince-fugnitto
Copy link
Member

@owlJaeger do you mind rebasing the pull-request (conflict with the changelog)?
I'll merge tomorrow if there are no objections :)

@owlJaeger
Copy link
Contributor Author

Will do 👍

owlJaeger added 2 commits May 20, 2020 15:09
…set-window-options" IPC-Event or by specifying the windowOptions inside package.json under theia/frontend/config/electron/windowOptions".

Move "disallowReloadKeybinding" to the aforementioned "electron" object.

Signed-off-by: Luca Jaeger <[email protected]>
@owlJaeger
Copy link
Contributor Author

@owlJaeger do you mind rebasing the pull-request (conflict with the changelog)?
I'll merge tomorrow if there are no objections :)

The conflict is resolved and I will check every day so there won't be any conflicts

@vince-fugnitto
Copy link
Member

@owlJaeger do you mind rebasing the pull-request (conflict with the changelog)?
I'll merge tomorrow if there are no objections :)

The conflict is resolved and I will check every day so there won't be any conflicts

Sorry, I wasn't notified of the rebased, I'll merge now :) thank you for your contribution.

@vince-fugnitto vince-fugnitto merged commit 82cc44c into eclipse-theia:master May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron issues related to the electron target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windowState not saving anymore.
5 participants