Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamezrin committed Jun 22, 2021
0 parents commit 4865f6b
Show file tree
Hide file tree
Showing 13 changed files with 489 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
patches/enhancer-query-selector-fix.patch text eol=lf
patches/enhancer-urlhelper-fix.patch text eol=lf
patches/notion-check-relativeurl.patch text eol=crlf
patches/enhancer-paths.patch text eol=tf
112 changes: 112 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Port sources and Package

on:
push:
branches: [main]

release:
types: [created]

workflow_dispatch:
inputs: {}

env:
NOTION_VERSION: 2.0.16
NOTION_DOWNLOAD_HASH: 9f72284086cda3977f7f569dff3974d5
NOTION_ENHANCER_COMMIT: b248ffa3bac393f267a4600d4e951aba8565f31e

jobs:
make-vanilla-sources:
name: Make vanilla sources
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Download official Windows build
run: scripts/download-exe.sh
- name: Extract sources from Windows Build
run: scripts/extract-src.sh
- name: Zips sources dir with 7z
working-directory: build
run: 7z a vanilla-src.zip vanilla-src
- name: Save vanilla sources as artifact
uses: actions/upload-artifact@v2
with:
name: vanilla-sources
path: build/vanilla-src.zip
make-enhanced-sources:
name: Make enhanced sources
needs: [make-vanilla-sources]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Retrieve saved vanilla sources
uses: actions/download-artifact@v2
with:
name: vanilla-sources
path: build/vanilla-src.zip
- name: Unzips sources with 7z
working-directory: build
run: 7z x vanilla-src.zip
- name: Enhance extracted sources
run: scripts/enhance-src.sh
- name: Zips sources dir with 7z
working-directory: build
run: 7z a enhanced-src.zip enhanced-src
- name: Save enhanced sources as artifact
uses: actions/upload-artifact@v2
with:
name: enhanced-sources
path: build/enhanced-src.zip
build-app:
name: Build electron app
needs: [make-vanilla-sources, make-enhanced-sources]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
edition: [vanilla, enhanced]
exclude:
- os: windows-latest
edition: vanilla
- os: macos-latest
edition: vanilla
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- name: Retrieve saved sources
uses: actions/download-artifact@v2
with:
name: '${{ matrix.edition }}-sources'
path: sources.zip
- name: Unzips sources with 7z
run: 7z x sources.zip
- name: Install build packages
working-directory: ${{ matrix.edition }}-src
run: npm install electron@11 electron-builder --save-dev
- name: Run electron-builder (Windows)
working-directory: ${{ matrix.edition }}-src
if: matrix.os == 'windows-latest'
run: node_modules/.bin/electron-builder --windows nsis
- name: Run electron-builder (Linux)
working-directory: ${{ matrix.edition }}-src
if: matrix.os == 'ubuntu-latest'
run: node_modules/.bin/electron-builder --linux deb rpm AppImage pacman
- name: Run electron-builder (MacOS)
working-directory: ${{ matrix.edition }}-src
if: matrix.os == 'macos-latest'
run: node_modules/.bin/electron-builder --macos dmg
cleanup:
if: ${{ false }}
name: Cleanup artifacts
continue-on-error: true
needs: [build-app]
strategy:
matrix:
edition: [vanilla, enhanced]
runs-on: ubuntu-latest
steps:
- uses: geekyeggo/delete-artifact@v1
with:
name: '${{ matrix.edition }}-sources'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
14.17.1
76 changes: 76 additions & 0 deletions common-electron-builder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
files:
- "build/"
- "package.json"
- "dev-app-update.yml"
- "!node_modules/jschardet/"

extraResources:
- from: "python/dist/main"
to: "python-rpc"
filter:
- "**/*"
- "ThirdPartyNotices.txt"
- "data"
- "i18n"
- "node_modules/jschardet/"

protocols:
- name: "BatchExplorer protocol"
role: "Viewer"
schemes:
- notion
- ms-batch-explorer

# Mac OS configuration
mac:
icon: "src/app/assets/images/icon.icns"

# Config for OSX dmg
dmg:
contents:
- x: 130
y: 220
- x: 410
y: 220
type: "link"
path: "/Applications"

# Windows configuration
win:
icon: "src/app/assets/images/icon.ico"
target:
- "zip"
- "nsis"

# Config for the windows installer
nsis:
oneClick: true
perMachine: true

# Linux configuration
linux:
category: Development
target:
- "AppImage"
- "deb"
- "rpm"

deb:
depends:
# --- Default START
- gconf2
- gconf-service
- libnotify4
- libappindicator1
- libxtst6
- libnss3
# --- Default END
- libsecret-1-0 # This is needed for keytar on linux

directories:
buildResources: "resources"
output: "release"

publish:
provider: "generic"
url: "https://batchlabsdist.blob.core.windows.net/releases"
90 changes: 90 additions & 0 deletions patches/enhancer-paths.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
--- pkg/helpers.js 2021-06-21 22:20:28.538393581 +0200
+++ pkg/helpers.js.new 2021-06-21 22:27:12.478124395 +0200
@@ -19,72 +19,18 @@
}
}

-// checks if being run on the windows subsystem for linux:
-// used to modify windows notion app.
-const is_wsl =
- process.platform === 'linux' &&
- os.release().toLowerCase().includes('microsoft'),
- // ~/.notion-enhancer absolute path.
- __data = path.resolve(
- `${
- is_wsl
- ? (() => {
- const stdout = execSync('cmd.exe /c echo %systemdrive%%homepath%', {
- encoding: 'utf8',
- }),
- drive = stdout[0];
- return `/mnt/${drive.toLowerCase()}${stdout
- .replace(/\\/g, '/')
- .slice(2)
- .trim()}`;
- })()
- : os.homedir()
- }/.notion-enhancer`
- );
+// patched: stripped unnecessary logic for WSL
+// ~/.notion-enhancer absolute path.
+const __data = `${os.homedir()}/.notion-enhancer`

-// transform a wsl filepath to its relative windows filepath if necessary.
+// patched: stripped unnecessary logic for WSL
function realpath(hack_path) {
- if (!is_wsl) return hack_path.replace(/\\/g, '/');
- hack_path = fs.realpathSync(hack_path);
- if (hack_path.startsWith('/mnt/')) {
- hack_path = `${hack_path[5].toUpperCase()}:${hack_path.slice(6)}`;
- } else hack_path = `//wsl$/${process.env.WSL_DISTRO_NAME}${hack_path}`;
- return hack_path;
+ return hack_path.replace(/\\/g, '/');
}

-// gets possible system notion app filepaths.
+// patched: stripped unnecessary logic for runtime path detection
function getNotionResources() {
- let folder = '';
- switch (process.platform) {
- case 'darwin':
- folder = '/Applications/Notion.app/Contents/Resources';
- break;
- case 'win32':
- folder = process.env.LOCALAPPDATA + '\\Programs\\Notion\\resources';
- break;
- case 'linux':
- if (is_wsl) {
- const stdout = execSync('cmd.exe /c echo %localappdata%', {
- encoding: 'utf8',
- }),
- drive = stdout[0];
- folder = `/mnt/${drive.toLowerCase()}${stdout
- .replace(/\\/g, '/')
- .slice(2)
- .trim()}/Programs/Notion/resources`;
- } else {
- for (let loc of [
- '/usr/lib/notion-desktop/resources', // https://github.com/davidbailey00/notion-deb-builder/
- '/opt/notion-app', // https://aur.archlinux.org/packages/notion-app/
- '/opt/notion', // https://github.com/jaredallard/notion-app
- ]) {
- if (fs.pathExistsSync(loc)) folder = loc;
- }
- }
- }
- if (!folder)
- throw new EnhancerError('nothing found: platform not supported.');
- return folder;
+ return path.resolve(__dirname, '../../../');
}

// lists/fetches all available extensions + themes
@@ -184,7 +130,6 @@

module.exports = {
EnhancerError,
- is_wsl,
__data,
realpath,
getNotionResources,
11 changes: 11 additions & 0 deletions patches/enhancer-query-selector-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- mods/core/client.js 2021-04-28 23:47:55.867684760 +0200
+++ mods/core/client.js.new 2021-04-28 23:58:26.305652911 +0200
@@ -105,7 +105,7 @@
if (
!document.querySelector('.notion-frame') ||
!document.querySelector('.notion-sidebar') ||
- !document.querySelector('.notion-topbar')
+ !document.querySelector('.notion-topbar > div[style*="display: flex"]')
)
return;
clearInterval(attempt_interval);
13 changes: 13 additions & 0 deletions patches/enhancer-urlhelper-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- mods/core/createWindow.js 2021-04-28 23:47:55.867684760 +0200
+++ mods/core/createWindow.js.new 2021-04-28 23:59:51.891726201 +0200
@@ -16,6 +16,10 @@
// createWindow = __exports.createWindow,
path = require('path'),
helpers = require('../../pkg/helpers.js');
+
+ __exports.getIndexUrl = require(`${helpers
+ .getNotionResources()
+ .replace(/\\/g, '/')}/app/helpers/urlHelpers.js`).getIndexUrl;

__exports.createWindow = function (relativeUrl, focused_window) {
if (!relativeUrl) relativeUrl = '';
11 changes: 11 additions & 0 deletions patches/notion-check-relativeurl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- main/main.js 2021-04-28 23:47:55.854352025 +0200
+++ main/main.js.new 2021-04-28 23:55:08.414711920 +0200
@@ -170,7 +170,7 @@
notionIpc.sendMainToNotionWindow(targetWindow, "notion:navigate-to-url", relativeUrl);
targetWindow.focus();
}
- else {
+ else if (relativeUrl) {
const win = createWindow_1.createWindow(relativeUrl);
win.focus();
}
33 changes: 33 additions & 0 deletions scripts/_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

WORKSPACE_DIR=`realpath $(dirname $0)/..`

NOTION_VERSION="${NOTION_VERSION:-2.0.16}"
NOTION_DOWNLOAD_HASH="${NOTION_DOWNLOAD_HASH:-9f72284086cda3977f7f569dff3974d5}"
NOTION_DOWNLOAD_URL="https://desktop-release.notion-static.com/Notion%20Setup%20${NOTION_VERSION}.exe"
NOTION_DOWNLOADED_NAME="Notion-${NOTION_VERSION}.exe"

NOTION_ENHANCER_COMMIT="${NOTION_ENHANCER_COMMIT:-b248ffa3bac393f267a4600d4e951aba8565f31e}"
NOTION_ENHANCER_REPO_URL="https://github.com/notion-enhancer/notion-enhancer"

NOTION_EXTRACTED_EXE_NAME="extracted-exe"
NOTION_EXTRACTED_APP_NAME="extracted-app"
NOTION_VANILLA_SRC_NAME="vanilla-src"
NOTION_ENHANCED_SRC_NAME="enhanced-src"
NOTION_EMBEDDED_NAME="embedded_enhancer"

function log() {
caller=`basename "$0"`
echo "[${caller%.*}]: $@"
}

function check-cmd() {
if ! command -v $1 > /dev/null; then
log "Missing required command dependency: $1"
exit -1
fi
}

function workspace-dir-pushd() {
mkdir -p "${WORKSPACE_DIR}/build"
pushd "${WORKSPACE_DIR}/build" > /dev/null
}
20 changes: 20 additions & 0 deletions scripts/download-exe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -ex

source `dirname $0`/_utils.sh
workspace-dir-pushd

check-cmd curl

if [ -f "${NOTION_DOWNLOADED_NAME}" ]; then
log "Removing already downloaded file..."
rm "${NOTION_DOWNLOADED_NAME}"
fi

log "Downloading Notion Windows package..."
curl "${NOTION_DOWNLOAD_URL}" --output "${NOTION_DOWNLOADED_NAME}"

log "Verifying downloaded package checksum..."
echo "${NOTION_DOWNLOAD_HASH} ${NOTION_DOWNLOADED_NAME}" | md5sum --check -

popd > /dev/null
Loading

0 comments on commit 4865f6b

Please sign in to comment.