platform_util.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/callback_forward.h"
  8. #include "base/files/file_path.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. };
  23. // Open the given external protocol URL in the desktop's default manner.
  24. // (For example, mailto: URLs in the default mail user agent.)
  25. void OpenExternal(const GURL& url,
  26. const OpenExternalOptions& options,
  27. OpenCallback callback);
  28. // Move a file to trash, asynchronously.
  29. void TrashItem(const base::FilePath& full_path,
  30. base::OnceCallback<void(bool, const std::string&)> callback);
  31. void Beep();
  32. #if BUILDFLAG(IS_WIN)
  33. // SHGetFolderPath calls not covered by Chromium
  34. bool GetFolderPath(int key, base::FilePath* result);
  35. #endif
  36. #if BUILDFLAG(IS_MAC)
  37. bool GetLoginItemEnabled();
  38. bool SetLoginItemEnabled(bool enabled);
  39. #endif
  40. #if BUILDFLAG(IS_LINUX)
  41. // Returns a success flag.
  42. // Unlike libgtkui, does *not* use "chromium-browser.desktop" as a fallback.
  43. bool GetDesktopName(std::string* setme);
  44. // The XDG application ID must match the name of the desktop entry file without
  45. // the .desktop extension.
  46. std::string GetXdgAppId();
  47. #endif
  48. } // namespace platform_util
  49. #endif // ELECTRON_SHELL_COMMON_PLATFORM_UTIL_H_