2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-29 20:41:11 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_COMMON_PLATFORM_UTIL_H_
|
|
|
|
#define ELECTRON_SHELL_COMMON_PLATFORM_UTIL_H_
|
2013-04-29 20:41:11 +08:00
|
|
|
|
2016-11-17 11:22:09 +09:00
|
|
|
#include <string>
|
|
|
|
|
2018-10-10 22:46:54 +02:00
|
|
|
#include "base/files/file_path.h"
|
2023-02-03 12:43:42 +01:00
|
|
|
#include "base/functional/callback_forward.h"
|
2016-10-14 12:38:55 -07:00
|
|
|
#include "build/build_config.h"
|
2016-07-11 17:11:05 +09:00
|
|
|
|
2013-04-29 20:41:11 +08:00
|
|
|
class GURL;
|
|
|
|
|
|
|
|
namespace platform_util {
|
|
|
|
|
2019-11-07 23:08:43 -08:00
|
|
|
typedef base::OnceCallback<void(const std::string&)> OpenCallback;
|
2016-11-17 11:22:09 +09:00
|
|
|
|
2013-04-29 20:41:11 +08:00
|
|
|
// Show the given file in a file manager. If possible, select the file.
|
|
|
|
// Must be called from the UI thread.
|
2019-02-27 12:58:23 +00:00
|
|
|
void ShowItemInFolder(const base::FilePath& full_path);
|
2013-04-29 20:41:11 +08:00
|
|
|
|
|
|
|
// Open the given file in the desktop's default manner.
|
|
|
|
// Must be called from the UI thread.
|
2019-11-07 23:08:43 -08:00
|
|
|
void OpenPath(const base::FilePath& full_path, OpenCallback callback);
|
2013-04-29 20:41:11 +08:00
|
|
|
|
2018-10-10 22:46:54 +02:00
|
|
|
struct OpenExternalOptions {
|
|
|
|
bool activate = true;
|
|
|
|
base::FilePath working_dir;
|
2023-02-14 09:53:18 +01:00
|
|
|
bool log_usage = false;
|
2018-10-10 22:46:54 +02:00
|
|
|
};
|
|
|
|
|
2013-04-29 20:41:11 +08:00
|
|
|
// Open the given external protocol URL in the desktop's default manner.
|
|
|
|
// (For example, mailto: URLs in the default mail user agent.)
|
2019-05-03 13:53:45 -07:00
|
|
|
void OpenExternal(const GURL& url,
|
|
|
|
const OpenExternalOptions& options,
|
2019-11-07 23:08:43 -08:00
|
|
|
OpenCallback callback);
|
2016-10-13 13:28:11 -07:00
|
|
|
|
2020-09-02 10:32:33 -07:00
|
|
|
// Move a file to trash, asynchronously.
|
|
|
|
void TrashItem(const base::FilePath& full_path,
|
|
|
|
base::OnceCallback<void(bool, const std::string&)> callback);
|
|
|
|
|
2013-04-29 22:10:03 +08:00
|
|
|
void Beep();
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-05-12 19:27:56 -07:00
|
|
|
// SHGetFolderPath calls not covered by Chromium
|
|
|
|
bool GetFolderPath(int key, base::FilePath* result);
|
|
|
|
#endif
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2023-10-16 18:25:11 +02:00
|
|
|
std::string GetLoginItemEnabled(const std::string& type,
|
|
|
|
const std::string& service_name);
|
|
|
|
bool SetLoginItemEnabled(const std::string& type,
|
|
|
|
const std::string& service_name,
|
|
|
|
bool enabled);
|
2017-10-17 16:28:29 +09:00
|
|
|
#endif
|
|
|
|
|
2022-02-09 18:58:52 -08:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2018-10-19 20:51:43 +02:00
|
|
|
// Returns a success flag.
|
|
|
|
// Unlike libgtkui, does *not* use "chromium-browser.desktop" as a fallback.
|
|
|
|
bool GetDesktopName(std::string* setme);
|
2022-07-11 21:26:18 +03:00
|
|
|
|
|
|
|
// The XDG application ID must match the name of the desktop entry file without
|
|
|
|
// the .desktop extension.
|
|
|
|
std::string GetXdgAppId();
|
2018-10-19 20:51:43 +02:00
|
|
|
#endif
|
|
|
|
|
2013-05-01 15:42:30 +08:00
|
|
|
} // namespace platform_util
|
2013-04-29 20:41:11 +08:00
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_COMMON_PLATFORM_UTIL_H_
|