From 382843668af8dc88ddc8c2607d38dce51634f0f4 Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Wed, 1 Jul 2020 16:48:15 +1000 Subject: [PATCH] more filepath improvements: relative paths + /opt/notion if /opt/notion-app not present --- .gitignore | 2 ++ cleaner.py | 16 +++++++++------- customiser.py | 34 +++++++++++++++++----------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 6704566..67c8fa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ + # Logs logs *.log @@ -5,6 +6,7 @@ npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* +.vscode # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/cleaner.py b/cleaner.py index 04c01f6..7a5ef4c 100644 --- a/cleaner.py +++ b/cleaner.py @@ -56,13 +56,15 @@ try: 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(): - print( - f' ...patching app launcher') - subprocess.call( - ['sed', '-i', r's/app/app\.asar/', '/usr/bin/notion-app']) - # patch this too just in case - subprocess.call(['sed', '-i', r's/app/app\.asar/', - os.path.join(filepath, "notion-app")]) + bin_path = '/usr/bin/notion-app' if os.path.exists( + '/usr/bin/notion-app') else '/usr/bin/notion' + with open(bin_path, 'r', encoding='UTF-8') as launcher: + if 'app.asar' not in launcher: + print( + f' ...patching app launcher') + subprocess.call( + ['sed', '-i', r's/electron\sapp/electron\sapp\.asar/', + bin_path]) print(f'\n{bold}>>> SUCCESSFULLY CLEANED <<<{normal}') diff --git a/customiser.py b/customiser.py index f9d99c5..3b0ae3e 100755 --- a/customiser.py +++ b/customiser.py @@ -28,20 +28,22 @@ print('=== NOTION ENHANCER CUSTOMISATION LOG ===\n') try: 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': filepath = '/mnt/c/' + \ subprocess.run( ['cmd.exe', '/c', 'echo', '%localappdata%'], stdout=subprocess.PIPE).stdout \ .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' - __folder__ = drive + ':/' + __folder__[6:] + enhancer_folder = drive + ':/' + enhancer_folder[6:] elif sys.platform == 'win32': filepath = subprocess.run(['echo', '%localappdata%'], shell=True, capture_output=True).stdout \ .rstrip().decode('utf-8') + '\\Programs\\Notion\\resources' 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': filepath = '/Applications/Notion.app/Contents/Resources' else: @@ -112,11 +114,11 @@ try: with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append: append.write('\n\n') with open(os.path.join(filepath, "app", "renderer", "preload.js"), 'a', encoding='UTF-8') as append: - print(' ...linking to ./resources/user.css') - with open('./resources/preload.js', 'r', encoding='UTF-8') as insert: + print( + 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( - '☃☃☃assets☃☃☃', __folder__ - + '/resources')) + '☃☃☃assets☃☃☃', enhancer_folder + '/resources')) else: print( 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() && enhancements());') + '\n') 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( '☃☃☃hotkey☃☃☃', hotkey)) print( - f' ...copying tray icon ./resources/notion.ico to {os.path.join(filepath, "app")}main/') - copyfile('./resources/notion.ico', + f' ...copying tray icon {os.path.join(".", "resources", "notion.ico")} to {os.path.join(filepath, "app", "main")}') + copyfile(os.path.join(__dirname__, 'resources', 'notion.ico'), os.path.join(filepath, "app", "main", "notion.ico")) print( - f' ...copying datastore wrapper ./resources/store.js to {os.path.join(filepath, "app")}') - copyfile('./resources/store.js', + f' ...copying datastore wrapper {os.path.join(".", "resources", "store.js")} to {os.path.join(filepath, "app")}') + copyfile(os.path.join(__dirname__, 'resources', 'store.js'), os.path.join(filepath, "app", "store.js")) else: print( @@ -207,10 +209,8 @@ try: print( f' ...patching app launcher') subprocess.call( - ['sed', '-i', r's/app\.asar/app/', '/usr/bin/notion-app']) - # patch this too just in case - subprocess.call(['sed', '-i', r's/app\.asar/app/', - os.path.join(filepath, "notion-app")]) + ['sed', '-i', r's/electron\sapp\.asar/electron\sapp/', + '/usr/bin/notion-app' if os.path.exists('/usr/bin/notion-app') else '/usr/bin/notion']) print('\n>>> SUCCESSFULLY CUSTOMISED <<<')