diff --git a/background/chrome/index.js b/background/chrome/index.js index 2ff2510..a7d454a 100644 --- a/background/chrome/index.js +++ b/background/chrome/index.js @@ -74,7 +74,7 @@ const prefix = `\n/* Do not edit this section of this file (outside the Browser // The media query seems to "reset" the parser (and doesn't do anything itself). // At the same time it serves as split point when the changes to the files are applied to the local edit files. const infix = `\n/*"*//*'*/;};};};};};}@media not all {} /* reset sequence, do not edit this line */ /*NEXT:${uuid}*/\n`; -const suffix = `/*END:${uuid}*/\n`; +const suffix = `\n/*END:${uuid}*/\n`; // extracts reStyles section from the files. This allows other content to coexist with reStyles managed code const rExtract = RegExpX` (?:^|\n) .* \/\*START:${uuid}\*\/ .*\n ([^]*) \n.*\/\*END:${uuid}\*\/ (?:\n|$) diff --git a/background/local/index.js b/background/local/index.js index 5cc200f..1b10338 100644 --- a/background/local/index.js +++ b/background/local/index.js @@ -84,7 +84,7 @@ async function enable(force) { let files; (await Native.on((onSpawn = async process => { native = (await process.require(require.resolve('./native'))); - files = (await native.readStyles(options.local.children.folder.value, onCange, options.local.children.folder.values.isSet)); + files = (await native.readStyles(options.local.children.folder.value, onCange, options.local.children.folder.values.isSet || force === 'create')); if (options.local.children.chrome.value) { debounceIdle(() => { files && active && native && native.watchChrome(onChromeChange); @@ -93,7 +93,10 @@ async function enable(force) { if (files === null) { { Native.on.removeListener(onSpawn); active = false; letRemoteProceed(); - notify.error(`Can't read local dir`, `The folder "${options.local.children.folder.value}" does not exist or can not be read. To use local styles, create the folder or change it in the options.`); + notify.error(`Can't read local dir`, + `The folder "${options.local.children.folder.value}" does not exist or can not be read.`, + `To use local styles, change the location in the options, create the folder manually or click here to do it automatically.` + ).then(_=>_ && options.local.value && enable('create')); } return; } // console.log('got local styles', files); diff --git a/background/local/native.js b/background/local/native.js index 086cf39..1989764 100644 --- a/background/local/native.js +++ b/background/local/native.js @@ -34,8 +34,8 @@ module.exports = { */ async writeStyle(path, css) { path = normalize(path); if ( - !(/\.css$/).test(path) || (/\/\./).test(path) - || !(await get(FS.access, path, FS.constants.W_OK).then(_=>1,_=>0)) // writable + !(/\/[^.][^/\\]+\.css$/).test(path) + || (await get(FS.access, path, FS.constants.W_OK).then(_=>0/*OK*/,_=>1/*not OK*/)) ) { throw new Error(`Can't write to "${path}"`); } (await get(FS.writeFile, path, css.replace(/\n/g, EOL), 'utf-8')); }, @@ -47,8 +47,8 @@ module.exports = { */ async createStyle(path, css) { path = normalize(path); if ( - !(/\.css$/).test(path) || (/\/\./).test(path) - || !(await get(FS.access, path).catch(_=>true)) // exists + !(/\/[^.][^/\\]+\.css$/).test(path) + || (await get(FS.access, path).then(_=>1/*exists*/, _=>_.code !== 'ENOENT'/*can't write*/)) ) { throw new Error(`Can't create file "${path}"`); } (await get(FS.writeFile, path, css.replace(/\n/g, EOL), { encoding: 'utf-8', flags: 'wx', })); }, @@ -59,8 +59,8 @@ module.exports = { */ async openStyle(path) { path = normalize(path); if ( - !(/\.css$/).test(path) || (/\/\./).test(path) - || (await get(FS.access, path).catch(_=>true)) // !exists + !(/\/[^.][^/\\]+\.css$/).test(path) + || (await get(FS.access, path).then(_=>0/*OK*/,_=>1/*not OK*/)) ) { throw new Error(`Can only open existing non-hidden .css files`); } switch (process.platform) { case 'win32': (await diff --git a/views/panel.js b/views/panel.js index 5ac01a6..369d111 100644 --- a/views/panel.js +++ b/views/panel.js @@ -112,6 +112,9 @@ create.addEventListener('click', async event => { try { name = name.slice(0, -4) +'-'+ Math.random().toString(16).slice(2) +'.css'; path = (await LocalStyle.createStyle(name, file)); } +// notify.success( // clicking the notification doesn't work if it is directly replaced by the restart notification +// `Created new Style at`, path, `Click here to open it!`, +// ).then(_=>_ && LocalStyle.openStyle(name).catch(notify.error)); notify.success(`Created new Style at`, path); LocalStyle.openStyle(name).catch(e => console.error(e)); } catch (error) { notify.error(error); } });