atom_api_app_mac.mm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "atom/browser/api/atom_api_app.h"
  5. #include "atom/browser/atom_paths.h"
  6. #include "atom/common/native_mate_converters/file_path_converter.h"
  7. #include "base/path_service.h"
  8. #import <Cocoa/Cocoa.h>
  9. namespace atom {
  10. namespace api {
  11. void App::SetAppLogsPath(mate::Arguments* args) {
  12. base::FilePath custom_path;
  13. if (args->GetNext(&custom_path)) {
  14. if (!custom_path.IsAbsolute()) {
  15. args->ThrowError("Path must be absolute");
  16. return;
  17. }
  18. base::PathService::Override(DIR_APP_LOGS, custom_path);
  19. } else {
  20. NSString* bundle_name =
  21. [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
  22. NSString* logs_path =
  23. [NSString stringWithFormat:@"Library/Logs/%@", bundle_name];
  24. NSString* library_path =
  25. [NSHomeDirectory() stringByAppendingPathComponent:logs_path];
  26. base::PathService::Override(DIR_APP_LOGS,
  27. base::FilePath([library_path UTF8String]));
  28. }
  29. }
  30. } // namespace atom
  31. } // namespace api