Skip to content

Commit

Permalink
Merge pull request #383 from ThaUnknown/node-js-mobile
Browse files Browse the repository at this point in the history
feat: node js mobile
  • Loading branch information
ThaUnknown authored Dec 7, 2023
2 parents d3c68d0 + d4b8295 commit df3fc91
Show file tree
Hide file tree
Showing 22 changed files with 657 additions and 2,111 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "capacitor/git_modules/nodejs-mobile"]
path = capacitor/git_modules/nodejs-mobile
url = https://github.com/nodejs-mobile/nodejs-mobile
7 changes: 0 additions & 7 deletions capacitor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ android/app/src/*
!android/app/src/main
android/app/src/main/*
!android/app/src/main/AndroidManifest.xml
!android/app/src/main/java
android/app/src/main/java/*
!android/app/src/main/java/watch
android/app/src/main/java/watch/*
!android/app/src/main/java/watch/miru
android/app/src/main/java/watch/miru/*
!android/app/src/main/java/watch/miru/MainActivity.java
ios/

package-lock.json
Expand Down
31 changes: 0 additions & 31 deletions capacitor/android/app/src/main/java/watch/miru/MainActivity.java

This file was deleted.

7 changes: 5 additions & 2 deletions capacitor/capacitor.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const config = {
appId: 'watch.miru',
appName: 'Miru',
webDir: 'build',
bundledWebRuntime: false,
android: {
buildOptions: {
keystorePath: './watch.miru',
Expand All @@ -14,7 +13,11 @@ const config = {
},
plugins: {
SplashScreen: { launchShowDuration: 0 },
CapacitorHttp: { enabled: false }
CapacitorHttp: { enabled: false },
CapacitorNodeJS: { nodeDir: 'nodejs' }
},
server: {
cleartext: true
}
}

Expand Down
48 changes: 48 additions & 0 deletions capacitor/config-node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# instructions
# Install Android NDK
# Set $ANDROID_NDK_PATH (example: ~/Android/Sdk/ndk/26.1.10909125)
# install other npm packages like normal
# run this script

toolchain_target_arch=aarch64
node_target_arch=arm64
android_api_level=22
toolchain_folder=$ANDROID_NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin
export LIBNODE_PATH=$(pwd)/git_modules/nodejs-mobile

export PATH=$toolchain_folder:$PATH

export CC=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang
export CXX=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export LINK=$toolchain_folder/${toolchain_target_arch}-linux-android${android_api_level}-clang++
export AR=$toolchain_folder/llvm-ar

export npm_config_verbose=1
export npm_config_nodedir=${LIBNODE_PATH}
export npm_config_node_gyp=$(pwd)/../node_modules/nodejs-mobile-gyp/bin/node-gyp.js
export npm_config_arch=${node_target_arch}
export npm_config_plaform=android
export npm_config_format=make-android
export npm_gyp_defines="target_arch=$node_target_arch v8_target_arch=$node_target_arch android_target_arch=$node_target_arch host_os=linux OS=android"

#mv node_modules ../node_modules.bak
# --from-from-source is used by node-pre-gyp
cd public/nodejs
npm rebuild --build-from-source
# Remove executable permissions from native node modules
# find node_modules -iname '*.node' -exec chmod -x '{}' \;

# buildroot=$(pwd)/ncc
# target=arm64-android

# buildpath="${buildroot}/${target}"
# if [ ! -d "${buildpath}" ]; then
# mkdir -p "${buildpath}"
# fi

# ncc build --source-map -d --asset-builds --target es2022 -o ${buildpath} src/offline.ts

# rm -rf node_modules
# mv ../node_modules.bak node_modules
24 changes: 6 additions & 18 deletions capacitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "capacitor",
"private": true,
"scripts": {
"postinstall": "cd public/nodejs/ && npm install",
"build:app": "cross-env NODE_ENV=production run-s build:web build:assets build:android",
"build:web": "webpack build",
"build:android": "cap build android",
Expand All @@ -18,21 +19,14 @@
},
"devDependencies": {
"@capacitor/assets": "^3.0.1",
"assert": "^2.1.0",
"buffer": "^6.0.3",
"chrome-dgram": "^3.0.6",
"chrome-net": "^3.3.4",
"cordova-res": "^0.15.4",
"crypto-browserify": "^3.12.0",
"hybrid-chunk-store": "^1.2.2",
"nodejs-mobile-gyp": "^0.3.1",
"npm-run-all": "^4.1.5",
"path-esm": "^1.0.0",
"querystring": "^0.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"timers-browserify": "^2.0.12",
"util": "^0.12.5",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0"
},
"dependencies": {
"@capacitor/android": "^5.5.1",
Expand All @@ -42,17 +36,11 @@
"@capacitor/core": "^5.5.1",
"@capacitor/ios": "^5.5.1",
"@capacitor/status-bar": "^5.0.6",
"@superfrogbe/cordova-plugin-chrome-apps-sockets-udp": "github:superfrogbe/cordova-plugin-chrome-apps-sockets-udp",
"capacitor-default-gateway": "github:funniray/capacitor-default-gateway",
"capacitor-dns": "github:funniray/capacitor-dns",
"capacitor-os-interfaces-hack": "github:funniray/capacitor-os-interfaces-hack",
"capacitor-nodejs": "https://github.com/hampoelz/capacitor-nodejs/releases/download/v1.0.0-beta.6/capacitor-nodejs.tgz",
"capacitor-plugin-safe-area": "^2.0.5",
"common": "workspace:*",
"cordova-plugin-chrome-apps-common": "^1.0.7",
"cordova-plugin-chrome-apps-sockets-tcp": "github:KoenLav/cordova-plugin-chrome-apps-sockets-tcp",
"cordova-plugin-navigationbar": "^1.0.31",
"cordova-plugin-screen-orientation": "^3.0.4",
"es6-promise-plugin": "^4.2.2",
"webpack-merge": "^5.10.0"
"es6-promise-plugin": "^4.2.2"
}
}
9 changes: 9 additions & 0 deletions capacitor/public/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "nodejs-capacitor-thread",
"private": true,
"dependencies": {
"utp-native": "^2.5.3"
},
"version": "1.0.0",
"main": "./index.js"
}
4 changes: 2 additions & 2 deletions capacitor/src/capacitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { StatusBar, Style } from '@capacitor/status-bar'
import { SafeArea } from 'capacitor-plugin-safe-area'
import { App } from '@capacitor/app'
import { Browser } from '@capacitor/browser'
import { ipcRendererUI, main } from './ipc.js'
// import { ipcRendererUI, main } from './ipc.js'

main.on('open', url => Browser.open({ url }))
// main.on('open', url => Browser.open({ url }))

App.addListener('appUrlOpen', ({ url }) => handleProtocol(url))

Expand Down
Loading

0 comments on commit df3fc91

Please sign in to comment.