mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
feat: Use DIR_ASSETS path to locate resource bundles (#47439)
* feat: Use DIR_ASSETS path to locate resource bundles
* Use DIR_ASSETS for calculating ASAR relative paths
* Add test to verify 'assets' matches parent dir of 'exe'
* Add Mac-specific test for assets path (but it is failing)
* test: Update app.getPath('assets') to expect an exception on Mac
* docs: Update docs for 'assets' path to indicate that it's only available on Windows + Linux
* fix: Don't define 'assets' mapping on macOS
This commit is contained in:
@@ -219,7 +219,7 @@ std::string LoadResourceBundle(const std::string& locale) {
|
||||
pak_dir =
|
||||
base::apple::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
||||
#else
|
||||
base::PathService::Get(base::DIR_MODULE, &pak_dir);
|
||||
base::PathService::Get(base::DIR_ASSETS, &pak_dir);
|
||||
#endif
|
||||
|
||||
std::string loaded_locale = ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
|
||||
@@ -383,6 +383,9 @@ int GetPathConstant(std::string_view name) {
|
||||
// clang-format off
|
||||
constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, int>({
|
||||
{"appData", DIR_APP_DATA},
|
||||
#if !BUILDFLAG(IS_MAC)
|
||||
{"assets", base::DIR_ASSETS},
|
||||
#endif
|
||||
#if BUILDFLAG(IS_POSIX)
|
||||
{"cache", base::DIR_CACHE},
|
||||
#else
|
||||
|
||||
@@ -26,13 +26,13 @@ const wchar_t kIntegrityCheckResourceType[] = L"Integrity";
|
||||
const wchar_t kIntegrityCheckResourceItem[] = L"ElectronAsar";
|
||||
|
||||
std::optional<base::FilePath> Archive::RelativePath() const {
|
||||
base::FilePath exe_path;
|
||||
if (!base::PathService::Get(base::FILE_EXE, &exe_path)) {
|
||||
LOG(FATAL) << "Couldn't get exe file path";
|
||||
base::FilePath assets_dir;
|
||||
if (!base::PathService::Get(base::DIR_ASSETS, &assets_dir)) {
|
||||
LOG(FATAL) << "Couldn't get assets directory path";
|
||||
}
|
||||
|
||||
base::FilePath relative_path;
|
||||
if (!exe_path.DirName().AppendRelativePath(path_, &relative_path)) {
|
||||
if (!assets_dir.AppendRelativePath(path_, &relative_path)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -456,11 +456,10 @@ base::FilePath GetResourcesPath() {
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
return MainApplicationBundlePath().Append("Contents").Append("Resources");
|
||||
#else
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
base::FilePath exec_path(command_line->GetProgram());
|
||||
base::PathService::Get(base::FILE_EXE, &exec_path);
|
||||
base::FilePath assets_path;
|
||||
base::PathService::Get(base::DIR_ASSETS, &assets_path);
|
||||
|
||||
return exec_path.DirName().Append(FILE_PATH_LITERAL("resources"));
|
||||
return assets_path.Append(FILE_PATH_LITERAL("resources"));
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user