From 99cf9fe1c281ba296c7d2336cde5e36e3c67629c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:25 +0000 Subject: [PATCH 1/7] feat: Use DIR_ASSETS path to locate resource bundles Co-authored-by: Will Anderson --- docs/api/app.md | 3 ++- shell/app/electron_main_delegate.cc | 2 +- shell/browser/api/electron_api_app.cc | 1 + shell/common/node_bindings.cc | 7 +++---- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 0ed350dad7fd6..91d7508441b76 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -602,6 +602,7 @@ Returns `string` - The current application directory. * `%APPDATA%` on Windows * `$XDG_CONFIG_HOME` or `~/.config` on Linux * `~/Library/Application Support` on macOS + * `assets` The directory where app assets such as `resources.pak` are stored. By default this is the same as the folder containing the `exe` path. * `userData` The directory for storing your app's configuration files, which by default is the `appData` directory appended with your app's name. By convention files storing user data should be written to this directory, and @@ -616,7 +617,7 @@ Returns `string` - The current application directory. directory. * `temp` Temporary directory. * `exe` The current executable file. - * `module` The `libchromiumcontent` library. + * `module` The location of the Chromium module. By default this is synonymous with `exe`. * `desktop` The current user's Desktop directory. * `documents` Directory for a user's "My Documents". * `downloads` Directory for a user's downloads. diff --git a/shell/app/electron_main_delegate.cc b/shell/app/electron_main_delegate.cc index 819843179406c..a5116fc8969f7 100644 --- a/shell/app/electron_main_delegate.cc +++ b/shell/app/electron_main_delegate.cc @@ -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( diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index ebb6cd875a7a1..7565b6a450c3d 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -383,6 +383,7 @@ int GetPathConstant(std::string_view name) { // clang-format off constexpr auto Lookup = base::MakeFixedFlatMap({ {"appData", DIR_APP_DATA}, + {"assets", base::DIR_ASSETS}, #if BUILDFLAG(IS_POSIX) {"cache", base::DIR_CACHE}, #else diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index c90809e99fb1e..04648369ce8d7 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -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 From 5e11a8a45dc942f0ade1cbedaca3ac53d2b09165 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:29 +0000 Subject: [PATCH 2/7] Use DIR_ASSETS for calculating ASAR relative paths Co-authored-by: Will Anderson --- shell/common/asar/archive_win.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/common/asar/archive_win.cc b/shell/common/asar/archive_win.cc index 861c2fec086e7..ae3e73797bf4f 100644 --- a/shell/common/asar/archive_win.cc +++ b/shell/common/asar/archive_win.cc @@ -26,13 +26,13 @@ const wchar_t kIntegrityCheckResourceType[] = L"Integrity"; const wchar_t kIntegrityCheckResourceItem[] = L"ElectronAsar"; std::optional 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; } From 157d40d9511dd1c1b31dd5eaaf76541b1c3669f9 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:33 +0000 Subject: [PATCH 3/7] Add test to verify 'assets' matches parent dir of 'exe' Co-authored-by: Will Anderson --- spec/api-app-spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 1aa4daae04e07..393468d68daba 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -1068,6 +1068,12 @@ describe('app module', () => { expect(paths).to.deep.equal([true, true, true]); }); + it('returns an assets path that is identical to the exe parent directory', () => { + const assetsPath = app.getPath('assets'); + expect(fs.existsSync(assetsPath)).to.be.true(); + expect(assetsPath).to.equal(path.dirname(app.getPath('exe'))); + }); + it('throws an error when the name is invalid', () => { expect(() => { app.getPath('does-not-exist' as any); From 89f38cca70711367e89ba7085261d0bb13cc961c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:37 +0000 Subject: [PATCH 4/7] Add Mac-specific test for assets path (but it is failing) Co-authored-by: Will Anderson --- spec/api-app-spec.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 393468d68daba..84753df3a264c 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -1068,11 +1068,19 @@ describe('app module', () => { expect(paths).to.deep.equal([true, true, true]); }); - it('returns an assets path that is identical to the exe parent directory', () => { - const assetsPath = app.getPath('assets'); - expect(fs.existsSync(assetsPath)).to.be.true(); - expect(assetsPath).to.equal(path.dirname(app.getPath('exe'))); - }); + if (process.platform === 'darwin') { + it('returns an assets path that is identical to the resources path', () => { + const assetsPath = app.getPath('assets'); + expect(fs.existsSync(assetsPath)).to.be.true(); + expect(assetsPath).to.equal(process.resourcesPath); + }); + } else { + it('returns an assets path that is identical to the module path', () => { + const assetsPath = app.getPath('assets'); + expect(fs.existsSync(assetsPath)).to.be.true(); + expect(assetsPath).to.equal(path.dirname(app.getPath('module'))); + }); + } it('throws an error when the name is invalid', () => { expect(() => { From e92a21dd1412bde645f1ce7ff25fc8dfba5ae63a Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:41 +0000 Subject: [PATCH 5/7] test: Update app.getPath('assets') to expect an exception on Mac Co-authored-by: Will Anderson --- spec/api-app-spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 84753df3a264c..f3817358050f6 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -1069,10 +1069,10 @@ describe('app module', () => { }); if (process.platform === 'darwin') { - it('returns an assets path that is identical to the resources path', () => { - const assetsPath = app.getPath('assets'); - expect(fs.existsSync(assetsPath)).to.be.true(); - expect(assetsPath).to.equal(process.resourcesPath); + it('throws an error when trying to get the assets path on macOS', () => { + expect(() => { + app.getPath('assets' as any); + }).to.throw(/Failed to get 'assets' path/); }); } else { it('returns an assets path that is identical to the module path', () => { From cc1923ae0b9257d63cf2f4ad3c80d35b01b20fb0 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:45 +0000 Subject: [PATCH 6/7] docs: Update docs for 'assets' path to indicate that it's only available on Windows + Linux Co-authored-by: Will Anderson --- docs/api/app.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/app.md b/docs/api/app.md index 91d7508441b76..e70b9016f0eaa 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -602,7 +602,7 @@ Returns `string` - The current application directory. * `%APPDATA%` on Windows * `$XDG_CONFIG_HOME` or `~/.config` on Linux * `~/Library/Application Support` on macOS - * `assets` The directory where app assets such as `resources.pak` are stored. By default this is the same as the folder containing the `exe` path. + * `assets` The directory where app assets such as `resources.pak` are stored. By default this is the same as the folder containing the `exe` path. Available on Windows and Linux only. * `userData` The directory for storing your app's configuration files, which by default is the `appData` directory appended with your app's name. By convention files storing user data should be written to this directory, and From abef8ab0246bef4cb4666650343c89f8e9c8a0ca Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 4 Aug 2025 03:34:49 +0000 Subject: [PATCH 7/7] fix: Don't define 'assets' mapping on macOS Co-authored-by: Will Anderson --- shell/browser/api/electron_api_app.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 7565b6a450c3d..6b5924eb4b5b3 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -383,7 +383,9 @@ int GetPathConstant(std::string_view name) { // clang-format off constexpr auto Lookup = base::MakeFixedFlatMap({ {"appData", DIR_APP_DATA}, +#if !BUILDFLAG(IS_MAC) {"assets", base::DIR_ASSETS}, +#endif #if BUILDFLAG(IS_POSIX) {"cache", base::DIR_CACHE}, #else