blob: de6ef4940a6d070eed7738abe6ed183b4eb5f1db [file] [log] [blame]
Avi Drissmanbfdd3a482023-01-25 19:17:161// Copyright 2013 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_MAC_LAUNCH_APPLICATION_H_
6#define BASE_MAC_LAUNCH_APPLICATION_H_
7
8#import <AppKit/AppKit.h>
9
10#include <string>
Victor Hugo Vianna Silvaab2c6ac2025-03-18 19:52:3411#include <variant>
Avi Drissmanbfdd3a482023-01-25 19:17:1612#include <vector>
13
14#include "base/base_export.h"
15#include "base/command_line.h"
16#include "base/files/file_path.h"
17#include "base/functional/callback_forward.h"
Avi Drissmanbfdd3a482023-01-25 19:17:1618
19// Launches an application.
20//
21// What makes this different from `LaunchProcess()` in /base/process/launch.h?
22// That code creates a sub-process, which is useful for utility processes and
23// the like, but inappropriate for independent applications.
24// `LaunchApplication()` below, on the other hand, launches an app in the way
25// that the Finder or Dock would launch an app.
26
27namespace base::mac {
28
29struct LaunchApplicationOptions {
30 bool activate = true;
31 bool create_new_instance = false;
32 bool prompt_user_if_needed = false;
Marijn Kruisselbrink88fa5d5f2023-08-09 18:27:5633
34 // When this option is set to true, a private SPI is used to launch the app
35 // "invisibly". Apps launched this way do not show up as running.
36 // Note that opening URLs in an already running hidden-in-background app
37 // appears to always cause the app to transition to foreground, even if we've
38 // requested a background launch.
39 bool hidden_in_background = false;
Avi Drissmanbfdd3a482023-01-25 19:17:1640};
41
42using LaunchApplicationCallback =
Avi Drissman4173dee2023-05-05 18:06:4543 base::OnceCallback<void(NSRunningApplication*, NSError*)>;
Avi Drissmanbfdd3a482023-01-25 19:17:1644
45using CommandLineArgs =
Victor Hugo Vianna Silvaab2c6ac2025-03-18 19:52:3446 std::variant<std::monostate, CommandLine, std::vector<std::string>>;
Avi Drissmanbfdd3a482023-01-25 19:17:1647
48// Launches the specified application.
49// - `app_bundle_path`: the location of the application to launch
50// - `command_line_args`: the command line arguments to pass to the
51// application if the app isn't already running (the default-constructed
52// monostate alternative means no arguments)
53// - Note: The application to launch is specified as `app_bundle_path`, so
54// if `base::CommandLine` is used to provide command line arguments, its
55// first argument will be ignored
56// - `url_specs`: the URLs for the application to open (an empty vector is OK)
57// - `options`: options to modify the launch
58// - `callback`: the result callback
59//
60// When the launch is complete, `callback` is called on the main thread. If the
Avi Drissman4173dee2023-05-05 18:06:4561// launch succeeded, it will be called with an `NSRunningApplication*` and the
62// `NSError*` will be nil. If the launch failed, it will be called with an
63// `NSError*`, and the `NSRunningApplication*` will be nil.
Avi Drissmanbfdd3a482023-01-25 19:17:1664BASE_EXPORT void LaunchApplication(const FilePath& app_bundle_path,
65 const CommandLineArgs& command_line_args,
66 const std::vector<std::string>& url_specs,
67 LaunchApplicationOptions options,
68 LaunchApplicationCallback callback);
69
70} // namespace base::mac
71
72#endif // BASE_MAC_LAUNCH_APPLICATION_H_