Skip to content

Commit

Permalink
fix: create userDataDir on requestSingleInstanceLock() if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
deermichel committed Apr 1, 2022
1 parent b2e7aea commit aa00bfd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions shell/browser/api/electron_api_app.cc
Expand Up @@ -1148,6 +1148,8 @@ bool App::RequestSingleInstanceLock(gin::Arguments* args) {

base::FilePath user_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_dir);
// The user_dir may not have been created yet.
base::CreateDirectoryAndGetError(user_dir, nullptr);

auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
auto wrapped_cb = base::BindRepeating(NotificationCallbackWrapper, cb);
Expand Down
2 changes: 1 addition & 1 deletion spec-main/api-app-spec.ts
Expand Up @@ -228,7 +228,7 @@ describe('app module', () => {
expect(code1).to.equal(0);
});

it.only('returns true when setting non-existent user data folder', async function () {
it('returns true when setting non-existent user data folder', async function () {
const appPath = path.join(fixturesPath, 'api', 'singleton-userdata');
const instance = cp.spawn(process.execPath, [appPath]);
const [code] = await emittedOnce(instance, 'exit');
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/api/singleton-userdata/main.js
Expand Up @@ -2,7 +2,7 @@ const { app } = require('electron');
const fs = require('fs');
const path = require('path');

// non-existing user data folder should not break requestSingleInstanceLock()
// non-existent user data folder should not break requestSingleInstanceLock()
// ref: https://github.com/electron/electron/issues/33547
const userDataFolder = path.join(app.getPath('home'), 'electron-test-singleton-userdata');
fs.rmSync(userDataFolder, { force: true, recursive: true });
Expand Down

0 comments on commit aa00bfd

Please sign in to comment.