fix: use mutex to prevent data race around electron singleton
Some checks failed
Playwright Tests / test (push) Failing after 2m0s
Some checks failed
Playwright Tests / test (push) Failing after 2m0s
This commit is contained in:
parent
8ed3faea13
commit
93d765d248
@ -8,6 +8,7 @@
|
|||||||
"@codemirror/view": "^6.0.1",
|
"@codemirror/view": "^6.0.1",
|
||||||
"@playwright/test": "^1.58.2",
|
"@playwright/test": "^1.58.2",
|
||||||
"asar": "^3.2.0",
|
"asar": "^3.2.0",
|
||||||
|
"async-mutex": "^0.5.0",
|
||||||
"electron": "^33.0.2",
|
"electron": "^33.0.2",
|
||||||
"obsidian": "latest",
|
"obsidian": "latest",
|
||||||
"playwright": "^1.58.2",
|
"playwright": "^1.58.2",
|
||||||
|
|||||||
@ -1,22 +1,26 @@
|
|||||||
import type { ElectronApplication } from "playwright"
|
import type { ElectronApplication } from "playwright"
|
||||||
import {_electron as electron} from "playwright";
|
import {_electron as electron} from "playwright";
|
||||||
import { addConsoleListener } from "./internal-util.js";
|
import { addConsoleListener } from "./internal-util.js";
|
||||||
|
import { Mutex } from "async-mutex";
|
||||||
|
|
||||||
const singleton: {
|
const singleton: {
|
||||||
app: ElectronApplication | null
|
app: ElectronApplication | null
|
||||||
} = {
|
} = {
|
||||||
app: null,
|
app: null,
|
||||||
}
|
}
|
||||||
|
const mutex = new Mutex();
|
||||||
|
|
||||||
export async function getOrCreateApp(obsidianPath: string, uriArg?: string) {
|
export async function getOrCreateApp(obsidianPath: string, uriArg?: string) {
|
||||||
if (singleton.app) {
|
if (singleton.app) {
|
||||||
return singleton.app;
|
return singleton.app;
|
||||||
}
|
}
|
||||||
|
const release =await mutex.acquire();
|
||||||
const app = await electron.launch({
|
const app = await electron.launch({
|
||||||
timeout: 60000,
|
timeout: 60000,
|
||||||
args: [obsidianPath, uriArg].filter((a) => !!a) as string[],
|
args: [obsidianPath, uriArg].filter((a) => !!a) as string[],
|
||||||
});
|
});
|
||||||
addConsoleListener(app);
|
addConsoleListener(app);
|
||||||
singleton.app = app;
|
singleton.app = app;
|
||||||
|
await release();
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|||||||
17
yarn.lock
17
yarn.lock
@ -1139,6 +1139,15 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"async-mutex@npm:^0.5.0":
|
||||||
|
version: 0.5.0
|
||||||
|
resolution: "async-mutex@npm:0.5.0"
|
||||||
|
dependencies:
|
||||||
|
tslib: "npm:^2.4.0"
|
||||||
|
checksum: 10c0/9096e6ad6b674c894d8ddd5aa4c512b09bb05931b8746ebd634952b05685608b2b0820ed5c406e6569919ff5fe237ab3c491e6f2887d6da6b6ba906db3ee9c32
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"balanced-match@npm:^1.0.0":
|
"balanced-match@npm:^1.0.0":
|
||||||
version: 1.0.2
|
version: 1.0.2
|
||||||
resolution: "balanced-match@npm:1.0.2"
|
resolution: "balanced-match@npm:1.0.2"
|
||||||
@ -2626,6 +2635,7 @@ __metadata:
|
|||||||
"@playwright/test": "npm:^1.58.2"
|
"@playwright/test": "npm:^1.58.2"
|
||||||
"@types/tmp": "npm:^0"
|
"@types/tmp": "npm:^0"
|
||||||
asar: "npm:^3.2.0"
|
asar: "npm:^3.2.0"
|
||||||
|
async-mutex: "npm:^0.5.0"
|
||||||
electron: "npm:^33.0.2"
|
electron: "npm:^33.0.2"
|
||||||
obsidian: "npm:latest"
|
obsidian: "npm:latest"
|
||||||
playwright: "npm:^1.58.2"
|
playwright: "npm:^1.58.2"
|
||||||
@ -3284,6 +3294,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"tslib@npm:^2.4.0":
|
||||||
|
version: 2.8.1
|
||||||
|
resolution: "tslib@npm:2.8.1"
|
||||||
|
checksum: 10c0/9c4759110a19c53f992d9aae23aac5ced636e99887b51b9e61def52611732872ff7668757d4e4c61f19691e36f4da981cd9485e869b4a7408d689f6bf1f14e62
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"tsutils@npm:^3.21.0":
|
"tsutils@npm:^3.21.0":
|
||||||
version: 3.21.0
|
version: 3.21.0
|
||||||
resolution: "tsutils@npm:3.21.0"
|
resolution: "tsutils@npm:3.21.0"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user