Skip to content

Commit

Permalink
Merge pull request #65 from fullstackedorg/android
Browse files Browse the repository at this point in the history
Android
  • Loading branch information
cplepage authored Sep 6, 2024
2 parents 113468f + 44eb1cb commit acd3630
Show file tree
Hide file tree
Showing 63 changed files with 2,452 additions and 95 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ Use some of the most popular tools to rapidly build.
Available on

- iOS/iPadOS
- Android
- MacOS
- Windows
- Linux
- Docker
- Android `Soon`
2 changes: 1 addition & 1 deletion build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (textBlockToUpdate) {
throw "Could not find typescript code block to patch.";
}

const baseFile = "src/js/index.js";
const baseFile = "src/js/base.js";

esbuild.buildSync({
entryPoints: ["src/index.ts"],
Expand Down
2 changes: 1 addition & 1 deletion editor-sample-demo
7 changes: 3 additions & 4 deletions editor/api/connectivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const connectivityAPI = {
]
.flat()
.filter(({ peer: { id } }) => {
if (seenPeerID.has(id)) return false;
if (id === me.id || seenPeerID.has(id)) return false;
seenPeerID.add(id);
return true;
});
Expand Down Expand Up @@ -226,7 +226,7 @@ const connectivityAPI = {
rpc().connectivity.advertise.stop();
}
},
async connect(peerNearby: PeerNearby) {
async connect(peerNearby: PeerNearby, verifyAlive = true) {
for (const peerConnection of peersConnections.values()) {
// already connected or in the process of connecting
if (peerConnection.peer?.id === peerNearby.peer?.id) return;
Expand All @@ -236,8 +236,7 @@ const connectivityAPI = {
switch (peerNearby.type) {
case PEER_ADVERSTISING_METHOD.WEB:
case PEER_ADVERSTISING_METHOD.BONJOUR:
const alive = await verifyWSS(peerNearby);
if (!alive) return;
if (verifyAlive && !(await verifyWSS(peerNearby))) return;
id = crypto.randomUUID();
connecterWebSocket.open(id, peerNearby);
break;
Expand Down
4 changes: 2 additions & 2 deletions editor/api/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export default {
const zipFilename = project.title.replace(/\//, "-") + ".zip";
const out = project.location + "/" + zipFilename;

if (await rpc().fs.exists(out)) {
await rpc().fs.unlink(out);
if (await rpc().fs.exists(out, { absolutePath: true })) {
await rpc().fs.unlink(out, { absolutePath: true });
}

const zipData = await zipDirectory(
Expand Down
2 changes: 1 addition & 1 deletion editor/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ a {
}

#splash {
height: 100dvh;
height: 100vh;
width: 100%;
display: flex;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion editor/packages/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class PackageInstaller {
PackageInstaller.updateProgress(pacakgeInfo.name, {
progress: 0,
total: -1,
error
error: JSON.stringify(error)
});
pacakgeInfo.errored = error;
}
Expand Down
16 changes: 14 additions & 2 deletions editor/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,20 @@ export class tsWorker {
this.worker = new Worker("worker-ts.js", { type: "module" });
this.worker.onmessage = (message) => {
if (message.data.ready) {
this.isReady = true;
this.readyAwaiter.forEach((resolve) => resolve());
rpc()
.platform()
.then((platform) => {
this.worker.postMessage({ platform });
this.isReady = true;
this.readyAwaiter.forEach((resolve) => resolve());
});
return;
}

if (message.data.body) {
const { id, body } = message.data;
(globalThis as any).Android?.passRequestBody(id, body);
this.worker.postMessage({ request_id: id });
return;
}

Expand Down
23 changes: 23 additions & 0 deletions editor/typescript/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { AdapterEditor } from "../rpc";
import type { rpcSync as rpcSyncFn } from "../../src/index";
import type rpcFn from "../../src/index";
import { bindPassRequestBody } from "../../src/android";

const rpc = globalThis.rpc as typeof rpcFn<AdapterEditor>;
const rpcSync = globalThis.rpcSync as typeof rpcSyncFn<AdapterEditor>;
Expand All @@ -34,7 +35,29 @@ function removeSourceObjects(obj: any) {
return obj;
}

const passingBodyToMainThread = new Map<number, () => void>();

self.onmessage = (message: MessageEvent) => {
if (message.data.request_id) {
const resolve = passingBodyToMainThread.get(message.data.request_id);
resolve?.();
passingBodyToMainThread.delete(message.data.request_id);
return;
}

if (message.data.platform) {
if (message.data.platform === "android") {
bindPassRequestBody((id, body) => {
return new Promise<void>((resolve) => {
passingBodyToMainThread.set(id, resolve);
self.postMessage({ id, body });
});
});
}

return;
}

const { id, methodPath, args } = message.data;

let method = methodPath.reduce(
Expand Down
2 changes: 1 addition & 1 deletion editor/views/esbuild/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@import "../../style/colors";

.esbuild-install {
height: 100dvh;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
Expand Down
20 changes: 12 additions & 8 deletions editor/views/peers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
PEER_ADVERSTISING_METHOD,
PEER_CONNECTION_STATE,
PEER_CONNECTION_TYPE,
PeerConnectionPairing
} from "../../../src/connectivity/types";
import api from "../../api";
Expand Down Expand Up @@ -289,15 +290,18 @@ class Peers {
const address = addressInput.value;
const port = portInput.value;

api.connectivity.connect({
peer: {
id: null,
name: `Manual Peer Connection [${address.includes(":") ? `[${address}]` : address}:${port}]`
api.connectivity.connect(
{
peer: {
id: null,
name: `Manual Peer Connection [${address.includes(":") ? `[${address}]` : address}:${port}]`
},
type: PEER_ADVERSTISING_METHOD.BONJOUR,
addresses: [address],
port: parseInt(port)
},
type: PEER_ADVERSTISING_METHOD.BONJOUR,
addresses: [address],
port: parseInt(port)
});
false
);

dialog.remove();
stackNavigation.lock = false;
Expand Down
2 changes: 1 addition & 1 deletion editor/views/project/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $transition: 0.3s all;
}

.project {
height: 100dvh;
height: 100vh;

> .top-bar {
position: fixed;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fullstacked-editor",
"version": "0.8.0",
"version": "0.8.1",
"scripts": {
"build": "esbuild build.ts --bundle --outfile=.cache/build.js --platform=node --format=esm --packages=external && node .cache/build.js",
"start": "npm run build && npm start -w platform/node",
Expand All @@ -26,7 +26,7 @@
"@codemirror/lang-sass": "^6.0.2",
"@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.26.3",
"@fullstacked/stack-navigation": "^0.0.0",
"@fullstacked/stack-navigation": "^0.0.1",
"@types/gzip-js": "^0.3.5",
"@types/node": "^20.12.11",
"@types/url-parse": "^1.4.11",
Expand Down Expand Up @@ -54,4 +54,4 @@
"url-parse": "^1.5.10",
"ws": "^8.17.1"
}
}
}
40 changes: 40 additions & 0 deletions platform/android/esbuild/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# go/Makefile

ESBUILD_DIR = $(CURDIR)/../../../lib/esbuild
GO_EXEC = $(CURDIR)/../../../lib/go/bin/go
ANDROID_OUT = $(CURDIR)/../studio/app/src/main/cpp/esbuild

android-arm:
cd $(ESBUILD_DIR) && git clean -f && \
cp $(CURDIR)/../../ios/esbuild/cmd/* $(ESBUILD_DIR)/cmd/esbuild && \
CGO_ENABLED=1 \
GOOS=android \
GOARCH=arm \
CGO_LDFLAGS="-Wl,-soname,esbuild.so" \
CC=~/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi34-clang \
$(GO_EXEC) build -buildmode=c-shared -o $(ANDROID_OUT)/armeabi-v7a/esbuild.so ./cmd/esbuild && \
cd $(ESBUILD_DIR) && git clean -f

android-arm64:
cd $(ESBUILD_DIR) && git clean -f && \
cp $(CURDIR)/../../ios/esbuild/cmd/* $(ESBUILD_DIR)/cmd/esbuild && \
CGO_ENABLED=1 \
GOOS=android \
GOARCH=arm64 \
CGO_LDFLAGS="-Wl,-soname,esbuild.so" \
CC=~/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android34-clang \
$(GO_EXEC) build -buildmode=c-shared -o $(ANDROID_OUT)/arm64-v8a/esbuild.so ./cmd/esbuild && \
cd $(ESBUILD_DIR) && git clean -f

android-x86_64:
cd $(ESBUILD_DIR) && git clean -f && \
cp $(CURDIR)/../../ios/esbuild/cmd/* $(ESBUILD_DIR)/cmd/esbuild && \
CGO_ENABLED=1 \
GOOS=android \
GOARCH=amd64 \
CGO_LDFLAGS="-Wl,-soname,esbuild.so" \
CC=~/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android34-clang \
$(GO_EXEC) build -buildmode=c-shared -o $(ANDROID_OUT)/x86_64/esbuild.so ./cmd/esbuild && \
cd $(ESBUILD_DIR) && git clean -f

android: android-arm android-arm64 android-x86_64
16 changes: 16 additions & 0 deletions platform/android/studio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
.idea
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions platform/android/studio/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build
/src/main/cpp/esbuild
/release
Loading

0 comments on commit acd3630

Please sign in to comment.