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

implement Win10+ app-restart feature in Notepad++ #14074

Closed

Conversation

xomx
Copy link
Contributor

@xomx xomx commented Aug 30, 2023

Fix: #9722 , #11721 , #11934 and Community forum requests like this.

Implemented as per previous discussion: #12541 (comment)

It will allow Notepad++ to be a "restartable app", like some other SW today (eg Google Chrome, Mozilla Firefox or all the MS Windows UWP apps, Office apps etc).

This is to create a seamless experience wherein, if you have to reboot your PC, you can now pick back up from where you left off and resume being productive.

The OS app-restart feature needs at least Windows 10 (20H1, builds 18963+, but it was quietly introduced earlier in the Fall Creators Update (b1709+)) and the user has to switch on the "Restart apps" in the system Settings, Win10 screenshot:
Win10-Settings-Accounts-SignInOptions-RestartApps

The corresponding Registry-key ON/OFF for testing:
RestartApps-Registry.zip

N++ Preferences (default is OFF):
NppMiscAppRestart

Currently the translation xml is not updated with new strings from this PR - I will add them later if this PR and the names used are accepted.

PR has been successfully tested under various Win10 and Win11. I also run this under Win7, all ok (the feature is not accessible from there).

It will allow for the Notepad++ to be a "restartable app", like some other SW can do today (eg Google Chrome, Mozilla Firefox or all the Microsoft UWP apps).

This is to create a seamless experience wherein, if you have to reboot your PC, you can now pick back up from where you left off and resume being productive.

The OS app-restart feature needs at least Windows 10 (20H1) and the user has to switch on the "Restart apps" in the system Settings (subsection Accounts > Sign-in options).
@xomx
Copy link
Contributor Author

xomx commented Aug 30, 2023

Another way to achieve this is to use Explorer compatibility hack:
app_properties_Compatibility_tab

@chcg chcg added the feature Feature requests and Feature commits label Aug 31, 2023
@donho donho self-assigned this Sep 2, 2023
@donho
Copy link
Member

donho commented Sep 3, 2023

@xomx
I'm kind of confused. According #12541 (comment), it's about a feature to restore application after Windows being restarted automatically due to a Windows update. So for me it's not necessary to have an option to activate it.

Am I missing some points about this feature?

@xomx
Copy link
Contributor Author

xomx commented Sep 4, 2023

@donho

Currently the N++ is not automatically restarted (reopened) by OS after the Windows Update restart at all.

If you activate this new PR option in N++, your actual N++ session will be automatically reopened not only in the case of the mentioned WU-restart, but also after usual user-initiated one (and even after user logoff/logon sequence).

I am currently using this feature e.g. in Firefox, where I usually have a lot of tabs open but for some reason I need a quick Windows restart and I do not want to bother with setting my browser to the exactly same state as it was before the restart.

@donho
Copy link
Member

donho commented Sep 4, 2023

@xomx
Thank you for your explanation.

I am currently using this feature e.g. in Firefox, where I usually have a lot of tabs open but for some reason I need a quick Windows restart and I do not want to bother with setting my browser to the exactly same state as it was before the restart.

My question is: does exist such option Restart Firefox for system app-restart to be enabled to make it work?

@xomx
Copy link
Contributor Author

xomx commented Sep 4, 2023

@donho

My question is: does exist such option Restart Firefox for system app-restart to be enabled to make it work?

Yes, in the Firefox settings for power-users, there is the toolkit.winRegisterApplicationRestart, which has to be true for that feature to work (I think this is currently the default option in Firefox builds and IMO - it's not a good choice):
Firefox-toolkit_winRegisterApplicationRestart

If you think in a way - let's enable this feature in N++ but save a corresponding on/off option in Preferences, I think it is not a good idea. This feature can have unpleasant consequences for the users privacy. If someone explicitly enables this option, that's fine (it is then up to such user to eventually close the N++ before the shutdown/restart/logoff, when one does not want N++ reopening at the next logon). It has a bit to do with the new N++ option "Always open a new document in addition at startup", which is there to prevent similar accidents for some users.

@donho
Copy link
Member

donho commented Sep 4, 2023

If you think in a way - let's enable this feature in N++ but save a corresponding on/off option in Preferences, I think it is not a good idea. This feature can have unpleasant consequences for the users privacy. If someone explicitly enables this option, that's fine (it is then up to such user to eventually close the N++ before the shutdown/restart/logoff, when one does not want N++ reopening at the next logon). It has a bit to do with the new N++ option "Always open a new document in addition at startup", which is there to prevent similar accidents for some users.

I see your point.
However, users won't be aware of this new option, so Notepad++ will be kept being ignored after OS restarting of Windows Update. It's shame that such good feature isn't useful for the most of users.
Furthermore, we've got already "Always open a new document in addition at startup", one more option for the same goal is kind of useless.

Another argument for removing this visual option is, obviously there aren't many complains from users of Firefox, Chrome & Edge (the amount of their users is huge) - otherwise, they would have considered making it as option and turn off it by default since long time ago.

What do you think?

@xomx
Copy link
Contributor Author

xomx commented Sep 5, 2023

@donho

I searched for such reports and it looks like you're right - most users probably like this feature ON as the default. But e.g. Tor Browser, which is based on Firefox and focuses on the privacy more, has this setting reversed.

Anyway, if you rather like the GUI option in the Preferences removed, I propose these changes:

  1. I will completely remove all my changes in the .\PowerEditor\src\WinControls\Preference\ subfolder, so the new GUI option simply disappear.

  2. But I will not touch much the other code, so we can easily put the GUI back if we need so in the future.

  3. For the power-users I am considering to use the hidden "GUIConfig commandLineInterpreter" way. Using so we can have even more flexible app-restart setting - we can use there an int value representing the dwFlags param for the RegisterApplicationRestart (new GUIConfig item will have its default int value 3, which is in fact the RESTART_NO_CRASH | RESTART_NO_HANG numerically) or -1 if one wants to completely dissable this feature in N++. I have already successfully tested this approach and the code changes are not big.

@donho
Copy link
Member

donho commented Sep 6, 2023

@xomx
IMO, the best way to let the most of users benefit it, but not to penalize small amount of users who don't want this feature, is make it optional, enabled by default.
It's a hidden option not on GUI, either in the config.xml, but to disable it by adding an empty xml (noRestartAutomatically.xml or you can find a better name) to disable this feature.

What do you think?

@xomx
Copy link
Contributor Author

xomx commented Sep 6, 2023

@donho

IMO, the best way to let the most of users benefit it, but not to penalize small amount of users who don't want this feature, is make it optional, enabled by default.

Yes, that is exactly my intention now.

t's a hidden option not on GUI, either in the config.xml, but to disable it by adding an empty xml (noRestartAutomatically.xml or you can find a better name) to disable this feature.

Ok, I will show you first my already finished solution with the config.xml file only. If you don't like it, I will also add another file trigger possibility (the mentioned noRestartAutomatically.xml)

@xomx
Copy link
Contributor Author

xomx commented Sep 6, 2023

@donho

The OS app-restart possibility is now automatically enabled in N++ at its startup unless a power-user chooses otherwise.

To disable this feature in N++, one has to manually edit the config.xml file in a similar way how it is described for the changing of the cmd-line interpreter in the Preferences for Advanced Users (if this way is accepted, I will also issue a request for the npp-user-manual update...)

Disabling the N++ app-restart feature (it has to be -1 and not 0, as the zero is also a suitable flag for the RegisterApplicationRestart WINAPI:
GUIConfig-item

When there is not such line in the config.xml, N++ uses its default value for the registerForOSAppRestart (which is 3 aka the RESTART_NO_CRASH | RESTART_NO_HANG)

In this way, the user can also adjust the registering parameters for his needs. E.g. when one uses 7 (instead of -1 for disabling), N++ uses HRESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH combination (1+2+4) for the registration.

All possible OS flags values:
RESTART_NO_CRASH: 0x00000001
RESTART_NO_HANG: 0x00000002
RESTART_NO_PATCH: 0x00000004
RESTART_NO_REBOOT: 0x00000008

Copy link
Member

@donho donho left a comment

Choose a reason for hiding this comment

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

Please remove the setting from config.xml and use noRestartAutomatically.xml to disable this feature.
Remove unnecessary arguments/parameters.

PowerEditor/src/Parameters.cpp Outdated Show resolved Hide resolved
PowerEditor/src/Notepad_plus.h Outdated Show resolved Hide resolved
PowerEditor/src/NppBigSwitch.cpp Outdated Show resolved Hide resolved
PowerEditor/src/Parameters.h Outdated Show resolved Hide resolved
@donho
Copy link
Member

donho commented Sep 7, 2023

@xomx
Thank you for the modification!

However,

To disable this feature in N++, one has to manually edit the config.xml file in a similar way how it is described for the changing of the cmd-line interpreter in the Preferences for Advanced Users (if this way is accepted, I will also issue a request for the npp-user-manual update...)

I remain the choice of noRestartAutomatically.xml - users don't need to modify config.xml at all. To re-enable this feature, remove this file - it's just simple and efficient.

When there is not such line in the config.xml, N++ uses its default value for the registerForOSAppRestart (which is 3 aka the RESTART_NO_CRASH | RESTART_NO_HANG)

In this way, the user can also adjust the registering parameters for his needs. E.g. when one uses 7 (instead of -1 for disabling), N++ uses HRESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH combination (1+2+4) for the registration.

I'm wondering why user do not need RESTART_NO_PATCH. IMO, we use HRESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH for the classic case and it's enough.

@xomx
Copy link
Contributor Author

xomx commented Sep 16, 2023

@donho
Sorry for the delay, now I resume my work on this.

I remain the choice of noRestartAutomatically.xml

ok

I'm wondering why user do not need RESTART_NO_PATCH. IMO, we use HRESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH for the classic case and it's enough.

Good point.
RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH is used e.g. in the Chrome source code, whereas other apps (e.g. Firefox) use RESTART_NO_CRASH | RESTART_NO_HANG only.

I will change it to the requested RESTART_NO_CRASH | RESTART_NO_HANG | RESTART_NO_PATCH.

@xomx
Copy link
Contributor Author

xomx commented Sep 19, 2023

@donho
Done.
Now N++ only automatically registers itself on its launch (at the end of successful WM_CREATE) for the OS app-restart.
To possibly suppress the registration, user can put the empty "noRestartAutomatically.xml" to the N++ app-folder or to the "%APPDATA%\Notepad++".

@donho
Copy link
Member

donho commented Sep 21, 2023

@xomx
Thank you for your work.
It works, but adding "noRestartAutomatically.xml" into "C:\temp\test" doesn't prevent Notepad++ from starting, after OS being restarted.
Here is my Debug Info:

Notepad++ v8.5.7   (64-bit)
Build time : Sep 21 2023 - 14:30:28
Path : C:\XXXXXXXX\notepad-plus-plus\PowerEditor\bin64\notepad++.exe
Command Line : 
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : C:\temp\test
OS Name : Windows 11 Home (64-bit)
OS Version : 22H2
OS Build : 22621.2283
Current ANSI codepage : 1252
Plugins : 
    ChangedLines (0.3.2.1)
    mimeTools (2.9)
    NppConverter (4.4)
    NppPluginDemo (4.3)

@xomx
Copy link
Contributor Author

xomx commented Sep 21, 2023

@donho
Maybe because of this (is that intended?):

Cloud Config : C:\temp\test

@donho
Copy link
Member

donho commented Sep 21, 2023

@xomx
Yes, that's what I said:
It works, but adding "noRestartAutomatically.xml" into "C:\temp\test" doesn't prevent Notepad++ from starting, after OS being restarted.

@donho
Copy link
Member

donho commented Sep 21, 2023

BTW, remove cloud setting and copy "noRestartAutomatically.xml" into "%APPDATA%\Notepad++" works.

@donho
Copy link
Member

donho commented Sep 21, 2023

@xomx
Sorry for the false alert: I have checked in your code, and found it it should work, so I did try several time. It works with cloud settings finally. I guess I've got the cloud settings file corrupted, due to some modification and test for fixing #14131
Sorry again for the false alert.

@donho donho added the accepted label Sep 21, 2023
@donho donho closed this in 87efdf5 Sep 21, 2023
@xomx xomx deleted the RegisterNppForOSAppRestart branch September 21, 2023 18:28
xomx added a commit to xomx/notepad-plus-plus that referenced this pull request Sep 22, 2023
donho pushed a commit that referenced this pull request Sep 22, 2023
@HarelM
Copy link

HarelM commented Nov 1, 2023

I see this feature in the release notes, do I need to activate it, or is this on by default?
I just restarted my PC and I didn't notice that N++ started again when the computer started.

@xomx
Copy link
Contributor Author

xomx commented Nov 1, 2023

@HarelM
In N++ v8.5.8+ it is ON by default.
But your Windows OS global setting for that feature has to be ON as well (in Win11 it is ON by default, but in Win10 it has to be activated manually (Settings > Accounts > Sign-in options > Restart Apps).

@HarelM
Copy link

HarelM commented Nov 1, 2023

Thanks for the quick response!
Interesting, I'm using win 11 and N++ 8.5.8, I'll do another restart and see if I can reproduce the issue. I might have closed it before the restart so it might have been my fault.

@HarelM
Copy link

HarelM commented Nov 1, 2023

Seems like this was off in the windows configuration, might be some company policy that turned it off.
Once turned in win 11, N++ is up and running after a restart.
THANKS!!!!! This is very very much appreciated.
Thanks for all the hours put into this amazing tool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted feature Feature requests and Feature commits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Make Notepad++ a restartable Windows 10 application
4 participants