Merge pull request #10191 from electron/add_log_path_support
add ability to access logs in getPath()
This commit is contained in:
commit
9f895879bf
6 changed files with 41 additions and 1 deletions
|
@ -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")
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -4,6 +4,13 @@
|
|||
|
||||
#include "brightray/browser/browser_main_parts.h"
|
||||
|
||||
#if defined(OSX_POSIX)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <string>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
|
@ -11,6 +18,7 @@
|
|||
#include "brightray/browser/browser_context.h"
|
||||
#include "brightray/browser/devtools_manager_delegate.h"
|
||||
#include "brightray/browser/web_ui_controller_factory.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "brightray/common/main_delegate.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
|
@ -156,11 +164,26 @@ BrowserMainParts::BrowserMainParts() {
|
|||
BrowserMainParts::~BrowserMainParts() {
|
||||
}
|
||||
|
||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||
void OverrideAppLogsPath() {
|
||||
#if defined(OS_WIN)
|
||||
std::wstring app_name = base::UTF8ToWide(GetApplicationName());
|
||||
std::wstring log_path = L"%HOMEDRIVE%%HOMEPATH%\\AppData\\Roaming\\";
|
||||
std::wstring app_log_path = log_path + app_name + L"\\logs";
|
||||
#else
|
||||
std::string app_name = GetApplicationName();
|
||||
std::string home_path = std::string(getenv("HOME"));
|
||||
std::string app_log_path = home_path + "/.config/" + app_name + "/logs";
|
||||
#endif
|
||||
PathService::Override(DIR_APP_LOGS, base::FilePath(app_log_path));
|
||||
}
|
||||
#endif
|
||||
|
||||
void BrowserMainParts::PreEarlyInitialization() {
|
||||
std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
|
||||
feature_list->InitializeFromCommandLine("", "");
|
||||
base::FeatureList::SetInstance(std::move(feature_list));
|
||||
|
||||
OverrideAppLogsPath();
|
||||
#if defined(USE_X11)
|
||||
views::LinuxUI::SetInstance(BuildGtkUi());
|
||||
OverrideLinuxAppDataPath();
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -45,6 +47,7 @@ class BrowserMainParts : public content::BrowserMainParts {
|
|||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
void InitializeMainNib();
|
||||
void OverrideAppLogsPath();
|
||||
#endif
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
|
|
|
@ -6,6 +6,16 @@
|
|||
|
||||
namespace brightray {
|
||||
|
||||
void BrowserMainParts::OverrideAppLogsPath() {
|
||||
base::FilePath path;
|
||||
NSString* bundleName = [[[NSBundle mainBundle] infoDictionary]
|
||||
objectForKey:@"CFBundleName"];
|
||||
NSString* logsPath = [NSString stringWithFormat:@"Library/Logs/%@",bundleName];
|
||||
NSString* libraryPath = [NSHomeDirectory() stringByAppendingPathComponent:logsPath];
|
||||
|
||||
PathService::Override(DIR_APP_LOGS, base::FilePath([libraryPath UTF8String]));
|
||||
}
|
||||
|
||||
// Replicates NSApplicationMain, but doesn't start a run loop.
|
||||
void BrowserMainParts::InitializeMainNib() {
|
||||
auto infoDictionary = base::mac::OuterBundle().infoDictionary;
|
||||
|
|
|
@ -458,6 +458,7 @@ You can request the following paths by the name:
|
|||
* `music` Directory for a user's music.
|
||||
* `pictures` Directory for a user's pictures.
|
||||
* `videos` Directory for a user's videos.
|
||||
* `logs` Directory for your app's log folder.
|
||||
* `pepperFlashSystemPlugin` Full path to the system version of the Pepper Flash plugin.
|
||||
|
||||
### `app.getFileIcon(path[, options], callback)`
|
||||
|
|
Loading…
Reference in a new issue