Compare commits
4
Commits
c5f129bb42
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61d08f8a34 | ||
|
|
41eaef92b0 | ||
|
|
55e21c06d9 | ||
|
|
eeab4d1221 |
@@ -0,0 +1,327 @@
|
|||||||
|
name: Android Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main, develop]
|
||||||
|
paths:
|
||||||
|
- 'carry-your-live/**'
|
||||||
|
- '.gitea/workflows/android-build.yml'
|
||||||
|
pull_request:
|
||||||
|
branches: [main, develop]
|
||||||
|
paths:
|
||||||
|
- 'carry-your-live/**'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
NODE_VERSION: '20'
|
||||||
|
JAVA_VERSION: '17'
|
||||||
|
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
||||||
|
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
||||||
|
GRADLE_OPTS: "-Dorg.gradle.workers.max=2 -Dorg.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=1024m"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
setup:
|
||||||
|
name: Setup & Install
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 20
|
||||||
|
outputs:
|
||||||
|
gradle-cache-key: ${{ steps.gradle-cache.outputs.cache-primary-key }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: carry-your-live/package-lock.json
|
||||||
|
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
cache: 'gradle'
|
||||||
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
- name: Install Android SDK
|
||||||
|
run: |
|
||||||
|
if [ -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
|
||||||
|
echo "Android SDK already present in cache"
|
||||||
|
else
|
||||||
|
rm -rf "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mkdir -p "$ANDROID_HOME/cmdline-tools"
|
||||||
|
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
||||||
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
|
fi
|
||||||
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
|
||||||
|
"platform-tools" \
|
||||||
|
"platforms;android-36" \
|
||||||
|
"build-tools;36.0.0" \
|
||||||
|
"ndk;27.1.12297006"
|
||||||
|
mkdir -p carry-your-live/android/app
|
||||||
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
working-directory: carry-your-live
|
||||||
|
run: |
|
||||||
|
for i in {1..3}; do
|
||||||
|
npm ci && break || sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Prebuild Android
|
||||||
|
working-directory: carry-your-live
|
||||||
|
run: |
|
||||||
|
for i in {1..2}; do
|
||||||
|
npx expo prebuild --platform android --clean && break || sleep 15
|
||||||
|
done
|
||||||
|
|
||||||
|
build-debug:
|
||||||
|
name: Build Debug APK
|
||||||
|
needs: setup
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: carry-your-live/package-lock.json
|
||||||
|
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
cache: 'gradle'
|
||||||
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
- name: Install Android SDK
|
||||||
|
run: |
|
||||||
|
if [ -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
|
||||||
|
echo "Android SDK already present in cache"
|
||||||
|
else
|
||||||
|
rm -rf "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mkdir -p "$ANDROID_HOME/cmdline-tools"
|
||||||
|
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
||||||
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
|
fi
|
||||||
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
|
||||||
|
"platform-tools" \
|
||||||
|
"platforms;android-36" \
|
||||||
|
"build-tools;36.0.0" \
|
||||||
|
"ndk;27.1.12297006"
|
||||||
|
mkdir -p carry-your-live/android/app
|
||||||
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
||||||
|
|
||||||
|
- name: Build Debug APK
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
for i in {1..3}; do
|
||||||
|
./gradlew assembleDebug --no-daemon -Dorg.gradle.workers.max=2 && break || sleep 30
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Find Debug APK
|
||||||
|
id: find-debug-apk
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*debug*.apk" -type f | head -n 1)
|
||||||
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Found Debug APK at: $APK_PATH"
|
||||||
|
|
||||||
|
- name: Upload Debug APK
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-debug-apk
|
||||||
|
path: ${{ steps.find-debug-apk.outputs.apk_path }}
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
|
build-release:
|
||||||
|
name: Build Release APK & AAB
|
||||||
|
needs: setup
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 35
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: carry-your-live/package-lock.json
|
||||||
|
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
cache: 'gradle'
|
||||||
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
- name: Install Android SDK
|
||||||
|
run: |
|
||||||
|
if [ -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
|
||||||
|
echo "Android SDK already present in cache"
|
||||||
|
else
|
||||||
|
rm -rf "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mkdir -p "$ANDROID_HOME/cmdline-tools"
|
||||||
|
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
||||||
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
|
fi
|
||||||
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
|
||||||
|
"platform-tools" \
|
||||||
|
"platforms;android-36" \
|
||||||
|
"build-tools;36.0.0" \
|
||||||
|
"ndk;27.1.12297006"
|
||||||
|
mkdir -p carry-your-live/android/app
|
||||||
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
||||||
|
|
||||||
|
- name: Build Release APK
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
for i in {1..3}; do
|
||||||
|
./gradlew assembleRelease --no-daemon -Dorg.gradle.workers.max=2 && break || sleep 30
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Build Release Bundle (AAB)
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
for i in {1..3}; do
|
||||||
|
./gradlew bundleRelease --no-daemon -Dorg.gradle.workers.max=2 && break || sleep 30
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Find Release APK
|
||||||
|
id: find-release-apk
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.apk" -type f | head -n 1)
|
||||||
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Found Release APK at: $APK_PATH"
|
||||||
|
|
||||||
|
- name: Find Release Bundle (AAB)
|
||||||
|
id: find-release-aab
|
||||||
|
run: |
|
||||||
|
AAB_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.aab" -type f | head -n 1)
|
||||||
|
echo "aab_path=$AAB_PATH" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Found Release AAB at: $AAB_PATH"
|
||||||
|
|
||||||
|
- name: Upload Release APK
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-release-apk
|
||||||
|
path: ${{ steps.find-release-apk.outputs.apk_path }}
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
|
- name: Upload Release Bundle (AAB)
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-release-aab
|
||||||
|
path: ${{ steps.find-release-aab.outputs.aab_path }}
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
|
test-lint:
|
||||||
|
name: Test & Lint
|
||||||
|
needs: setup
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 25
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: carry-your-live/package-lock.json
|
||||||
|
|
||||||
|
- name: Setup Java
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
cache: 'gradle'
|
||||||
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
|
- name: Install Android SDK
|
||||||
|
run: |
|
||||||
|
if [ -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
|
||||||
|
echo "Android SDK already present in cache"
|
||||||
|
else
|
||||||
|
rm -rf "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mkdir -p "$ANDROID_HOME/cmdline-tools"
|
||||||
|
wget -q https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -O /tmp/cmdtools.zip
|
||||||
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
|
fi
|
||||||
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
|
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
|
||||||
|
"platform-tools" \
|
||||||
|
"platforms;android-36" \
|
||||||
|
"build-tools;36.0.0" \
|
||||||
|
"ndk;27.1.12297006"
|
||||||
|
mkdir -p carry-your-live/android/app
|
||||||
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
||||||
|
|
||||||
|
- name: Run Unit Tests
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
for i in {1..3}; do
|
||||||
|
./gradlew test --no-daemon -Dorg.gradle.workers.max=2 && break || sleep 30
|
||||||
|
done
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Run Lint
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
for i in {1..2}; do
|
||||||
|
./gradlew lint --no-daemon -Dorg.gradle.workers.max=2 && break || sleep 30
|
||||||
|
done
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Upload Test Reports
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-test-reports
|
||||||
|
path: carry-your-live/android/app/build/reports/tests/
|
||||||
|
retention-days: 14
|
||||||
|
|
||||||
|
- name: Upload Lint Reports
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-lint-reports
|
||||||
|
path: carry-your-live/android/app/build/reports/lint-results*.html
|
||||||
|
retention-days: 14
|
||||||
+172
-75
@@ -1,36 +1,46 @@
|
|||||||
name: Build and Release APK
|
name: Build and Release Android
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
tags:
|
||||||
|
- 'v*'
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
NODE_VERSION: '20'
|
||||||
|
JAVA_VERSION: '17'
|
||||||
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
ANDROID_HOME: ${{ runner.tool_cache }}/android-sdk
|
||||||
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
ANDROID_SDK_ROOT: ${{ runner.tool_cache }}/android-sdk
|
||||||
|
GITEA_SERVER_URL: "https://techmos.gitea.org"
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
name: Build Android
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
timeout-minutes: 45
|
||||||
apk-path: ${{ steps.upload-apk.outputs.path }}
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Node
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 22
|
node-version: ${{ env.NODE_VERSION }}
|
||||||
|
cache: 'npm'
|
||||||
|
cache-dependency-path: carry-your-live/package-lock.json
|
||||||
|
|
||||||
- name: Set up JDK
|
- name: Setup Java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v4
|
||||||
with:
|
with:
|
||||||
distribution: temurin
|
distribution: 'temurin'
|
||||||
java-version: 17
|
java-version: ${{ env.JAVA_VERSION }}
|
||||||
|
cache: 'gradle'
|
||||||
|
cache-dependency-path: carry-your-live/android/gradle/wrapper/gradle-wrapper.properties
|
||||||
|
|
||||||
- name: Install Android SDK
|
- name: Install Android SDK
|
||||||
run: |
|
run: |
|
||||||
@@ -43,7 +53,6 @@ jobs:
|
|||||||
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
unzip -q /tmp/cmdtools.zip -d "$ANDROID_HOME/cmdline-tools"
|
||||||
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
mv "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/latest"
|
||||||
fi
|
fi
|
||||||
# Accept all licenses by writing known license hashes
|
|
||||||
mkdir -p "$ANDROID_HOME/licenses"
|
mkdir -p "$ANDROID_HOME/licenses"
|
||||||
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license"
|
||||||
@@ -56,85 +65,173 @@ jobs:
|
|||||||
mkdir -p carry-your-live/android/app
|
mkdir -p carry-your-live/android/app
|
||||||
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
echo "sdk.dir=$ANDROID_HOME" > carry-your-live/android/app/local.properties
|
||||||
|
|
||||||
- name: Install JS dependencies
|
- name: Install dependencies
|
||||||
working-directory: carry-your-live
|
working-directory: carry-your-live
|
||||||
run: |
|
run: |
|
||||||
for i in {1..3}; do
|
for i in {1..3}; do
|
||||||
npm ci && break || sleep 10
|
npm ci && break || sleep 10
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Generate debug keystore (signs the release APK)
|
- name: Prebuild Android
|
||||||
run: |
|
working-directory: carry-your-live
|
||||||
mkdir -p carry-your-live/android/app
|
run: npx expo prebuild --platform android --clean
|
||||||
rm -f carry-your-live/android/app/debug.keystore
|
|
||||||
keytool -genkeypair -v \
|
|
||||||
-keystore carry-your-live/android/app/debug.keystore \
|
|
||||||
-alias androiddebugkey -storepass android -keypass android \
|
|
||||||
-keyalg RSA -keysize 2048 -validity 10000 \
|
|
||||||
-dname "CN=Android Debug,O=Android,C=US"
|
|
||||||
|
|
||||||
- name: Build release APK
|
- name: Configure Release Signing
|
||||||
|
if: env.KEYSTORE_BASE64 != ''
|
||||||
|
working-directory: carry-your-live/android/app
|
||||||
run: |
|
run: |
|
||||||
cd carry-your-live/android
|
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 -d > release.keystore
|
||||||
./gradlew assembleRelease
|
cat > ../release-signing.properties <<EOF
|
||||||
|
storeFile=release.keystore
|
||||||
|
storePassword=${{ secrets.KEYSTORE_PASSWORD }}
|
||||||
|
keyAlias=${{ secrets.KEY_ALIAS }}
|
||||||
|
keyPassword=${{ secrets.KEY_PASSWORD }}
|
||||||
|
EOF
|
||||||
|
|
||||||
- name: Upload APK
|
- name: Build Release APK
|
||||||
id: upload-apk
|
working-directory: carry-your-live/android
|
||||||
uses: actions/upload-artifact@v3
|
run: |
|
||||||
|
if [ -f "../release-signing.properties" ]; then
|
||||||
|
./gradlew assembleRelease -PreleaseSigningProperties=../release-signing.properties --no-daemon
|
||||||
|
else
|
||||||
|
./gradlew assembleRelease --no-daemon
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build Release Bundle (AAB)
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: |
|
||||||
|
if [ -f "../release-signing.properties" ]; then
|
||||||
|
./gradlew bundleRelease -PreleaseSigningProperties=../release-signing.properties --no-daemon
|
||||||
|
else
|
||||||
|
./gradlew bundleRelease --no-daemon
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: ./gradlew test --no-daemon
|
||||||
|
|
||||||
|
- name: Run Lint
|
||||||
|
working-directory: carry-your-live/android
|
||||||
|
run: ./gradlew lint --no-daemon
|
||||||
|
|
||||||
|
- name: Find Release APK
|
||||||
|
id: find-release-apk
|
||||||
|
run: |
|
||||||
|
APK_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.apk" -type f | head -n 1)
|
||||||
|
echo "apk_path=$APK_PATH" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Found Release APK at: $APK_PATH"
|
||||||
|
|
||||||
|
- name: Find Release Bundle (AAB)
|
||||||
|
id: find-release-aab
|
||||||
|
run: |
|
||||||
|
AAB_PATH=$(find carry-your-live/android/app/build/outputs -name "*release*.aab" -type f | head -n 1)
|
||||||
|
echo "aab_path=$AAB_PATH" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "Found Release AAB at: $AAB_PATH"
|
||||||
|
|
||||||
|
- name: Upload Build Artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: carry-your-live-release
|
name: android-release-build
|
||||||
path: carry-your-live/android/app/build/outputs/release/app-release.apk
|
path: |
|
||||||
|
${{ steps.find-release-apk.outputs.apk_path }}
|
||||||
|
${{ steps.find-release-aab.outputs.aab_path }}
|
||||||
|
retention-days: 90
|
||||||
|
|
||||||
|
- name: Upload Test Reports
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-test-reports
|
||||||
|
path: carry-your-live/android/app/build/reports/tests/
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
|
- name: Upload Lint Reports
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: android-lint-reports
|
||||||
|
path: carry-your-live/android/app/build/reports/lint-results*.html
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
release:
|
release:
|
||||||
|
name: Create Gitea Release
|
||||||
needs: build
|
needs: build
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Download Build Artifacts
|
||||||
uses: actions/checkout@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
name: android-release-build
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
- name: Download APK artifact
|
- name: Create Gitea Release
|
||||||
uses: actions/download-artifact@v3
|
env:
|
||||||
with:
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
name: carry-your-live-release
|
|
||||||
path: .
|
|
||||||
|
|
||||||
- name: Compute next version
|
|
||||||
id: version
|
|
||||||
run: |
|
run: |
|
||||||
latest=$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1)
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||||
if [ -z "$latest" ]; then
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
||||||
next="v1.0.0"
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
else
|
|
||||||
latest=${latest#v}
|
# Detect Gitea server URL
|
||||||
IFS='.' read -r major minor patch <<< "$latest"
|
GITEA_URL="${GITEA_SERVER_URL:-https://techmos.gitea.org}"
|
||||||
next="v${major}.${minor}.$((patch + 1))"
|
|
||||||
|
# Create release
|
||||||
|
RESPONSE=$(curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
|
||||||
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"${TAG_NAME}\",
|
||||||
|
\"name\": \"${TAG_NAME}\",
|
||||||
|
\"body\": \"Automated release for ${TAG_NAME}\",
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": false
|
||||||
|
}")
|
||||||
|
|
||||||
|
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
|
||||||
|
|
||||||
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Release might already exist, fetching existing release..."
|
||||||
|
RELEASE_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
|
"${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${TAG_NAME}" | jq -r '.id')
|
||||||
fi
|
fi
|
||||||
echo "next=${next}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "Failed to create or find release"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Release ID: $RELEASE_ID"
|
||||||
|
echo "release_id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
|
||||||
|
id: create-release
|
||||||
|
|
||||||
- name: Build changelog
|
- name: Upload APK to Release
|
||||||
id: changelog
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
prev_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
GITEA_URL="${GITEA_URL:-https://techmos.gitea.org}"
|
||||||
if [ -z "$prev_tag" ]; then
|
REPO_OWNER="${GITHUB_REPOSITORY%/*}"
|
||||||
log=$(git log --oneline --no-merges main | head -n 40)
|
REPO_NAME="${GITHUB_REPOSITORY#*/}"
|
||||||
else
|
RELEASE_ID="${{ steps.create-release.outputs.release_id }}"
|
||||||
log=$(git log --oneline --no-merges "$prev_tag"..main | head -n 40)
|
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||||
fi
|
|
||||||
{
|
for file in artifacts/*; do
|
||||||
echo "body<<EOF"
|
if [[ "$file" == *.apk ]]; then
|
||||||
echo "## What's new in this release"
|
FILENAME="carry-your-live-${TAG_NAME}.apk"
|
||||||
echo ""
|
elif [[ "$file" == *.aab ]]; then
|
||||||
echo "$log" | sed 's/^/- /'
|
FILENAME="carry-your-live-${TAG_NAME}.aab"
|
||||||
echo "EOF"
|
else
|
||||||
} >> "$GITHUB_OUTPUT"
|
continue
|
||||||
|
fi
|
||||||
- name: Create release
|
|
||||||
uses: softprops/action-gh-release@v2
|
echo "Uploading $file as $FILENAME..."
|
||||||
with:
|
curl -s -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases/${RELEASE_ID}/assets" \
|
||||||
tag_name: ${{ steps.version.outputs.next }}
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||||
name: ${{ steps.version.outputs.next }}
|
-F "attachment=@${file};filename=${FILENAME}"
|
||||||
body: ${{ steps.changelog.outputs.body }}
|
|
||||||
files: ./app-release.apk
|
echo "Uploaded $FILENAME"
|
||||||
generate_release_notes: false
|
done
|
||||||
@@ -104,15 +104,27 @@ android {
|
|||||||
keyAlias 'androiddebugkey'
|
keyAlias 'androiddebugkey'
|
||||||
keyPassword 'android'
|
keyPassword 'android'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
release {
|
||||||
|
if (project.hasProperty('releaseSigningProperties')) {
|
||||||
|
def propsFile = file(project.property('releaseSigningProperties'))
|
||||||
|
if (propsFile.exists()) {
|
||||||
|
def props = new Properties()
|
||||||
|
props.load(new FileInputStream(propsFile))
|
||||||
|
storeFile = file(props['storeFile'])
|
||||||
|
storePassword = props['storePassword']
|
||||||
|
keyAlias = props['keyAlias']
|
||||||
|
keyPassword = props['keyPassword']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
signingConfig = signingConfigs.debug
|
signingConfig = signingConfigs.debug
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
// Caution! In production, you need to generate your own keystore file.
|
signingConfig = signingConfigs.release
|
||||||
// see https://reactnative.dev/docs/signed-apk-android.
|
|
||||||
signingConfig = signingConfigs.debug
|
|
||||||
def enableShrinkResources = findProperty('android.enableShrinkResourcesInReleaseBuilds') ?: 'false'
|
def enableShrinkResources = findProperty('android.enableShrinkResourcesInReleaseBuilds') ?: 'false'
|
||||||
shrinkResources = enableShrinkResources.toBoolean()
|
shrinkResources = enableShrinkResources.toBoolean()
|
||||||
minifyEnabled enableMinifyInReleaseBuilds
|
minifyEnabled enableMinifyInReleaseBuilds
|
||||||
|
|||||||
@@ -74,7 +74,9 @@ export default function SettingsScreen() {
|
|||||||
loadSettingsFromServer,
|
loadSettingsFromServer,
|
||||||
} = useSettings();
|
} = useSettings();
|
||||||
const categories = useCategories();
|
const categories = useCategories();
|
||||||
const [picker, setPicker] = useState<null | 'category' | 'sort' | 'reminder' | 'todoAhead'>(null);
|
const [picker, setPicker] = useState<
|
||||||
|
null | 'category' | 'sort' | 'reminder' | 'todoAhead' | 'themeMode'
|
||||||
|
>(null);
|
||||||
const [reminderTagPicker, setReminderTagPicker] = useState<Category | null>(null);
|
const [reminderTagPicker, setReminderTagPicker] = useState<Category | null>(null);
|
||||||
const [editingCategory, setEditingCategory] = useState<Category | null | 'new'>(null);
|
const [editingCategory, setEditingCategory] = useState<Category | null | 'new'>(null);
|
||||||
const [syncVisible, setSyncVisible] = useState(false);
|
const [syncVisible, setSyncVisible] = useState(false);
|
||||||
@@ -245,7 +247,7 @@ export default function SettingsScreen() {
|
|||||||
rightElement={
|
rightElement={
|
||||||
<Switch
|
<Switch
|
||||||
value={notifications}
|
value={notifications}
|
||||||
onValueChange={async (value) => {
|
onValueChange={async value => {
|
||||||
setNotifications(value);
|
setNotifications(value);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
const { cancelAllReminders } = await import('@/services/notifications');
|
const { cancelAllReminders } = await import('@/services/notifications');
|
||||||
@@ -358,6 +360,15 @@ export default function SettingsScreen() {
|
|||||||
onPress={openCustomAccent}
|
onPress={openCustomAccent}
|
||||||
showChevron
|
showChevron
|
||||||
/>
|
/>
|
||||||
|
<Text style={[styles.sectionHint, { color: theme.textFaint }]}>Theme</Text>
|
||||||
|
<ListItem
|
||||||
|
title="Theme Mode"
|
||||||
|
subtitle={
|
||||||
|
themeMode === 'system' ? 'System default' : themeMode === 'dark' ? 'Dark' : 'Light'
|
||||||
|
}
|
||||||
|
onPress={() => setPicker('themeMode')}
|
||||||
|
showChevron
|
||||||
|
/>
|
||||||
<Text style={[styles.sectionTitle, { color: theme.textMuted }]}>Data</Text>
|
<Text style={[styles.sectionTitle, { color: theme.textMuted }]}>Data</Text>
|
||||||
<SyncStatus />
|
<SyncStatus />
|
||||||
<ListItem
|
<ListItem
|
||||||
@@ -366,6 +377,32 @@ export default function SettingsScreen() {
|
|||||||
onPress={() => setSyncVisible(true)}
|
onPress={() => setSyncVisible(true)}
|
||||||
showChevron
|
showChevron
|
||||||
/>
|
/>
|
||||||
|
<ListItem
|
||||||
|
title="Sync Settings to Server"
|
||||||
|
subtitle="Push local settings to backend"
|
||||||
|
onPress={async () => {
|
||||||
|
try {
|
||||||
|
await syncSettingsToServer();
|
||||||
|
Alert.alert('Success', 'Settings synced to server');
|
||||||
|
} catch {
|
||||||
|
Alert.alert('Error', 'Failed to sync settings');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
showChevron
|
||||||
|
/>
|
||||||
|
<ListItem
|
||||||
|
title="Load Settings from Server"
|
||||||
|
subtitle="Pull settings from backend"
|
||||||
|
onPress={async () => {
|
||||||
|
try {
|
||||||
|
await loadSettingsFromServer();
|
||||||
|
Alert.alert('Success', 'Settings loaded from server');
|
||||||
|
} catch {
|
||||||
|
Alert.alert('Error', 'Failed to load settings');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
showChevron
|
||||||
|
/>
|
||||||
<ListItem
|
<ListItem
|
||||||
title="Friends"
|
title="Friends"
|
||||||
subtitle="Manage friends and requests"
|
subtitle="Manage friends and requests"
|
||||||
@@ -444,6 +481,15 @@ export default function SettingsScreen() {
|
|||||||
onClose={() => setPicker(null)}
|
onClose={() => setPicker(null)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<OptionPickerModal
|
||||||
|
visible={picker === 'themeMode'}
|
||||||
|
title="Theme Mode"
|
||||||
|
options={THEME_MODE_OPTIONS}
|
||||||
|
selectedValue={themeMode}
|
||||||
|
onSelect={value => setThemeMode(value as ThemeMode)}
|
||||||
|
onClose={() => setPicker(null)}
|
||||||
|
/>
|
||||||
|
|
||||||
<CategoryEditorModal
|
<CategoryEditorModal
|
||||||
visible={editorVisible}
|
visible={editorVisible}
|
||||||
category={editorCategory}
|
category={editorCategory}
|
||||||
@@ -551,6 +597,12 @@ const AHEAD_OPTIONS: { value: string; label: string }[] = Array.from({ length: 2
|
|||||||
label: i === 0 ? 'Only today' : `${i} day${i === 1 ? '' : 's'}`,
|
label: i === 0 ? 'Only today' : `${i} day${i === 1 ? '' : 's'}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const THEME_MODE_OPTIONS: { value: ThemeMode; label: string }[] = [
|
||||||
|
{ value: 'light', label: 'Light' },
|
||||||
|
{ value: 'dark', label: 'Dark' },
|
||||||
|
{ value: 'system', label: 'System default' },
|
||||||
|
];
|
||||||
|
|
||||||
function formatSyncTime(timestamp: number): string {
|
function formatSyncTime(timestamp: number): string {
|
||||||
const seconds = Math.floor((Date.now() - timestamp) / 1000);
|
const seconds = Math.floor((Date.now() - timestamp) / 1000);
|
||||||
if (seconds < 60) return 'just now';
|
if (seconds < 60) return 'just now';
|
||||||
|
|||||||
@@ -285,4 +285,4 @@ export async function rescheduleAllReminders(
|
|||||||
export function useNotificationSettings() {
|
export function useNotificationSettings() {
|
||||||
const { notifications, reminderPreference } = useSettings();
|
const { notifications, reminderPreference } = useSettings();
|
||||||
return { notificationsEnabled: notifications, globalReminderPreference: reminderPreference };
|
return { notificationsEnabled: notifications, globalReminderPreference: reminderPreference };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState, ReactNode } from 'react';
|
import React, {
|
||||||
|
createContext,
|
||||||
|
useCallback,
|
||||||
|
useContext,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
ReactNode,
|
||||||
|
} from 'react';
|
||||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||||
import { DEFAULT_API_BASE_URL, API_URL_KEY } from '@/services/auth';
|
import { DEFAULT_API_BASE_URL, API_URL_KEY } from '@/services/auth';
|
||||||
import { Platform } from 'react-native';
|
import { Platform } from 'react-native';
|
||||||
@@ -110,10 +118,15 @@ function accentTextColor(accent: string): string {
|
|||||||
return luminance > 0.5 ? '#111111' : '#FFFFFF';
|
return luminance > 0.5 ? '#111111' : '#FFFFFF';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function colors(accent: string = DEFAULT_ACCENT, mode: ThemeMode = 'dark', opacity: number = 1): ThemeColors {
|
export function colors(
|
||||||
|
accent: string = DEFAULT_ACCENT,
|
||||||
|
mode: ThemeMode = 'dark',
|
||||||
|
opacity: number = 1
|
||||||
|
): ThemeColors {
|
||||||
const softAccent = desaturate(accent, 0.35);
|
const softAccent = desaturate(accent, 0.35);
|
||||||
const accentWithOpacity = opacity < 1 ? `${opacity.toString(16).padStart(2, '0')}${accent.slice(1)}` : accent;
|
const accentWithOpacity =
|
||||||
|
opacity < 1 ? `${opacity.toString(16).padStart(2, '0')}${accent.slice(1)}` : accent;
|
||||||
|
|
||||||
if (mode === 'light') {
|
if (mode === 'light') {
|
||||||
return {
|
return {
|
||||||
background: '#FFFFFF',
|
background: '#FFFFFF',
|
||||||
@@ -144,7 +157,7 @@ export function colors(accent: string = DEFAULT_ACCENT, mode: ThemeMode = 'dark'
|
|||||||
info: '#1E88E5',
|
info: '#1E88E5',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// dark mode
|
// dark mode
|
||||||
return {
|
return {
|
||||||
background: '#121212',
|
background: '#121212',
|
||||||
@@ -289,34 +302,52 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
STORAGE_KEYS.reminderPreference,
|
STORAGE_KEYS.reminderPreference,
|
||||||
'15'
|
'15'
|
||||||
);
|
);
|
||||||
const [tagReminderPreferences, setTagReminderPreferences] = useStoredSetting<TagReminderPreferences>(
|
const [tagReminderPreferences, setTagReminderPreferences] =
|
||||||
STORAGE_KEYS.tagReminderPreferences,
|
useStoredSetting<TagReminderPreferences>(STORAGE_KEYS.tagReminderPreferences, {});
|
||||||
{}
|
|
||||||
);
|
|
||||||
const [apiUrl, setApiUrl] = useStoredSetting<string>(API_URL_KEY, DEFAULT_API_BASE_URL);
|
const [apiUrl, setApiUrl] = useStoredSetting<string>(API_URL_KEY, DEFAULT_API_BASE_URL);
|
||||||
const [accentColor, setAccentColor] = useStoredSetting<string>(STORAGE_KEYS.accentColor, DEFAULT_ACCENT);
|
const [accentColor, setAccentColor] = useStoredSetting<string>(
|
||||||
const [accentOpacity, setAccentOpacity] = useStoredSetting<number>(STORAGE_KEYS.accentOpacity, DEFAULT_ACCENT_OPACITY);
|
STORAGE_KEYS.accentColor,
|
||||||
const [todoAheadDays, setTodoAheadDays] = useStoredSetting<number>(STORAGE_KEYS.todoAheadDays, DEFAULT_TODO_AHEAD_DAYS);
|
DEFAULT_ACCENT
|
||||||
const [showCompleted, setShowCompleted] = useStoredSetting<boolean>(STORAGE_KEYS.showCompleted, false);
|
);
|
||||||
const [deleteBySwipe, setDeleteBySwipe] = useStoredSetting<boolean>(STORAGE_KEYS.deleteBySwipe, false);
|
const [accentOpacity, setAccentOpacity] = useStoredSetting<number>(
|
||||||
|
STORAGE_KEYS.accentOpacity,
|
||||||
|
DEFAULT_ACCENT_OPACITY
|
||||||
|
);
|
||||||
|
const [todoAheadDays, setTodoAheadDays] = useStoredSetting<number>(
|
||||||
|
STORAGE_KEYS.todoAheadDays,
|
||||||
|
DEFAULT_TODO_AHEAD_DAYS
|
||||||
|
);
|
||||||
|
const [showCompleted, setShowCompleted] = useStoredSetting<boolean>(
|
||||||
|
STORAGE_KEYS.showCompleted,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
const [deleteBySwipe, setDeleteBySwipe] = useStoredSetting<boolean>(
|
||||||
|
STORAGE_KEYS.deleteBySwipe,
|
||||||
|
false
|
||||||
|
);
|
||||||
const [themeMode, setThemeMode, themeModeLoaded] = useStoredSetting<ThemeMode>(
|
const [themeMode, setThemeMode, themeModeLoaded] = useStoredSetting<ThemeMode>(
|
||||||
STORAGE_KEYS.themeMode,
|
STORAGE_KEYS.themeMode,
|
||||||
'system'
|
'system'
|
||||||
);
|
);
|
||||||
|
|
||||||
const effectiveMode = themeMode === 'system'
|
const effectiveMode: 'light' | 'dark' =
|
||||||
? (Platform.OS === 'web' ? 'dark' : 'dark') // Will be updated by useColorScheme in real app
|
themeMode === 'system'
|
||||||
: themeMode;
|
? 'dark' // Will be updated by useColorScheme in real app
|
||||||
|
: themeMode;
|
||||||
|
|
||||||
const theme = useMemo(() => colors(accentColor, effectiveMode, accentOpacity), [accentColor, effectiveMode, accentOpacity]);
|
const theme = useMemo(
|
||||||
|
() => colors(accentColor, effectiveMode, accentOpacity),
|
||||||
|
[accentColor, effectiveMode, accentOpacity]
|
||||||
|
);
|
||||||
|
|
||||||
const syncSettingsToServer = useCallback(async () => {
|
const syncSettingsToServer = useCallback(async () => {
|
||||||
const { getAuthToken } = await import('@/services/auth');
|
const { getAuthToken } = await import('@/services/auth');
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
|
|
||||||
|
const isDark = effectiveMode === 'dark';
|
||||||
const settings = {
|
const settings = {
|
||||||
darkMode: effectiveMode === 'dark' || (themeMode === 'system' && effectiveMode === 'dark'),
|
darkMode: isDark,
|
||||||
defaultCategoryId,
|
defaultCategoryId,
|
||||||
sortOrder: sortBy,
|
sortOrder: sortBy,
|
||||||
reminderPreference,
|
reminderPreference,
|
||||||
@@ -325,13 +356,23 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
deleteBySwipe,
|
deleteBySwipe,
|
||||||
};
|
};
|
||||||
await pushServerSettings(apiUrl, token, settings);
|
await pushServerSettings(apiUrl, token, settings);
|
||||||
}, [apiUrl, effectiveMode, themeMode, defaultCategoryId, sortBy, reminderPreference, todoAheadDays, showCompleted, deleteBySwipe]);
|
}, [
|
||||||
|
apiUrl,
|
||||||
|
effectiveMode,
|
||||||
|
themeMode,
|
||||||
|
defaultCategoryId,
|
||||||
|
sortBy,
|
||||||
|
reminderPreference,
|
||||||
|
todoAheadDays,
|
||||||
|
showCompleted,
|
||||||
|
deleteBySwipe,
|
||||||
|
]);
|
||||||
|
|
||||||
const loadSettingsFromServer = useCallback(async () => {
|
const loadSettingsFromServer = useCallback(async () => {
|
||||||
const { getAuthToken } = await import('@/services/auth');
|
const { getAuthToken } = await import('@/services/auth');
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
|
|
||||||
const serverSettings = await fetchServerSettings(apiUrl, token);
|
const serverSettings = await fetchServerSettings(apiUrl, token);
|
||||||
if (!serverSettings) return;
|
if (!serverSettings) return;
|
||||||
|
|
||||||
@@ -344,7 +385,16 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
if (serverSettings.todoAheadDays !== undefined) setTodoAheadDays(serverSettings.todoAheadDays);
|
if (serverSettings.todoAheadDays !== undefined) setTodoAheadDays(serverSettings.todoAheadDays);
|
||||||
if (serverSettings.showCompleted !== undefined) setShowCompleted(serverSettings.showCompleted);
|
if (serverSettings.showCompleted !== undefined) setShowCompleted(serverSettings.showCompleted);
|
||||||
if (serverSettings.deleteBySwipe !== undefined) setDeleteBySwipe(serverSettings.deleteBySwipe);
|
if (serverSettings.deleteBySwipe !== undefined) setDeleteBySwipe(serverSettings.deleteBySwipe);
|
||||||
}, [apiUrl, setThemeMode, setDefaultCategoryId, setSortBy, setReminderPreference, setTodoAheadDays, setShowCompleted, setDeleteBySwipe]);
|
}, [
|
||||||
|
apiUrl,
|
||||||
|
setThemeMode,
|
||||||
|
setDefaultCategoryId,
|
||||||
|
setSortBy,
|
||||||
|
setReminderPreference,
|
||||||
|
setTodoAheadDays,
|
||||||
|
setShowCompleted,
|
||||||
|
setDeleteBySwipe,
|
||||||
|
]);
|
||||||
|
|
||||||
const value = useMemo<SettingsContextType>(
|
const value = useMemo<SettingsContextType>(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -407,11 +457,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return <SettingsContext.Provider value={value}>{children}</SettingsContext.Provider>;
|
||||||
<SettingsContext.Provider value={value}>
|
|
||||||
{children}
|
|
||||||
</SettingsContext.Provider>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSettings() {
|
export function useSettings() {
|
||||||
@@ -422,4 +468,4 @@ export function useSettings() {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './theme/tokens';
|
export * from './theme/tokens';
|
||||||
|
|||||||
Reference in New Issue
Block a user