mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-19 19:19:03 +00:00
use async fs methods in apply.js
should avoid potential race conditions
This commit is contained in:
parent
7082899f86
commit
336d8bd980
44
pkg/apply.js
44
pkg/apply.js
@ -66,7 +66,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
|||||||
console.info(' ...unpacking app.asar.');
|
console.info(' ...unpacking app.asar.');
|
||||||
const asar_bak = path.resolve(`${__notion}/app.asar.bak`);
|
const asar_bak = path.resolve(`${__notion}/app.asar.bak`);
|
||||||
extractAll(check_app.executable, `${path.resolve(`${__notion}/app`)}`);
|
extractAll(check_app.executable, `${path.resolve(`${__notion}/app`)}`);
|
||||||
if (await fs.pathExists(asar_bak)) fs.remove(asar_bak);
|
if (await fs.pathExists(asar_bak)) await fs.remove(asar_bak);
|
||||||
await fs.move(check_app.executable, asar_bak);
|
await fs.move(check_app.executable, asar_bak);
|
||||||
} else {
|
} else {
|
||||||
console.info(' ...backing up default app.');
|
console.info(' ...backing up default app.');
|
||||||
@ -104,7 +104,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
|||||||
process.platform === 'darwin' &&
|
process.platform === 'darwin' &&
|
||||||
(await fs.pathExists(path.resolve(`${__notion}/../Info.plist`)))
|
(await fs.pathExists(path.resolve(`${__notion}/../Info.plist`)))
|
||||||
) {
|
) {
|
||||||
fs.copy(
|
await fs.copy(
|
||||||
path.resolve(`${__dirname}/Info.plist`),
|
path.resolve(`${__dirname}/Info.plist`),
|
||||||
path.resolve(`${__notion}/../Info.plist`),
|
path.resolve(`${__notion}/../Info.plist`),
|
||||||
{ overwrite: true }
|
{ overwrite: true }
|
||||||
@ -124,27 +124,25 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
|||||||
if (insertion_target === 'main/main.js') {
|
if (insertion_target === 'main/main.js') {
|
||||||
// https://github.com/notion-enhancer/notion-enhancer/issues/160
|
// https://github.com/notion-enhancer/notion-enhancer/issues/160
|
||||||
// patch the notion:// url scheme/protocol to work on linux
|
// patch the notion:// url scheme/protocol to work on linux
|
||||||
fs.readFile(insertion_file, 'utf8', (err, data) => {
|
const data = await fs.readFile(insertion_file, 'utf8');
|
||||||
if (err) throw err;
|
await fs.writeFile(
|
||||||
fs.writeFile(
|
insertion_file,
|
||||||
insertion_file,
|
data
|
||||||
data
|
.replace(
|
||||||
.replace(
|
/process.platform === "win32"/g,
|
||||||
/process.platform === "win32"/g,
|
'process.platform === "win32" || process.platform === "linux"'
|
||||||
'process.platform === "win32" || process.platform === "linux"'
|
)
|
||||||
)
|
.replace(
|
||||||
.replace(
|
/else \{[\s\n]+const win = createWindow_1\.createWindow\(relativeUrl\);/g,
|
||||||
/else \{[\s\n]+const win = createWindow_1\.createWindow\(relativeUrl\);/g,
|
'else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);'
|
||||||
'else if (relativeUrl) { const win = createWindow_1.createWindow(relativeUrl);'
|
),
|
||||||
),
|
'utf8',
|
||||||
'utf8',
|
(err) => {
|
||||||
(err) => {
|
if (err) throw err;
|
||||||
if (err) throw err;
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
fs.appendFile(
|
await fs.appendFile(
|
||||||
insertion_file,
|
insertion_file,
|
||||||
`\n\n//notion-enhancer\nrequire('notion-enhancer/pkg/loader.js')(__filename, exports);`
|
`\n\n//notion-enhancer\nrequire('notion-enhancer/pkg/loader.js')(__filename, exports);`
|
||||||
);
|
);
|
||||||
@ -153,7 +151,7 @@ module.exports = async function ({ overwrite_version, friendly_errors } = {}) {
|
|||||||
// not resolved, nothing else in apply process depends on it
|
// not resolved, nothing else in apply process depends on it
|
||||||
// so it's just a "let it do its thing"
|
// so it's just a "let it do its thing"
|
||||||
console.info(' ...recording enhancement version.');
|
console.info(' ...recording enhancement version.');
|
||||||
fs.outputFile(
|
await fs.outputFile(
|
||||||
path.resolve(`${__notion}/app/ENHANCER_VERSION.txt`),
|
path.resolve(`${__notion}/app/ENHANCER_VERSION.txt`),
|
||||||
version
|
version
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user