Browse Source

add ability to access logs in getPath()

Shelley Vohr 7 years ago
parent
commit
5ef4caf8ab

+ 2 - 0
atom/browser/api/atom_api_app.cc

@@ -375,6 +375,8 @@ int GetPathConstant(const std::string& name) {
     return brightray::DIR_CACHE;
   else if (name == "userCache")
     return brightray::DIR_USER_CACHE;
+  else if (name == "logs")
+    return brightray::DIR_APP_LOGS;
   else if (name == "home")
     return base::DIR_HOME;
   else if (name == "temp")

+ 1 - 0
brightray/browser/brightray_paths.h

@@ -22,6 +22,7 @@ enum {
 
   DIR_USER_DATA = PATH_START,  // Directory where user data can be written.
   DIR_USER_CACHE,  // Directory where user cache can be written.
+  DIR_APP_LOGS,  // Directory where app logs live
 
 #if defined(OS_LINUX)
   DIR_APP_DATA,  // Application Data directory under the user profile.

+ 5 - 1
brightray/browser/browser_main_parts.cc

@@ -55,6 +55,8 @@
 
 namespace brightray {
 
+void OverrideMacAppLogsPath();
+
 namespace {
 
 #if defined(OS_WIN)
@@ -160,7 +162,9 @@ void BrowserMainParts::PreEarlyInitialization() {
   std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
   feature_list->InitializeFromCommandLine("", "");
   base::FeatureList::SetInstance(std::move(feature_list));
-
+#if defined(OS_MACOSX)
+  OverrideMacAppLogsPath();
+#endif
 #if defined(USE_X11)
   views::LinuxUI::SetInstance(BuildGtkUi());
   OverrideLinuxAppDataPath();

+ 2 - 0
brightray/browser/browser_main_parts.h

@@ -9,6 +9,8 @@
 
 #include "base/compiler_specific.h"
 #include "base/macros.h"
+#include "base/path_service.h"
+#include "brightray/browser/brightray_paths.h"
 #include "content/public/browser/browser_main_parts.h"
 #include "ui/views/layout/layout_provider.h"
 

+ 12 - 0
brightray/browser/browser_main_parts_mac.mm

@@ -6,6 +6,18 @@
 
 namespace brightray {
 
+void OverrideMacAppLogsPath() {
+  base::FilePath path;
+  NSString* bundleName = [[[NSBundle mainBundle] infoDictionary]
+    objectForKey:@"CFBundleName"];
+  NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName];
+
+  NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath];
+  std::string libPathString = std::string([libraryPath UTF8String]);
+
+  PathService::Override(DIR_APP_LOGS, base::FilePath(libPathString));
+}
+
 // Replicates NSApplicationMain, but doesn't start a run loop.
 void BrowserMainParts::InitializeMainNib() {
   auto infoDictionary = base::mac::OuterBundle().infoDictionary;