-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Call AllowSetForegroundWindow before sending IPC #13255
Conversation
@the-ress, thanks for your PR! By analyzing the history of the files in this pull request, we identified @sandy081, @joaomoreno and @bpasero to be potential reviewers. |
Hi @the-ress, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! The agreement was validated by Microsoft and real humans are currently evaluating your PR. TTYL, MSBOT; |
@@ -306,7 +305,12 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> { | |||
promise = service.getMainProcessId() | |||
.then(processId => { | |||
logService.log('Sending some foreground love to the running instance:', processId); | |||
allowSetForegroundWindow(processId); | |||
try { | |||
const { allowSetForegroundWindow } = <any>require.__$__nodeRequire('windows-foreground-love'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@the-ress this is rather ugly, can we do what windows-mutex does? This native module is also only build for Windows and it still has a nice import 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried leaving the import there, but I got this error when committing:
Unused import: 'allowSetForegroundWindow'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, its fine, we seem to do the same for windows-mutex
I don't think it's possible/practical to solve this in Electron. VS Code has its own implementation of single-instance behavior (and Atom has another one). So on the Electron level, we don't know if the current instance is the second one, what is the PID of the first one or if the application is single-instance at all. Only way I can think of would be a catch-all approach - call |
Coverage decreased (-0.0004%) to 61.234% when pulling fa494be48bb42c6c91795dc1133d2ac572e1c6bc on the-ress:send-foreground-love into 809cef1 on Microsoft:master. |
@the-ress I think that is fine. When someone calls |
Here's an article about how |
@the-ress that is right and here is the problem:
Possible fix:
Alternatively I think it would be better to just implement the In any case, this has nothing to do with how on startup a single instance is maintained because the second instance that is starting up is just telling the first (main) instance to focus a window. The second instance is imho not doing anything wrong that would prevent the first instance from focussing the window. It is due to the process model within Electron that this is problematic. |
@the-ress I apologise, I should have read the blog post earlier and now I better understand the problem. I will actually post it to the relevant Atom and Electron issues so that people become aware of it. Nevertheless I still believe that a solution in Electron is possible. Electron provides API Since VS Code currently does not plan to use |
@the-ress can you resolve the merge conflicts? I reviewed the change and it looks good 👍 |
fa494be
to
124a86a
Compare
124a86a
to
2f13f1d
Compare
I resolved the conflicts. The Chromium API already does this so |
Hm, ok, we should eventually think about moving to that API if it solves the issue. |
Thank you. |
Call
AllowSetForegroundWindow
before sending IPC to the running instance on Windows (Fixes #929)When a second instance of vscode is started on Windows, it now performs these actions:
AllowSetForegroundWindow
to allow the original instance to useSetForegroundWindow
. (https://blogs.msdn.microsoft.com/oldnewthing/20090220-00/?p=19083)start
IPC to the original instance and exit.I created a
windows-foreground-love
npm package to wrap theAllowSetForegroundWindow
API.