platform_util.h 2.1 KB

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