more filepath improvements: relative paths + /opt/notion if /opt/notion-app not present

This commit is contained in:
dragonwocky 2020-07-01 16:48:15 +10:00
parent f20aaf1f4c
commit 382843668a
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
3 changed files with 28 additions and 24 deletions

2
.gitignore vendored
View File

@ -1,3 +1,4 @@
# Logs # Logs
logs logs
*.log *.log
@ -5,6 +6,7 @@ npm-debug.log*
yarn-debug.log* yarn-debug.log*
yarn-error.log* yarn-error.log*
lerna-debug.log* lerna-debug.log*
.vscode
# Diagnostic reports (https://nodejs.org/api/report.html) # Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

View File

@ -56,13 +56,15 @@ try:
f' * {os.path.join(filepath, "app.asar.bak")} was not found: step skipped.') f' * {os.path.join(filepath, "app.asar.bak")} was not found: step skipped.')
if sys.platform == 'linux' and 'microsoft' not in platform.uname()[3].lower(): if sys.platform == 'linux' and 'microsoft' not in platform.uname()[3].lower():
print( bin_path = '/usr/bin/notion-app' if os.path.exists(
f' ...patching app launcher') '/usr/bin/notion-app') else '/usr/bin/notion'
subprocess.call( with open(bin_path, 'r', encoding='UTF-8') as launcher:
['sed', '-i', r's/app/app\.asar/', '/usr/bin/notion-app']) if 'app.asar' not in launcher:
# patch this too just in case print(
subprocess.call(['sed', '-i', r's/app/app\.asar/', f' ...patching app launcher')
os.path.join(filepath, "notion-app")]) subprocess.call(
['sed', '-i', r's/electron\sapp/electron\sapp\.asar/',
bin_path])
print(f'\n{bold}>>> SUCCESSFULLY CLEANED <<<{normal}') print(f'\n{bold}>>> SUCCESSFULLY CLEANED <<<{normal}')

View File

@ -28,20 +28,22 @@ print('=== NOTION ENHANCER CUSTOMISATION LOG ===\n')
try: try:
filepath = '' filepath = ''
__folder__ = os.path.dirname(os.path.realpath(__file__)) __dirname__ = os.path.dirname(__file__)
enhancer_folder = os.path.realpath(__dirname__)
if 'microsoft' in platform.uname()[3].lower() and sys.platform == 'linux': if 'microsoft' in platform.uname()[3].lower() and sys.platform == 'linux':
filepath = '/mnt/c/' + \ filepath = '/mnt/c/' + \
subprocess.run( subprocess.run(
['cmd.exe', '/c', 'echo', '%localappdata%'], stdout=subprocess.PIPE).stdout \ ['cmd.exe', '/c', 'echo', '%localappdata%'], stdout=subprocess.PIPE).stdout \
.rstrip().decode('utf-8')[3:].replace('\\', '/') + '/Programs/Notion/resources' .rstrip().decode('utf-8')[3:].replace('\\', '/') + '/Programs/Notion/resources'
drive = __folder__[5].capitalize() if __folder__.startswith( drive = enhancer_folder[5].capitalize() if enhancer_folder.startswith(
'/mnt/') else 'C' '/mnt/') else 'C'
__folder__ = drive + ':/' + __folder__[6:] enhancer_folder = drive + ':/' + enhancer_folder[6:]
elif sys.platform == 'win32': elif sys.platform == 'win32':
filepath = subprocess.run(['echo', '%localappdata%'], shell=True, capture_output=True).stdout \ filepath = subprocess.run(['echo', '%localappdata%'], shell=True, capture_output=True).stdout \
.rstrip().decode('utf-8') + '\\Programs\\Notion\\resources' .rstrip().decode('utf-8') + '\\Programs\\Notion\\resources'
elif sys.platform == 'linux': elif sys.platform == 'linux':
filepath = '/opt/notion-app' filepath = '/opt/notion-app' if os.path.exists(
'/opt/notion-app') else '/opt/notion'
elif sys.platform == 'darwin': elif sys.platform == 'darwin':
filepath = '/Applications/Notion.app/Contents/Resources' filepath = '/Applications/Notion.app/Contents/Resources'
else: else:
@ -112,11 +114,11 @@ try:
with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append: with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append:
append.write('\n\n') append.write('\n\n')
with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append: with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append:
print(' ...linking to ./resources/user.css') print(
with open('./resources/preload.js', 'r', encoding='UTF-8') as insert: f' ...linking to {os.path.join(".", "resources", "user.css")}')
with open(os.path.join(__dirname__, 'resources', 'preload.js'), 'r', encoding='UTF-8') as insert:
append.write(insert.read().replace( append.write(insert.read().replace(
'☃☃☃assets☃☃☃', __folder__ '☃☃☃assets☃☃☃', enhancer_folder + '/resources'))
+ '/resources'))
else: else:
print( print(
f' * {os.path.join(filepath, "app","renderer","preload.js")} was not found: step skipped.') f' * {os.path.join(filepath, "app","renderer","preload.js")} was not found: step skipped.')
@ -188,16 +190,16 @@ try:
'electron_1.app.on("ready", handleReady);', 'electron_1.app.on("ready", handleReady);',
'electron_1.app.on("ready", () => handleReady() && enhancements());') + '\n') 'electron_1.app.on("ready", () => handleReady() && enhancements());') + '\n')
with open(os.path.join(filepath, "app", "main", "main.js"), 'a', encoding='UTF-8') as append: with open(os.path.join(filepath, "app", "main", "main.js"), 'a', encoding='UTF-8') as append:
with open('./resources/tray.js', 'r', encoding='UTF-8') as insert: with open(os.path.join(__dirname__, 'resources', 'tray.js'), 'r', encoding='UTF-8') as insert:
append.write('\n' + insert.read().replace( append.write('\n' + insert.read().replace(
'☃☃☃hotkey☃☃☃', hotkey)) '☃☃☃hotkey☃☃☃', hotkey))
print( print(
f' ...copying tray icon ./resources/notion.ico to {os.path.join(filepath, "app")}main/') f' ...copying tray icon {os.path.join(".", "resources", "notion.ico")} to {os.path.join(filepath, "app", "main")}')
copyfile('./resources/notion.ico', copyfile(os.path.join(__dirname__, 'resources', 'notion.ico'),
os.path.join(filepath, "app", "main", "notion.ico")) os.path.join(filepath, "app", "main", "notion.ico"))
print( print(
f' ...copying datastore wrapper ./resources/store.js to {os.path.join(filepath, "app")}') f' ...copying datastore wrapper {os.path.join(".", "resources", "store.js")} to {os.path.join(filepath, "app")}')
copyfile('./resources/store.js', copyfile(os.path.join(__dirname__, 'resources', 'store.js'),
os.path.join(filepath, "app", "store.js")) os.path.join(filepath, "app", "store.js"))
else: else:
print( print(
@ -207,10 +209,8 @@ try:
print( print(
f' ...patching app launcher') f' ...patching app launcher')
subprocess.call( subprocess.call(
['sed', '-i', r's/app\.asar/app/', '/usr/bin/notion-app']) ['sed', '-i', r's/electron\sapp\.asar/electron\sapp/',
# patch this too just in case '/usr/bin/notion-app' if os.path.exists('/usr/bin/notion-app') else '/usr/bin/notion'])
subprocess.call(['sed', '-i', r's/app\.asar/app/',
os.path.join(filepath, "notion-app")])
print('\n>>> SUCCESSFULLY CUSTOMISED <<<') print('\n>>> SUCCESSFULLY CUSTOMISED <<<')