fix: update shell.openExternal to correctly focus on external window (#44408)
* fix: Use openURL:configuration:completionHandler instead of openUrl * test: add a test * fix: add dispatch_async to replace GetUIThreadTaskRunner * refactor: remove unused import * fix: update to use BindPostTaskToCurrentDefault * test: add regression test for window focus * refactor: update to explicit task runner
This commit is contained in:
parent
7ff7160135
commit
de04fc3b90
2 changed files with 36 additions and 4 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "base/logging.h"
|
||||
#include "base/mac/scoped_aedesc.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "content/public/browser/browser_task_traits.h"
|
||||
#include "electron/mas.h"
|
||||
|
@ -147,11 +148,27 @@ void OpenExternal(const GURL& url,
|
|||
return;
|
||||
}
|
||||
|
||||
bool success = [[NSWorkspace sharedWorkspace] openURL:ns_url];
|
||||
if (success && options.activate)
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
NSWorkspaceOpenConfiguration* configuration =
|
||||
[NSWorkspaceOpenConfiguration configuration];
|
||||
configuration.activates = options.activate;
|
||||
|
||||
std::move(callback).Run(success ? "" : "Failed to open URL");
|
||||
__block OpenCallback copied_callback = std::move(callback);
|
||||
scoped_refptr<base::SequencedTaskRunner> runner =
|
||||
base::SequencedTaskRunner::GetCurrentDefault();
|
||||
|
||||
[[NSWorkspace sharedWorkspace]
|
||||
openURL:ns_url
|
||||
configuration:configuration
|
||||
completionHandler:^(NSRunningApplication* _Nullable app,
|
||||
NSError* _Nullable error) {
|
||||
if (error) {
|
||||
runner->PostTask(FROM_HERE, base::BindOnce(std::move(copied_callback),
|
||||
"Failed to open URL"));
|
||||
} else {
|
||||
runner->PostTask(FROM_HERE,
|
||||
base::BindOnce(std::move(copied_callback), ""));
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
bool MoveItemToTrashWithError(const base::FilePath& full_path,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue