Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/beige-pumas-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pulse-editor/shared-utils": patch
"@pulse-editor/react-api": patch
---

Add rebounce option for useFile hook's saveFile
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"afraid-moments-punch",
"angry-llamas-smash",
"beige-pandas-rhyme",
"beige-pumas-run",
"bumpy-parents-pull",
"calm-rivers-march",
"chatty-trains-beam",
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/publish-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Publish Android

env:
ANDROID_SDK_VERSION: "36.1.0"

on:
push:
tags:
- "v*.*.*"

permissions:
contents: read

jobs:
build:
strategy:
matrix:
target: [android]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: "21"
distribution: "temurin"

- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Install Android SDK build tools
run: |
sdkmanager "build-tools;${{env.ANDROID_SDK_VERSION}}"
echo "$ANDROID_SDK_ROOT/build-tools/${{env.ANDROID_SDK_VERSION}}" >> $GITHUB_PATH

- name: Get Keystore
run: |
mkdir ~/.keystore
echo ${{ secrets.ANDROID_KEYSTORE }} | base64 --decode > ~/.keystore/pulse-editor.keystore

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install shared-utils dependencies
run: npm install --workspace=npm-packages/shared-utils

- name: Build shared-utils
run: npm run shared-utils-build

- name: Install web dependencies
run: npm install --workspace=web

- name: Save public env variables into .env file
run: |
echo NEXT_PUBLIC_BACKEND_URL=$NEXT_PUBLIC_BACKEND_URL >> ./web/.env
echo NEXT_PUBLIC_CDN_URL=$NEXT_PUBLIC_CDN_URL >> ./web/.env
echo NEXT_PUBLIC_STORAGE_CONTAINER=$NEXT_PUBLIC_STORAGE_CONTAINER >> ./web/.env
env:
NEXT_PUBLIC_BACKEND_URL: ${{ vars.NEXT_PUBLIC_BACKEND_URL }}
NEXT_PUBLIC_CDN_URL: ${{ vars.NEXT_PUBLIC_CDN_URL }}
NEXT_PUBLIC_STORAGE_CONTAINER: ${{ vars.NEXT_PUBLIC_STORAGE_CONTAINER }}

- name: Build Web App
run: npm run web-build

- name: Install mobile dependencies
run: npm install --workspace=mobile

- name: Change Android Project Permission
run: chmod +x mobile/android/gradlew

- name: Sync Capacitor App
run: npx cap sync
working-directory: mobile

- name: Build Capacitor App
run: npx cap build android --keystorepath ~/.keystore/pulse-editor.keystore --keystorepass ${{ secrets.ANDROID_KEYSTORE_PASS }} --keystorealias ${{ secrets.ANDROID_KEYSTORE_ALIAS }} --keystorealiaspass ${{ secrets.ANDROID_KEYSTORE_ALIAS_PASS }} --androidreleasetype AAB --signing-type jarsigner
working-directory: mobile

- name: Publish to Play Store
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
packageName: com.pulse_editor.app
releaseFiles: mobile/android/app/build/outputs/bundle/release/app-release-signed.aab
track: internal
status: draft
6 changes: 2 additions & 4 deletions mobile/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Android release
```bash
npx cap sync
# Build .aab file (will fail signing, use the next command to fix)
npx cap build android --keystorepath "<path_to_keystore>" --keystorepass "<keystore_pass>" --keystorealias "<keystore_alias>" --keystorealiaspass "<keystore_alias_pass>" --androidreleasetype AAB
# Sign the .aab
jarsigner -verbose -keystore "<path_to_keystore>" "<path_to_aab>" "<keystore_alias>"
# Build .aab file
npx cap build android --keystorepath "<path_to_keystore>" --keystorepass "<keystore_pass>" --keystorealias "<keystore_alias>" --keystorealiaspass "<keystore_alias_pass>" --androidreleasetype AAB --signing-type jarsigner
```

Then, `mobile/android/app/build/outputs/bundle/release/app-released.aab` is a signed .aab ready for publishing.
2 changes: 1 addition & 1 deletion mobile/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
applicationId "com.pulse_editor.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionCode 2
versionName "v0.1.1-beta"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
Expand Down
8 changes: 8 additions & 0 deletions npm-packages/react-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @pulse-editor/react-api

## 0.1.1-beta.57

### Patch Changes

- Add rebounce option for useFile hook's saveFile
- Updated dependencies
- @pulse-editor/[email protected]

## 0.1.1-beta.56

### Patch Changes
Expand Down
7 changes: 5 additions & 2 deletions npm-packages/react-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pulse-editor/react-api",
"version": "0.1.1-beta.56",
"version": "0.1.1-beta.57",
"main": "dist/main.js",
"files": [
"dist"
Expand Down Expand Up @@ -37,8 +37,11 @@
"typescript-eslint": "^8.30.1"
},
"peerDependencies": {
"@pulse-editor/shared-utils": "0.1.1-beta.56",
"@pulse-editor/shared-utils": "0.1.1-beta.57",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"dependencies": {
"use-debounce": "^10.0.6"
}
}
37 changes: 25 additions & 12 deletions npm-packages/react-api/src/hooks/editor/use-file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { IMCMessage, IMCMessageTypeEnum } from "@pulse-editor/shared-utils";
import { useCallback, useEffect, useState } from "react";
import { useDebouncedCallback } from "use-debounce";
import useIMC from "../imc/use-imc";

export default function useFile(uri: string | undefined) {
/**
*
* @param uri The file URI to read/write
* @param debounce Debounce time in ms for write operations
* @returns
*/
export default function useFile(uri: string | undefined, debounce = 0) {
const [file, setFile] = useState<File | undefined>(undefined);

const receiverHandlerMap = new Map<
Expand All @@ -20,26 +27,32 @@ export default function useFile(uri: string | undefined) {

const { imc, isReady } = useIMC(receiverHandlerMap, "file");

const sendFileDebounced = useDebouncedCallback(
async (newFile: File) => {
if (!isReady || !uri) return;
await imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {
uri,
file: newFile,
});
},
debounce,
{ maxWait: debounce * 2 },
);

const saveFile = useCallback(
(fileContent: string) => {
if (!uri) return;
else if (!file) return;
async (fileContent: string) => {
if (!uri || !file) return;

// Update file content
const newFile = new File([fileContent], file.name, {
type: file.type,
lastModified: Date.now(),
});
setFile(newFile);

if (isReady && uri) {
imc?.sendMessage(IMCMessageTypeEnum.PlatformWriteFile, {
uri,
file: newFile,
});
}
// ✅ This now waits until the debounced write actually finishes
await sendFileDebounced(newFile);
},
[uri, file, isReady],
[file, uri, sendFileDebounced],
);

// Read file when uri changes
Expand Down
6 changes: 6 additions & 0 deletions npm-packages/shared-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @pulse-editor/shared-utils

## 0.1.1-beta.57

### Patch Changes

- Add rebounce option for useFile hook's saveFile

## 0.1.1-beta.56

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion npm-packages/shared-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pulse-editor/shared-utils",
"version": "0.1.1-beta.56",
"version": "0.1.1-beta.57",
"main": "dist/main.js",
"files": [
"dist"
Expand Down
9 changes: 6 additions & 3 deletions package-lock.json

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