fix: use correct userData path when unbundled (#30113)
This commit is contained in:
parent
4db7221c7d
commit
bec47f54f4
7 changed files with 32 additions and 36 deletions
|
@ -123,7 +123,8 @@ bool ElectronPathProvider(int key, base::FilePath* result) {
|
||||||
case chrome::DIR_USER_DATA:
|
case chrome::DIR_USER_DATA:
|
||||||
if (!base::PathService::Get(DIR_APP_DATA, &cur))
|
if (!base::PathService::Get(DIR_APP_DATA, &cur))
|
||||||
return false;
|
return false;
|
||||||
cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
||||||
|
GetPossiblyOverriddenApplicationName()));
|
||||||
create_dir = true;
|
create_dir = true;
|
||||||
break;
|
break;
|
||||||
case DIR_CRASH_DUMPS:
|
case DIR_CRASH_DUMPS:
|
||||||
|
@ -153,7 +154,8 @@ bool ElectronPathProvider(int key, base::FilePath* result) {
|
||||||
#endif
|
#endif
|
||||||
if (!base::PathService::Get(parent_key, &cur))
|
if (!base::PathService::Get(parent_key, &cur))
|
||||||
return false;
|
return false;
|
||||||
cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
||||||
|
GetPossiblyOverriddenApplicationName()));
|
||||||
create_dir = true;
|
create_dir = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +180,8 @@ bool ElectronPathProvider(int key, base::FilePath* result) {
|
||||||
return false;
|
return false;
|
||||||
cur = cur.Append(FILE_PATH_LITERAL("Library"));
|
cur = cur.Append(FILE_PATH_LITERAL("Library"));
|
||||||
cur = cur.Append(FILE_PATH_LITERAL("Logs"));
|
cur = cur.Append(FILE_PATH_LITERAL("Logs"));
|
||||||
cur = cur.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
cur = cur.Append(base::FilePath::FromUTF8Unsafe(
|
||||||
|
GetPossiblyOverriddenApplicationName()));
|
||||||
#else
|
#else
|
||||||
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
|
if (!base::PathService::Get(chrome::DIR_USER_DATA, &cur))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -136,25 +136,25 @@ void Browser::Shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Browser::GetVersion() const {
|
std::string Browser::GetVersion() const {
|
||||||
std::string ret = GetOverriddenApplicationVersion();
|
std::string ret = OverriddenApplicationVersion();
|
||||||
if (ret.empty())
|
if (ret.empty())
|
||||||
ret = GetExecutableFileVersion();
|
ret = GetExecutableFileVersion();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetVersion(const std::string& version) {
|
void Browser::SetVersion(const std::string& version) {
|
||||||
OverrideApplicationVersion(version);
|
OverriddenApplicationVersion() = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Browser::GetName() const {
|
std::string Browser::GetName() const {
|
||||||
std::string ret = GetOverriddenApplicationName();
|
std::string ret = OverriddenApplicationName();
|
||||||
if (ret.empty())
|
if (ret.empty())
|
||||||
ret = GetExecutableFileProductName();
|
ret = GetExecutableFileProductName();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::SetName(const std::string& name) {
|
void Browser::SetName(const std::string& name) {
|
||||||
OverrideApplicationName(name);
|
OverriddenApplicationName() = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Browser::GetBadgeCount() {
|
int Browser::GetBadgeCount() {
|
||||||
|
|
|
@ -118,11 +118,7 @@ ElectronBrowserContext::ElectronBrowserContext(const std::string& partition,
|
||||||
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize),
|
||||||
&max_cache_size_);
|
&max_cache_size_);
|
||||||
|
|
||||||
if (!base::PathService::Get(chrome::DIR_USER_DATA, &path_)) {
|
CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &path_));
|
||||||
base::PathService::Get(DIR_APP_DATA, &path_);
|
|
||||||
path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
|
|
||||||
base::PathService::Override(chrome::DIR_USER_DATA, path_);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_memory && !partition.empty())
|
if (!in_memory && !partition.empty())
|
||||||
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
path_ = path_.Append(FILE_PATH_LITERAL("Partitions"))
|
||||||
|
|
|
@ -13,27 +13,21 @@
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
namespace {
|
std::string& OverriddenApplicationName() {
|
||||||
|
static base::NoDestructor<std::string> overridden_application_name;
|
||||||
base::NoDestructor<std::string> g_overridden_application_name;
|
return *overridden_application_name;
|
||||||
base::NoDestructor<std::string> g_overridden_application_version;
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// name
|
|
||||||
void OverrideApplicationName(const std::string& name) {
|
|
||||||
*g_overridden_application_name = name;
|
|
||||||
}
|
|
||||||
std::string GetOverriddenApplicationName() {
|
|
||||||
return *g_overridden_application_name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// version
|
std::string& OverriddenApplicationVersion() {
|
||||||
void OverrideApplicationVersion(const std::string& version) {
|
static base::NoDestructor<std::string> overridden_application_version;
|
||||||
*g_overridden_application_version = version;
|
return *overridden_application_version;
|
||||||
}
|
}
|
||||||
std::string GetOverriddenApplicationVersion() {
|
|
||||||
return *g_overridden_application_version;
|
std::string GetPossiblyOverriddenApplicationName() {
|
||||||
|
std::string ret = OverriddenApplicationName();
|
||||||
|
if (!ret.empty())
|
||||||
|
return ret;
|
||||||
|
return GetApplicationName();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetApplicationUserAgent() {
|
std::string GetApplicationUserAgent() {
|
||||||
|
|
|
@ -13,11 +13,10 @@
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
void OverrideApplicationName(const std::string& name);
|
std::string& OverriddenApplicationName();
|
||||||
std::string GetOverriddenApplicationName();
|
std::string& OverriddenApplicationVersion();
|
||||||
|
|
||||||
void OverrideApplicationVersion(const std::string& version);
|
std::string GetPossiblyOverriddenApplicationName();
|
||||||
std::string GetOverriddenApplicationVersion();
|
|
||||||
|
|
||||||
std::string GetApplicationName();
|
std::string GetApplicationName();
|
||||||
std::string GetApplicationVersion();
|
std::string GetApplicationVersion();
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace electron {
|
||||||
|
|
||||||
std::string GetApplicationName() {
|
std::string GetApplicationName() {
|
||||||
// attempt #1: the string set in app.setName()
|
// attempt #1: the string set in app.setName()
|
||||||
std::string ret = GetOverriddenApplicationName();
|
std::string ret = OverriddenApplicationName();
|
||||||
|
|
||||||
// attempt #2: the 'Name' entry from .desktop file's [Desktop] section
|
// attempt #2: the 'Name' entry from .desktop file's [Desktop] section
|
||||||
if (ret.empty()) {
|
if (ret.empty()) {
|
||||||
|
@ -64,7 +64,7 @@ std::string GetApplicationVersion() {
|
||||||
|
|
||||||
// try to use the string set in app.setVersion()
|
// try to use the string set in app.setVersion()
|
||||||
if (ret.empty())
|
if (ret.empty())
|
||||||
ret = GetOverriddenApplicationVersion();
|
ret = OverriddenApplicationVersion();
|
||||||
|
|
||||||
// no known version number; return some safe fallback
|
// no known version number; return some safe fallback
|
||||||
if (ret.empty()) {
|
if (ret.empty()) {
|
||||||
|
|
|
@ -924,6 +924,10 @@ describe('app module', () => {
|
||||||
expect(app.getPath('recent')).to.equal('C:\\fake-path');
|
expect(app.getPath('recent')).to.equal('C:\\fake-path');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('uses the app name in getPath(userData)', () => {
|
||||||
|
expect(app.getPath('userData')).to.include(app.name);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setPath(name, path)', () => {
|
describe('setPath(name, path)', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue