refactor: make app logs dir creation opt-in (#17841)
Previously, we were creating the app logs folder at a predefined location during initial electron startup, which meant that it had to be manually removed and prevented clean app portability. This refactors that implementation such that it's now an opt-in feature and developers must call app.setAppLogsPath(path) with an optional custom path in order to set this directory.
This commit is contained in:
parent
841e31b7e6
commit
0749dc4cc1
8 changed files with 76 additions and 31 deletions
|
@ -16,6 +16,7 @@
|
|||
#include "atom/browser/atom_paths.h"
|
||||
#include "atom/browser/login_handler.h"
|
||||
#include "atom/browser/relauncher.h"
|
||||
#include "atom/common/application_info.h"
|
||||
#include "atom/common/atom_command_line.h"
|
||||
#include "atom/common/native_mate_converters/callback.h"
|
||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||
|
@ -830,6 +831,26 @@ void App::SetAppPath(const base::FilePath& app_path) {
|
|||
app_path_ = app_path;
|
||||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
void App::SetAppLogsPath(mate::Arguments* args) {
|
||||
base::FilePath custom_path;
|
||||
if (args->GetNext(&custom_path)) {
|
||||
if (!custom_path.IsAbsolute()) {
|
||||
args->ThrowError("Path must be absolute");
|
||||
return;
|
||||
}
|
||||
base::PathService::Override(DIR_APP_LOGS, custom_path);
|
||||
} else {
|
||||
base::FilePath path;
|
||||
if (base::PathService::Get(DIR_USER_DATA, &path)) {
|
||||
path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
||||
path = path.Append(base::FilePath::FromUTF8Unsafe("logs"));
|
||||
base::PathService::Override(DIR_APP_LOGS, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
|
||||
bool succeed = false;
|
||||
base::FilePath path;
|
||||
|
@ -1377,6 +1398,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("getAppPath", &App::GetAppPath)
|
||||
.SetMethod("setPath", &App::SetPath)
|
||||
.SetMethod("getPath", &App::GetPath)
|
||||
.SetMethod("setAppLogsPath", &App::SetAppLogsPath)
|
||||
.SetMethod("setDesktopName", &App::SetDesktopName)
|
||||
.SetMethod("getLocale", &App::GetLocale)
|
||||
.SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue