platform_util.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ATOM_COMMON_PLATFORM_UTIL_H_
  5. #define ATOM_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. #if defined(OS_WIN)
  11. #include "base/strings/string16.h"
  12. #endif
  13. class GURL;
  14. namespace platform_util {
  15. typedef base::Callback<void(const std::string&)> OpenExternalCallback;
  16. // Show the given file in a file manager. If possible, select the file.
  17. // Must be called from the UI thread.
  18. bool ShowItemInFolder(const base::FilePath& full_path);
  19. // Open the given file in the desktop's default manner.
  20. // Must be called from the UI thread.
  21. bool OpenItem(const base::FilePath& full_path);
  22. struct OpenExternalOptions {
  23. bool activate = true;
  24. base::FilePath working_dir;
  25. };
  26. // Open the given external protocol URL in the desktop's default manner.
  27. // (For example, mailto: URLs in the default mail user agent.)
  28. bool OpenExternal(
  29. #if defined(OS_WIN)
  30. const base::string16& url,
  31. #else
  32. const GURL& url,
  33. #endif
  34. const OpenExternalOptions& options);
  35. // The asynchronous version of OpenExternal.
  36. void OpenExternal(
  37. #if defined(OS_WIN)
  38. const base::string16& url,
  39. #else
  40. const GURL& url,
  41. #endif
  42. const OpenExternalOptions& options,
  43. const OpenExternalCallback& callback);
  44. // Move a file to trash.
  45. bool MoveItemToTrash(const base::FilePath& full_path);
  46. void Beep();
  47. #if defined(OS_MACOSX)
  48. bool GetLoginItemEnabled();
  49. void SetLoginItemEnabled(bool enabled);
  50. #endif
  51. } // namespace platform_util
  52. #endif // ATOM_COMMON_PLATFORM_UTIL_H_