Browse Source

fix: update to use BindPostTaskToCurrentDefault

alice 5 months ago
parent
commit
08d8163201
2 changed files with 14 additions and 31 deletions
  1. 14 15
      shell/common/platform_util_mac.mm
  2. 0 16
      spec/api-shell-spec.ts

+ 14 - 15
shell/common/platform_util_mac.mm

@@ -19,6 +19,7 @@
 #include "base/logging.h"
 #include "base/mac/scoped_aedesc.h"
 #include "base/strings/sys_string_conversions.h"
+#include "base/task/bind_post_task.h"
 #include "base/task/thread_pool.h"
 #include "content/public/browser/browser_task_traits.h"
 #include "content/public/browser/browser_thread.h"
@@ -151,21 +152,19 @@ void OpenExternal(const GURL& url,
       [NSWorkspaceOpenConfiguration configuration];
   configuration.activates = options.activate;
 
-  __block OpenCallback copied_callback = std::move(callback);
-
-  [[NSWorkspace sharedWorkspace]
-                openURL:ns_url
-          configuration:configuration
-      completionHandler:^(NSRunningApplication* _Nullable app,
-                          NSError* _Nullable error) {
-        dispatch_async(dispatch_get_main_queue(), ^{
-          if (error) {
-            std::move(copied_callback).Run("Failed to open URL");
-          } else {
-            std::move(copied_callback).Run("");
-          }
-        });
-      }];
+  __block OpenCallback copied_callback =
+      base::BindPostTaskToCurrentDefault(std::move(callback));
+
+  [[NSWorkspace sharedWorkspace] openURL:ns_url
+                           configuration:configuration
+                       completionHandler:^(NSRunningApplication* _Nullable app,
+                                           NSError* _Nullable error) {
+                         if (error) {
+                           std::move(copied_callback).Run("Failed to open URL");
+                         } else {
+                           std::move(copied_callback).Run("");
+                         }
+                       }];
 }
 
 bool MoveItemToTrashWithError(const base::FilePath& full_path,

+ 0 - 16
spec/api-shell-spec.ts

@@ -76,22 +76,6 @@ describe('shell module', () => {
         requestReceived
       ]);
     });
-
-    ifit(process.platform === 'darwin')('should focus the external app when opening the URL on macOS', async () => {
-      const testUrl = 'http://127.0.0.1';
-      const mainWindow = new BrowserWindow({ show: true, webPreferences: { nodeIntegration: true, contextIsolation: false } });
-      await mainWindow.loadURL('about:blank');
-
-      mainWindow.webContents.on('will-navigate', (event, rawTarget) => {
-        event.preventDefault();
-        shell.openExternal(rawTarget);
-      });
-      const blurPromise = once(mainWindow, 'blur');
-      expect(mainWindow.isFocused()).to.be.true();
-      await mainWindow.webContents.executeJavaScript(`window.location.href = '${testUrl}'`);
-      await blurPromise;
-      expect(mainWindow.isFocused()).to.be.false();
-    });
   });
 
   describe('shell.trashItem()', () => {