sign cli cmd (macos), bugfix error printing, fs dep on __enhancerElectronApi, actually apply systemMenu patch

This commit is contained in:
dragonwocky 2021-12-13 13:36:06 +11:00
parent 3af07ca21a
commit b8647deede
Signed by: dragonwocky
GPG Key ID: 86DFC3C312A56010
9 changed files with 80 additions and 30 deletions

View File

@ -20,6 +20,9 @@ a complete redesign & rewrite of the enhancer, with new features and a port to t
- an open on startup option under the tray mod.
- optional icon or title-only tab labels.
- choice of tab layout styles: traditional tabbed, traditional, bubble and compact.
- a hotkey for reopening closed tabs.
- an option to remember last open tabs for a continue-where-you-left-off experience
(recently active tabs are reopened after an app relaunch).
#### improved
@ -41,10 +44,12 @@ a complete redesign & rewrite of the enhancer, with new features and a port to t
with an option to truncate timeline item titles.
- renamed "notion icons" to "icon sets" with new support for uploading/reusing custom icons
directly within the icon picker.
- cli can now detect and apply to user-only installations on macOS.
- moved the tray to its own configurable and enable/disable-able mod, with window management enhancements
that follow more sensible defaults and work more reliably.
- tabs will auto shrink/expand to take up available space instead of wrapping to a second line.
- a visually revamped cli to more clearly and aesthetically communicate status and usage.
- cli can now detect and apply to user-only installations on macOS.
- a shortcut built into the cli to fix the "you do not have permission to open this app" error on macos.
#### removed

30
bin.mjs
View File

@ -16,6 +16,7 @@ import { line, options, log, help, args, lastSpinner } from './pkg/cli.mjs';
import apply from './pkg/apply.mjs';
import remove from './pkg/remove.mjs';
import check from './pkg/check.mjs';
import sign from './pkg/sign.mjs';
const manifest = pkg(),
opts = options({
@ -36,6 +37,7 @@ const displayHelp = () => {
['apply', 'add enhancements to the notion app'],
['remove', 'return notion to its pre-enhanced/pre-modded state'],
['check, status', 'check the current state of the notion app'],
['sign', '[macos only] fix the "you do not have permission to open this app" error'],
],
options: [
['-y, --yes', 'skip prompts'],
@ -72,22 +74,22 @@ function handleError(err) {
stack = err.stack.split('\n');
for (let i = 0; i < stack.length; i++) {
const text = stack[i].replace(/^ /, ' ');
if (i > 1) {
strs.push('{grey ');
tags.push(text);
strs.push('}');
tags.push('');
} else if (i > 0) {
strs.push('');
tags.push(text);
} else {
if (i === 0) {
const [type, msg] = text.split(/:((.+)|$)/);
strs.push('{bold.red ');
tags.push(type);
strs.push(':} ');
tags.push(msg);
} else {
strs.push('{grey ');
tags.push(text);
strs.push('}');
tags.push('');
}
if (i !== stack.length - 1) {
strs.push('\n');
tags.push('');
}
strs.push(i !== stack.length - 1 ? '\n' : '');
}
log(strs, ...tags);
} else {
@ -133,6 +135,14 @@ try {
}
break;
}
case 'sign': {
log`{bold.rgb(245,245,245) [NOTION-ENHANCER] SIGN}`;
const res = await sign(notionPath);
if (res) {
log`{bold.rgb(245,245,245) SUCCESS} {green ✔}`;
} else log`{bold.rgb(245,245,245) CANCELLED} {red ✘}`;
break;
}
default:
displayHelp();
}

@ -1 +1 @@
Subproject commit f5613ab6b1ca4abffb597a81433a1557fc642533
Subproject commit cf0c26434f8085823d1add0390befbb899866423

24
insert/env/fs.mjs vendored
View File

@ -11,6 +11,13 @@
* @module notion-enhancer/api/fs
*/
/**
* get an absolute path to files within notion
* @param {string} path - relative to the root notion/resources/app/ e.g. renderer/search.js
* @runtime electron
*/
export const notionPath = globalThis.__enhancerElectronApi.notionPath;
/**
* transform a path relative to the enhancer root directory into an absolute path
* @param {string} path - a url or within-the-enhancer filepath
@ -42,9 +49,8 @@ export const getJSON = (path, opts = {}) => {
export const getText = (path, opts = {}) => {
if (path.startsWith('http')) return fetch(path, opts).then((res) => res.text());
try {
const fs = globalThis.__enhancerElectronApi.nodeRequire('fs'),
{ resolve: resolvePath } = globalThis.__enhancerElectronApi.nodeRequire('path');
return fs.readFileSync(resolvePath(`${__dirname}/../../${path}`));
const fs = globalThis.__enhancerElectronApi.nodeRequire('fs');
return fs.readFileSync(notionPath(`notion-enhancer/${path}`));
} catch (err) {
return fetch(localPath(path), opts).then((res) => res.text());
}
@ -57,13 +63,12 @@ export const getText = (path, opts = {}) => {
*/
export const isFile = async (path) => {
try {
const fs = globalThis.__enhancerElectronApi.nodeRequire('fs'),
{ resolve: resolvePath } = globalThis.__enhancerElectronApi.nodeRequire('path');
const fs = globalThis.__enhancerElectronApi.nodeRequire('fs');
if (path.startsWith('http')) {
await fetch(path);
} else {
try {
fs.existsSync(resolvePath(`${__dirname}/../../${path}`));
fs.existsSync(notionPath(`notion-enhancer/${path}`));
} catch (err) {
await fetch(localPath(path));
}
@ -73,10 +78,3 @@ export const isFile = async (path) => {
return false;
}
};
/**
* get an absolute path to files within notion
* @param {string} path - relative to the root notion/resources/app/ e.g. renderer/search.js
* @runtime electron
*/
export const notionPath = globalThis.__enhancerElectronApi.notionPath;

@ -1 +1 @@
Subproject commit 2f602a34b3293a7ece50dfa2bc8d22997102e65f
Subproject commit 635b0815f0bcdf0afceb6200110f634ab7e6bd89

View File

@ -51,7 +51,7 @@ export default async function (
asar.extractAll(status.executable, status.executable.replace(/\.asar$/, ''));
s.stop();
}
if (takeBackup) {
if (status.code === 0 && takeBackup) {
s = spinner(' * backing up default app').loop();
if (status.executable.endsWith('.asar')) {
await fsp.rename(status.executable, status.executable + '.bak');
@ -63,7 +63,7 @@ export default async function (
}
s = spinner(' * inserting enhancements').loop();
if (!(status.code === 2 && applyDevPatch)) {
if (status.code === 0) {
const notionFiles = (await readDirDeep(status.executable))
.map((file) => file.path)
.filter((file) => file.endsWith('.js') && !file.includes('node_modules'));

View File

@ -30,6 +30,15 @@ export default function (notionFolder = findNotion()) {
executable: executable ? resolvePath(executable) : undefined,
backup: backup ? resolvePath(backup) : undefined,
cache: fs.existsSync(insertCache) ? insertCache : undefined,
installation: path.resolve(
resolvePath('.')
.split(path.sep)
.reduceRight((prev, val) => {
if (val.toLowerCase().includes('notion') || prev.toLowerCase().includes('notion'))
prev = `${val}/${prev}`;
return prev;
}, '')
),
};
if (insert) {
if (insertVersion === enhancerVersion) {

View File

@ -14,8 +14,8 @@ export default async function (filepath) {
await fsp.writeFile(
filepath,
contents.replace(
/\}\nexports\.setupSystemMenu = setupSystemMenu;/g,
'return template;}\nexports.setupSystemMenu = setupSystemMenu;'
/electron_1\.Menu\.setApplicationMenu\(menu\);/g,
'electron_1.Menu.setApplicationMenu(menu); return template;'
)
);
return true;

28
pkg/sign.mjs Normal file
View File

@ -0,0 +1,28 @@
/**
* notion-enhancer
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (https://notion-enhancer.github.io/) under the MIT license
*/
import { log } from './cli.mjs';
import { findNotion } from './helpers.mjs';
import { execSync } from 'child_process';
import check from './check.mjs';
export default async function (notionFolder = findNotion()) {
const status = check(notionFolder);
if (process.platform === 'darwin') {
log` {grey * app re-signing is only available on macos: exiting}`;
return false;
}
if (status.code > 1 && status.executable) {
log` {grey * installing xcode cli tools}`;
execSync('xcode-select --install');
log` {grey * codesigning app directory}`;
execSync(`codesign --force --deep --sign - ${status.installation}`);
} else log` {grey * enhancements not found: skipping}`;
return true;
}