From aa00bfda5f432a22638574b21011e130cbd8ef02 Mon Sep 17 00:00:00 2001 From: Micha Hanselmann Date: Fri, 1 Apr 2022 10:19:30 +0200 Subject: [PATCH] fix: create userDataDir on requestSingleInstanceLock() if needed --- shell/browser/api/electron_api_app.cc | 2 ++ spec-main/api-app-spec.ts | 2 +- spec/fixtures/api/singleton-userdata/main.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index 73db1e756f885..e3a88a28b0872 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -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); diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index 98b7b8ac2778f..0389b70931a07 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -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'); diff --git a/spec/fixtures/api/singleton-userdata/main.js b/spec/fixtures/api/singleton-userdata/main.js index 6b9a33cc1ac08..98f6841b4282a 100644 --- a/spec/fixtures/api/singleton-userdata/main.js +++ b/spec/fixtures/api/singleton-userdata/main.js @@ -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 });