Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0b5bb3599 | ||
|
|
e62357670f | ||
|
|
59ebb09921 | ||
|
|
d8a6521ce4 | ||
|
|
e5c77d0a0e | ||
|
|
0c13c833e3 | ||
|
|
f29a1f8cf7 | ||
|
|
1b0e06dce2 | ||
|
|
db7bb624e4 | ||
|
|
4a8a554396 | ||
|
|
ffc7577ddc | ||
|
|
b577e8411b | ||
|
|
10103c82a0 | ||
|
|
4e7c737c1c | ||
|
|
6c96e8a119 | ||
|
|
87829c5dd6 | ||
|
|
e736bb7ec7 | ||
|
|
3236a6176a | ||
|
|
fae1cb89bb | ||
|
|
7b01f675a7 | ||
|
|
beefec7df0 | ||
|
|
f8ee130b45 |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
build-essential
|
||||
ca-certificates
|
||||
curl
|
||||
libcurl4-openssl-dev
|
||||
libdrm-dev
|
||||
libegl1-mesa-dev
|
||||
libgbm-dev
|
||||
libgles2-mesa-dev
|
||||
libsdl2-dev
|
||||
patchelf
|
||||
pkg-config
|
||||
zip
|
||||
@@ -1,106 +0,0 @@
|
||||
name: Android Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Build Release APK
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Grant execute permission for gradlew
|
||||
run: chmod +x droid/gradlew
|
||||
|
||||
- name: Create keystore directory
|
||||
run: mkdir -p ~/.android
|
||||
|
||||
- name: Decode Keystore
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
echo "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore
|
||||
echo "Keystore decoded successfully"
|
||||
|
||||
- name: Copy Assets to Android Project
|
||||
run: ./scripts/copy-android-assets.sh
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
|
||||
- name: Build Release APK
|
||||
working-directory: ./droid
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
|
||||
run: |
|
||||
./gradlew assembleRelease \
|
||||
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
||||
-Pkeystore.path="/home/runner/.android/inbe-release.keystore" \
|
||||
--stacktrace
|
||||
|
||||
- name: Rename APK
|
||||
run: |
|
||||
VERSION=$(grep "versionName" droid/app/build.gradle | awk '{print $2}' | tr -d '"')
|
||||
find droid/app/build/outputs/apk/release -name "*-universal-release.apk" -exec cp {} inbe-$VERSION.apk \; 2>/dev/null || true
|
||||
|
||||
- name: Upload APK to Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-apk
|
||||
path: inbe-*.apk
|
||||
if-no-files-found: warn
|
||||
|
||||
- name: Create and Push Tag (if new version)
|
||||
id: tag_version
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
VERSION=$(grep "versionName" droid/app/build.gradle | awk '{print $2}' | tr -d '"')
|
||||
TAG="v$VERSION"
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG exists, skipping"
|
||||
echo "tag_pushed=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "$TAG" -m "Release $VERSION"
|
||||
git push origin "$TAG"
|
||||
echo "tag_pushed=true" >> $GITHUB_OUTPUT
|
||||
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: steps.tag_version.outputs.tag_pushed == 'true'
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ steps.tag_version.outputs.tag_name }}
|
||||
files: inbe-*.apk
|
||||
generate_release_notes: true
|
||||
draft: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1,37 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Test Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
@@ -0,0 +1,320 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Test Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev
|
||||
|
||||
- name: Run Tests
|
||||
run: make test
|
||||
|
||||
build-web:
|
||||
name: Build Web
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Web Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential zlib1g-dev zip
|
||||
|
||||
- name: Set up Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
|
||||
"$HOME/emsdk/emsdk" install latest
|
||||
"$HOME/emsdk/emsdk" activate latest
|
||||
echo "EMSDK=$HOME/emsdk" >> "$GITHUB_ENV"
|
||||
echo "EM_CONFIG=$HOME/emsdk/.emscripten" >> "$GITHUB_ENV"
|
||||
echo "$HOME/emsdk" >> "$GITHUB_PATH"
|
||||
echo "$HOME/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Build Web ZIP
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make package-unpackaged-assets
|
||||
make web
|
||||
mkdir -p build/release/web
|
||||
cp build/dist/inbe-web.zip build/release/web/
|
||||
|
||||
- name: Upload Web Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-web
|
||||
path: build/release/web/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-linux:
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
env:
|
||||
APT_CACHE_DIR: /tmp/apt-cache
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache Linux apt packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ env.APT_CACHE_DIR }}
|
||||
key: linux-apt-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/apt/linux-packages.txt') }}
|
||||
restore-keys: |
|
||||
linux-apt-${{ runner.os }}-${{ runner.arch }}-
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mapfile -t packages < .github/apt/linux-packages.txt
|
||||
mkdir -p "$APT_CACHE_DIR/partial"
|
||||
sudo apt-get update
|
||||
sudo apt-get \
|
||||
-o Dir::Cache::archives="$APT_CACHE_DIR" \
|
||||
install -y "${packages[@]}"
|
||||
sudo chown -R "$USER:$USER" "$APT_CACHE_DIR"
|
||||
|
||||
- name: Install AppImage Tools
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
curl -L -o "$HOME/.local/bin/linuxdeploy" \
|
||||
https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
|
||||
curl -L -o "$HOME/.local/bin/linuxdeploy-plugin-appimage" \
|
||||
https://github.com/linuxdeploy/linuxdeploy-plugin-appimage/releases/download/1-alpha-20250213-1/linuxdeploy-plugin-appimage-x86_64.AppImage
|
||||
curl -L -o "$HOME/.local/bin/appimagetool" \
|
||||
https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
|
||||
chmod +x "$HOME/.local/bin/linuxdeploy" "$HOME/.local/bin/linuxdeploy-plugin-appimage" "$HOME/.local/bin/appimagetool"
|
||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||
|
||||
- name: Build Linux AppImage
|
||||
env:
|
||||
APPIMAGE_EXTRACT_AND_RUN: "1"
|
||||
RAY_RAYLIB_CONFIG: -DSUPPORT_SCREEN_CAPTURE=0 -DSUPPORT_COMPRESSION_API=0 -DSUPPORT_AUTOMATION_EVENTS=0 -DSUPPORT_CLIPBOARD_IMAGE=0 -DSUPPORT_FILEFORMAT_BMP=0 -DSUPPORT_FILEFORMAT_GIF=0 -DSUPPORT_FILEFORMAT_QOI=0 -DSUPPORT_FILEFORMAT_DDS=0 -DSUPPORT_FILEFORMAT_TTF=0
|
||||
run: |
|
||||
set -euo pipefail
|
||||
RAY_SDL_INCLUDE_DIR="$(pkg-config --variable=includedir sdl2 | sed 's,/SDL2$,,')"
|
||||
RAY_CFLAGS="$(pkg-config --cflags sdl2 libdrm gbm egl glesv2)"
|
||||
RAY_LDLIBS="$(pkg-config --libs sdl2 libdrm gbm egl glesv2)"
|
||||
RAY_SDL_LDLIBS="$(pkg-config --libs sdl2)"
|
||||
export RAY_SDL_INCLUDE_DIR RAY_CFLAGS RAY_LDLIBS RAY_SDL_LDLIBS
|
||||
make appimage
|
||||
mkdir -p build/release/linux
|
||||
find build/dist/linux -maxdepth 1 -type f -name '*.AppImage' -exec cp {} build/release/linux/ \;
|
||||
test -n "$(find build/release/linux -type f -print -quit)"
|
||||
|
||||
- name: Upload Linux Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-linux
|
||||
path: build/release/linux/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-windows:
|
||||
name: Build Windows
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Windows Dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
gcc-mingw-w64-i686-win32 \
|
||||
gcc-mingw-w64-x86-64-win32 \
|
||||
zlib1g-dev \
|
||||
zip
|
||||
if [ -x /usr/bin/x86_64-w64-mingw32-gcc-win32 ]; then
|
||||
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-win32
|
||||
fi
|
||||
if [ -x /usr/bin/i686-w64-mingw32-gcc-win32 ]; then
|
||||
sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-win32
|
||||
fi
|
||||
|
||||
- name: Build Windows ZIP
|
||||
run: |
|
||||
set -euo pipefail
|
||||
make windows
|
||||
mkdir -p build/release/windows
|
||||
find build/dist/windows -maxdepth 1 -type f -name '*.zip' -exec cp {} build/release/windows/ \;
|
||||
test -n "$(find build/release/windows -type f -print -quit)"
|
||||
|
||||
- name: Upload Windows Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-windows
|
||||
path: build/release/windows/*
|
||||
if-no-files-found: error
|
||||
|
||||
build-android:
|
||||
name: Build Android
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
|
||||
- name: Install Android SDK Components
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-35" "build-tools;34.0.0" "ndk;25.1.8937393" "cmake;3.22.1"
|
||||
|
||||
- name: Prepare Android signing key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p ~/.android
|
||||
echo "$KEYSTORE_BASE64" | base64 -d > ~/.android/inbe-release.keystore
|
||||
|
||||
- name: Copy Android Assets
|
||||
run: ./scripts/copy-android-assets.sh
|
||||
|
||||
- name: Build Android APK
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
chmod +x droid/gradlew
|
||||
./droid/gradlew -p droid assembleRelease \
|
||||
-Pkeystore.path="$HOME/.android/inbe-release.keystore" \
|
||||
-Pkeystore.alias="$KEY_ALIAS" \
|
||||
-Pkeystore.password="$KEYSTORE_PASSWORD" \
|
||||
--stacktrace
|
||||
make android-copy-release-apks
|
||||
|
||||
- name: Collect Android Release Files
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p build/release/android
|
||||
VERSION=$(sed -n 's/^#define INBE_VERSION_STRING "\([^"]*\)".*/\1/p' src/core/version.h)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Could not read INBE_VERSION_STRING"
|
||||
exit 1
|
||||
fi
|
||||
cp "build/android/inbe-$VERSION.apk" build/release/android/
|
||||
|
||||
- name: Upload Android Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-android
|
||||
path: build/release/android/*
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build-web
|
||||
- build-linux
|
||||
- build-windows
|
||||
- build-android
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download Release Artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
pattern: release-*
|
||||
path: build/release
|
||||
merge-multiple: true
|
||||
|
||||
- name: Verify Release Artifacts
|
||||
run: |
|
||||
set -euo pipefail
|
||||
test -n "$(find build/release -type f -print -quit)"
|
||||
|
||||
- name: Create and Push Tag If Version Is New
|
||||
id: tag_version
|
||||
run: |
|
||||
set -euo pipefail
|
||||
VERSION=$(sed -n 's/^#define INBE_VERSION_STRING "\([^"]*\)".*/\1/p' src/core/version.h)
|
||||
if [ -z "$VERSION" ]; then
|
||||
echo "Could not read INBE_VERSION_STRING"
|
||||
exit 1
|
||||
fi
|
||||
TAG="v$VERSION"
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG exists, skipping release"
|
||||
echo "tag_pushed=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git tag -a "$TAG" -m "Release $VERSION"
|
||||
git push origin "$TAG"
|
||||
echo "tag_pushed=true" >> "$GITHUB_OUTPUT"
|
||||
echo "tag_name=$TAG" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: steps.tag_version.outputs.tag_pushed == 'true'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
tag_name: ${{ steps.tag_version.outputs.tag_name }}
|
||||
files: build/release/*
|
||||
generate_release_notes: true
|
||||
draft: false
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -10,3 +10,6 @@
|
||||
[submodule "vendor/sqlite"]
|
||||
path = vendor/sqlite
|
||||
url = https://github.com/sqlite/sqlite
|
||||
[submodule "vendor/liboqs"]
|
||||
path = vendor/liboqs
|
||||
url = https://github.com/open-quantum-safe/liboqs.git
|
||||
@@ -1,4 +1,23 @@
|
||||
# Changelog
|
||||
## [1.4.0] - 2026-06-19
|
||||
### Added
|
||||
- optional sync client, offline account creation
|
||||
- simplify tutorial
|
||||
|
||||
## [1.3.6] - 2026-06-18
|
||||
### Fixed
|
||||
- Fixed Tickmate `.db` imports so zero-based months map correctly and long habit histories load without dropping later dates.
|
||||
|
||||
## [1.3.5] - 2026-06-18
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
|
||||
## [1.3.4] - 2026-06-18
|
||||
### Changed
|
||||
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
|
||||
- Split the meditation manual into an image intro page and a shorter music/gong setup page.
|
||||
- Expanded release automation to build Web, Linux AppImage, Windows, APK, and AAB artifacts after tests pass.
|
||||
|
||||
## [1.3.3] - 2026-06-17
|
||||
### Fixed
|
||||
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
|
||||
|
||||
@@ -69,10 +69,15 @@ SQLITE_AMALGAMATION_C := $(SQLITE_BUILD_DIR)/sqlite3.c
|
||||
SQLITE_AMALGAMATION_H := $(SQLITE_BUILD_DIR)/sqlite3.h
|
||||
SQLITE_SRC := $(SQLITE_AMALGAMATION_C)
|
||||
SQLITE_INCLUDE := -I$(SQLITE_BUILD_DIR)
|
||||
LIBOQS_DIR := vendor/liboqs
|
||||
LIBOQS_BUILD_DIR := $(BUILD_OBJ_DIR)/liboqs/linux/$(ARCH)
|
||||
LIBOQS_A := $(LIBOQS_BUILD_DIR)/lib/liboqs.a
|
||||
LIBOQS_INCLUDE := -I$(LIBOQS_BUILD_DIR)/include
|
||||
TEST_BIN_DIR := $(BUILD_BIN_DIR)/tests
|
||||
STORAGE_IMPORT_TEST := $(TEST_BIN_DIR)/storage_import_test
|
||||
FLINT_TEXT_SCALING_TEST := $(TEST_BIN_DIR)/flint_text_scaling_test
|
||||
LOCALE_KEYS_TEST := $(TEST_BIN_DIR)/locale_keys_test
|
||||
SYNC_URL_TEST := $(TEST_BIN_DIR)/sync_url_test
|
||||
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
|
||||
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
|
||||
|
||||
@@ -80,23 +85,38 @@ APP_SRCS := \
|
||||
src/main.c \
|
||||
src/core/breath_engine.c \
|
||||
src/app/app.c \
|
||||
src/app/app_settings.c \
|
||||
src/app/device_preferences.c \
|
||||
src/session/session.c \
|
||||
src/practices/practice_registry.c \
|
||||
src/practices/whm/whm_practice.c \
|
||||
src/practices/whm/whm_session.c \
|
||||
src/practices/whm/whm_manual.c \
|
||||
src/practices/whm/whm_config.c \
|
||||
src/practices/meditation/meditation_practice.c \
|
||||
src/practices/meditation/meditation_session.c \
|
||||
src/practices/meditation/meditation_manual.c \
|
||||
src/practices/meditation/meditation_config.c \
|
||||
src/screens/habits_screen.c \
|
||||
src/session/meditation_music.c \
|
||||
src/practices/meditation/meditation_music.c \
|
||||
src/core/locale.c \
|
||||
src/core/theme.c \
|
||||
src/storage/data.c \
|
||||
src/storage/storage.c \
|
||||
src/storage/sync_account.c \
|
||||
src/storage/sync_client.c \
|
||||
src/third_party/miniz.c \
|
||||
src/platform/android/android_device.c \
|
||||
src/screens/practice_screen.c \
|
||||
src/screens/language_screen.c \
|
||||
src/screens/manual_screen.c \
|
||||
src/screens/settings/settings_screen.c
|
||||
src/screens/settings/settings_screen.c \
|
||||
src/screens/settings/settings_device.c \
|
||||
src/screens/settings/settings_theme.c \
|
||||
src/screens/settings/settings_data.c \
|
||||
src/screens/settings/settings_sync_account.c
|
||||
|
||||
LOCALE_FILES := $(wildcard locales/*.txt)
|
||||
IMAGE_FILES := assets/whm/1.jpg assets/whm/2.jpg
|
||||
IMAGE_FILES := assets/practices/whm/1.jpg assets/practices/whm/2.jpg assets/practices/meditation/1.jpg
|
||||
SOUND_FILES := $(wildcard assets/sounds/*.ogg)
|
||||
FONT_OUTPUTS := assets/fonts/locales.png assets/fonts/locales.dat assets/fonts/locales-8.png assets/fonts/locales-8.dat
|
||||
OTFCHOP_DIR ?= vendor/otfchop
|
||||
@@ -106,7 +126,7 @@ EMBEDDED_ASSETS_C := $(BUILD_OBJ_DIR)/$(APP_NAME)_embedded_assets.c
|
||||
EMBEDDED_ASSET_FILES := $(LOCALE_FILES) $(IMAGE_FILES) $(SOUND_FILES) $(FONT_OUTPUTS)
|
||||
SRC := $(APP_SRCS) $(EMBEDDED_ASSETS_C)
|
||||
|
||||
APP_INCLUDE := -Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/session -Isrc/storage -Isrc/platform/android -Isrc/third_party
|
||||
APP_INCLUDE := -Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party
|
||||
APP_RAYLIB_CONFIG := $(filter-out -DSUPPORT_MODULE_RAUDIO=0 -DSUPPORT_FILEFORMAT_PNG=0 -DSUPPORT_FILEFORMAT_JPG=0 -DSUPPORT_FILEFORMAT_OGG=0 -DSUPPORT_FILEFORMAT_MP3=0,$(RAY_RAYLIB_CONFIG)) -DSUPPORT_MODULE_RAUDIO=1 -DSUPPORT_FILEFORMAT_JPG=1 -DSUPPORT_FILEFORMAT_OGG=1 -DSUPPORT_FILEFORMAT_MP3=1
|
||||
CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1 $(FLINT_RUNTIME_ASSET_CFLAGS)
|
||||
WINDOWS_CFLAGS := -Wall -Wextra -std=c99 -Os -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections -DSUPPORT_FILEFORMAT_JPG=1 -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_EMBEDDED_ONLY=1
|
||||
@@ -139,8 +159,10 @@ WEB_CC ?= emcc
|
||||
WEB_AR ?= emar
|
||||
WEB_CACHE_BUSTER ?= $(shell git rev-parse --short HEAD 2>/dev/null || date +%s)
|
||||
WEB_TARGET := $(WEB_DIST_DIR)/index.html
|
||||
WEB_DIST_ZIP := $(BUILD_DIST_DIR)/$(APP_NAME)-web.zip
|
||||
WEB_ASSET_FILES := $(shell find web-assets -type f 2>/dev/null)
|
||||
UNPACKAGED_AUDIO_DIR := unpackaged_assets/audio
|
||||
WEB_AUDIO_FILES := $(shell find $(UNPACKAGED_AUDIO_DIR) -type f 2>/dev/null)
|
||||
MEDITATION_AUDIO_ZIP := web-assets/dl/inbe-meditation-audio-v1.zip
|
||||
|
||||
.PHONY: all native run test dist appimage clean clean-linux clean-raylib android-check-keystore android-copy-assets android-debug android-release android-bundle android-install android-install-release android-clean package-unpackaged-assets windows-runtime-assets-check windows windows64 windows32 web
|
||||
@@ -176,14 +198,15 @@ appimage: $(APPIMAGE_TARGET)
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST)
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST) $(SYNC_URL_TEST)
|
||||
$(STORAGE_IMPORT_TEST)
|
||||
$(FLINT_TEXT_SCALING_TEST)
|
||||
$(LOCALE_KEYS_TEST)
|
||||
$(SYNC_URL_TEST)
|
||||
|
||||
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/storage.h src/screens/habits_screen.c src/screens/habits_screen.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -ffunction-sections -fdata-sections \
|
||||
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/session -Isrc/storage -Isrc/platform/android -Isrc/third_party -Ivendor/raylib/src $(FLINT_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party -Ivendor/raylib/src $(FLINT_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/storage_import_test.c src/storage/storage.c src/screens/habits_screen.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
-Wl,--gc-sections -lm -lpthread -ldl
|
||||
@@ -200,6 +223,12 @@ $(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
|
||||
-o $@ \
|
||||
tests/locale_keys_test.c
|
||||
|
||||
$(SYNC_URL_TEST): tests/sync_url_test.c src/storage/sync_client.c src/storage/sync_client.h | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -Wno-unused-function -std=c99 -D_DEFAULT_SOURCE -DINBE_SYNC_CLIENT_TESTS -ffunction-sections -fdata-sections \
|
||||
-Isrc/storage -Isrc -Ivendor/raylib/src -o $@ \
|
||||
tests/sync_url_test.c src/storage/sync_client.c \
|
||||
-Wl,--gc-sections
|
||||
|
||||
$(BUILD_OBJ_DIR) $(LINUX_BIN_DIR) $(LINUX_DIST_DIR) $(LINUX_APPIMAGE_BUILD_DIR) $(WINDOWS_DIST_DIR) $(ANDROID_BUILD_DIR) $(TEST_BIN_DIR) $(WEB_OBJ_DIR) $(WEB_DIST_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
@@ -292,13 +321,24 @@ $(SQLITE_AMALGAMATION_C) $(SQLITE_AMALGAMATION_H): $(SQLITE_DIR)/configure $(SQL
|
||||
cd $(SQLITE_BUILD_DIR) && ../../../$(SQLITE_DIR)/configure
|
||||
$(MAKE) -C $(SQLITE_BUILD_DIR) sqlite3.c sqlite3.h
|
||||
|
||||
$(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(RAYLIB_A) | $(LINUX_BIN_DIR)
|
||||
$(LIBOQS_A): $(LIBOQS_DIR)/CMakeLists.txt | $(BUILD_OBJ_DIR)
|
||||
cmake -S $(LIBOQS_DIR) -B $(LIBOQS_BUILD_DIR) \
|
||||
-DCMAKE_BUILD_TYPE=MinSizeRel \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DOQS_BUILD_ONLY_LIB=ON \
|
||||
-DOQS_USE_OPENSSL=OFF \
|
||||
-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44
|
||||
cmake --build $(LIBOQS_BUILD_DIR) --target oqs
|
||||
|
||||
$(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(RAYLIB_A) $(LIBOQS_A) | $(LINUX_BIN_DIR)
|
||||
$(CC) $(CFLAGS) \
|
||||
$(APP_INCLUDE) \
|
||||
$(FLINT_INCLUDE) \
|
||||
$(SQLITE_INCLUDE) \
|
||||
$(LIBOQS_INCLUDE) \
|
||||
-I$(RAYLIB_DIR) \
|
||||
$(RAY_CFLAGS) \
|
||||
-DINBE_HAS_LIBOQS=1 \
|
||||
-DSUPPORT_MODULE_RAUDIO=1 \
|
||||
-DSUPPORT_FILEFORMAT_OGG=1 \
|
||||
-DSUPPORT_FILEFORMAT_MP3=1 \
|
||||
@@ -307,6 +347,7 @@ $(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H)
|
||||
$(FLINT_SRCS) \
|
||||
$(SQLITE_SRC) \
|
||||
$(RAYLIB_A) \
|
||||
$(LIBOQS_A) \
|
||||
$(RAY_LDLIBS) \
|
||||
$(FLINT_RUNTIME_ASSET_LDLIBS) \
|
||||
-lm -lpthread -ldl -lrt \
|
||||
@@ -379,7 +420,7 @@ $(APPIMAGE_TARGET): $(TARGET) $(LINUX_APPIMAGE_APPRUN) $(LINUX_APPIMAGE_DESKTOP)
|
||||
--output appimage
|
||||
test -f $@
|
||||
|
||||
$(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(WEB_RAYLIB_A) src/web_shell.html manifest.json $(WEB_ASSET_FILES) | $(WEB_DIST_DIR)
|
||||
$(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(WEB_RAYLIB_A) src/web_shell.html manifest.json $(WEB_ASSET_FILES) $(WEB_AUDIO_FILES) | $(WEB_DIST_DIR)
|
||||
$(WEB_CC) $(WEB_CFLAGS) \
|
||||
$(APP_INCLUDE) \
|
||||
$(FLINT_INCLUDE) \
|
||||
@@ -399,6 +440,7 @@ $(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMA
|
||||
-sFORCE_FILESYSTEM=1 \
|
||||
-sFETCH=1 \
|
||||
-sALLOW_MEMORY_GROWTH=1 \
|
||||
--preload-file $(UNPACKAGED_AUDIO_DIR)@$(UNPACKAGED_AUDIO_DIR) \
|
||||
--shell-file src/web_shell.html \
|
||||
-lidbfs.js \
|
||||
-lm
|
||||
@@ -551,6 +593,8 @@ windows:
|
||||
|
||||
web:
|
||||
$(MAKE) $(WEB_TARGET)
|
||||
rm -f $(WEB_DIST_ZIP)
|
||||
cd $(WEB_DIST_DIR) && zip -9 -r $(abspath $(WEB_DIST_ZIP)) .
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 67 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
Before Width: | Height: | Size: 54 KiB |
@@ -35,8 +35,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdk 19
|
||||
targetSdk 35
|
||||
versionCode 31
|
||||
versionName "1.3.3"
|
||||
versionCode 35
|
||||
versionName "1.4.0"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,14 +10,19 @@ set(SQLITE_BUILD_DIR "${CMAKE_BINARY_DIR}/sqlite")
|
||||
set(SQLITE_AMALGAMATION_C "${SQLITE_BUILD_DIR}/sqlite3.c")
|
||||
set(SQLITE_AMALGAMATION_H "${SQLITE_BUILD_DIR}/sqlite3.h")
|
||||
set(NATIVE_APP_GLUE_DIR "${ANDROID_NDK}/sources/android/native_app_glue")
|
||||
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "" FORCE)
|
||||
set(OQS_USE_OPENSSL OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44" CACHE STRING "" FORCE)
|
||||
add_subdirectory("${REPO_ROOT}/vendor/liboqs" "${CMAKE_BINARY_DIR}/liboqs")
|
||||
file(GLOB FLINT_SOURCES CONFIGURE_DEPENDS "${FLINT_DIR}/src/*.c")
|
||||
list(REMOVE_ITEM FLINT_SOURCES "${FLINT_DIR}/src/flint_file_dialog.c")
|
||||
file(GLOB INBE_LOCALE_ASSETS RELATIVE "${REPO_ROOT}" CONFIGURE_DEPENDS "${REPO_ROOT}/locales/*.txt")
|
||||
file(GLOB INBE_SOUND_ASSETS RELATIVE "${REPO_ROOT}" CONFIGURE_DEPENDS "${REPO_ROOT}/assets/sounds/*.ogg")
|
||||
set(INBE_EMBEDDED_INPUTS
|
||||
${INBE_LOCALE_ASSETS}
|
||||
assets/whm/1.jpg
|
||||
assets/whm/2.jpg
|
||||
assets/practices/whm/1.jpg
|
||||
assets/practices/whm/2.jpg
|
||||
assets/practices/meditation/1.jpg
|
||||
assets/fonts/locales.png
|
||||
assets/fonts/locales.dat
|
||||
assets/fonts/locales-8.png
|
||||
@@ -88,14 +93,25 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/main.c"
|
||||
"${SRC_DIR}/core/breath_engine.c"
|
||||
"${SRC_DIR}/app/app.c"
|
||||
"${SRC_DIR}/app/app_settings.c"
|
||||
"${SRC_DIR}/app/device_preferences.c"
|
||||
"${SRC_DIR}/session/session.c"
|
||||
"${SRC_DIR}/practices/practice_registry.c"
|
||||
"${SRC_DIR}/practices/whm/whm_practice.c"
|
||||
"${SRC_DIR}/practices/whm/whm_session.c"
|
||||
"${SRC_DIR}/practices/whm/whm_manual.c"
|
||||
"${SRC_DIR}/practices/whm/whm_config.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_practice.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_session.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_manual.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_config.c"
|
||||
"${SRC_DIR}/screens/habits_screen.c"
|
||||
"${SRC_DIR}/session/meditation_music.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_music.c"
|
||||
"${SRC_DIR}/core/locale.c"
|
||||
"${SRC_DIR}/core/theme.c"
|
||||
"${SRC_DIR}/storage/data.c"
|
||||
"${SRC_DIR}/storage/storage.c"
|
||||
"${SRC_DIR}/storage/sync_account.c"
|
||||
"${SRC_DIR}/storage/sync_client.c"
|
||||
"${SRC_DIR}/third_party/miniz.c"
|
||||
"${SQLITE_AMALGAMATION_C}"
|
||||
"${SRC_DIR}/platform/android/android_device.c"
|
||||
@@ -106,6 +122,10 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/screens/language_screen.c"
|
||||
"${SRC_DIR}/screens/manual_screen.c"
|
||||
"${SRC_DIR}/screens/settings/settings_screen.c"
|
||||
"${SRC_DIR}/screens/settings/settings_device.c"
|
||||
"${SRC_DIR}/screens/settings/settings_theme.c"
|
||||
"${SRC_DIR}/screens/settings/settings_data.c"
|
||||
"${SRC_DIR}/screens/settings/settings_sync_account.c"
|
||||
"${INBE_EMBEDDED_ASSETS_C}"
|
||||
${FLINT_SOURCES}
|
||||
"${SRC_DIR}/platform/android/android_insets.c"
|
||||
@@ -120,7 +140,9 @@ target_include_directories(main PRIVATE
|
||||
"${SRC_DIR}/core"
|
||||
"${SRC_DIR}/screens"
|
||||
"${SRC_DIR}/screens/settings"
|
||||
"${SRC_DIR}/session"
|
||||
"${SRC_DIR}/practices"
|
||||
"${SRC_DIR}/practices/whm"
|
||||
"${SRC_DIR}/practices/meditation"
|
||||
"${SRC_DIR}/storage"
|
||||
"${SRC_DIR}/platform/android"
|
||||
"${SRC_DIR}/third_party"
|
||||
@@ -141,6 +163,7 @@ target_compile_definitions(main PRIVATE
|
||||
SUPPORT_MODULE_RAUDIO=1
|
||||
SUPPORT_FILEFORMAT_OGG=1
|
||||
FLINT_EMBEDDED_ONLY=1
|
||||
INBE_HAS_LIBOQS=1
|
||||
)
|
||||
|
||||
target_compile_options(main PRIVATE
|
||||
@@ -158,6 +181,7 @@ target_link_options(main PRIVATE
|
||||
|
||||
target_link_libraries(main
|
||||
raylib
|
||||
oqs
|
||||
android
|
||||
log
|
||||
OpenSLES
|
||||
|
||||
@@ -26,11 +26,13 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class MainActivity extends NativeActivity {
|
||||
private static final String TAG = "InbeMainActivity";
|
||||
@@ -51,6 +53,7 @@ public class MainActivity extends NativeActivity {
|
||||
private boolean windowFocused = true;
|
||||
private boolean backgroundExecutionActive = false;
|
||||
private boolean autoPausedForLifecycle = false;
|
||||
private int lastDeleteRepeatCount = -1;
|
||||
|
||||
private native void nativeSetInsets(int status, int nav,
|
||||
int cutoutLeft, int cutoutTop, int cutoutRight, int cutoutBottom);
|
||||
@@ -149,18 +152,32 @@ public class MainActivity extends NativeActivity {
|
||||
if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
int keyCode = event.getKeyCode();
|
||||
if (keyCode == KeyEvent.KEYCODE_DEL) {
|
||||
nativeTextInputBackspace();
|
||||
int repeatCount = event.getRepeatCount();
|
||||
int deleteCount = lastDeleteRepeatCount < 0
|
||||
? 1
|
||||
: Math.max(1, repeatCount - lastDeleteRepeatCount);
|
||||
lastDeleteRepeatCount = repeatCount;
|
||||
for (int i = 0; i < deleteCount; i++) {
|
||||
nativeTextInputBackspace();
|
||||
}
|
||||
} else if (keyCode == KeyEvent.KEYCODE_ENTER ||
|
||||
keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
nativeTextInputEnter();
|
||||
} else {
|
||||
lastDeleteRepeatCount = -1;
|
||||
int unicode = event.getUnicodeChar();
|
||||
if (unicode >= 32) {
|
||||
nativeTextInputCommit(unicode);
|
||||
}
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_MULTIPLE &&
|
||||
event.getCharacters() != null) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
String chars = event.getCharacters();
|
||||
for (int i = 0; i < chars.length();) {
|
||||
int codepoint = chars.codePointAt(i);
|
||||
@@ -268,6 +285,68 @@ public class MainActivity extends NativeActivity {
|
||||
}, "inbe-runtime-asset-download").start();
|
||||
}
|
||||
|
||||
public String syncHttpRequest(String method, String urlText, String body, String[] headers) {
|
||||
HttpURLConnection connection = null;
|
||||
int status = 0;
|
||||
|
||||
try {
|
||||
byte[] bodyBytes = body != null ? body.getBytes(StandardCharsets.UTF_8) : new byte[0];
|
||||
connection = (HttpURLConnection)new URL(urlText).openConnection();
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setReadTimeout(30000);
|
||||
connection.setRequestMethod(method);
|
||||
connection.setRequestProperty("User-Agent", "inbe-sync/1");
|
||||
if (headers != null) {
|
||||
for (String header : headers) {
|
||||
if (header == null) continue;
|
||||
int colon = header.indexOf(':');
|
||||
if (colon <= 0) continue;
|
||||
String key = header.substring(0, colon).trim();
|
||||
String value = header.substring(colon + 1).trim();
|
||||
if (!key.isEmpty()) {
|
||||
connection.setRequestProperty(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("POST".equals(method) || "DELETE".equals(method)) {
|
||||
connection.setDoOutput(true);
|
||||
connection.setFixedLengthStreamingMode(bodyBytes.length);
|
||||
try (OutputStream output = connection.getOutputStream()) {
|
||||
output.write(bodyBytes);
|
||||
}
|
||||
}
|
||||
|
||||
status = connection.getResponseCode();
|
||||
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
|
||||
String response = "";
|
||||
if (stream != null) {
|
||||
try (InputStream input = stream) {
|
||||
byte[] bytes = readAllBytesCompat(input);
|
||||
response = new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return status + "\n" + response;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Sync HTTP request failed", e);
|
||||
return status + "\n" + (e.getMessage() != null ? e.getMessage() : "request failed");
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] readAllBytesCompat(InputStream input) throws java.io.IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
|
||||
while ((read = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, read);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
public void openImportPicker() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@@ -281,7 +360,8 @@ public class MainActivity extends NativeActivity {
|
||||
"application/x-zip-compressed",
|
||||
"application/vnd.sqlite3",
|
||||
"application/x-sqlite",
|
||||
"application/x-sqlite3"
|
||||
"application/x-sqlite3",
|
||||
"application/octet-stream"
|
||||
});
|
||||
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -11,6 +11,40 @@ import java.io.FileOutputStream;
|
||||
public class ShareHelper {
|
||||
private static final String TAG = "InbeShare";
|
||||
|
||||
public static void shareFile(Activity activity, byte[] data, String filename, String mimeType, String chooserTitle) {
|
||||
if (activity == null || data == null) return;
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File cacheFile = new File(activity.getCacheDir(), filename);
|
||||
FileOutputStream fos = new FileOutputStream(cacheFile);
|
||||
fos.write(data);
|
||||
fos.close();
|
||||
|
||||
Uri contentUri = FileProvider.getUriForFile(
|
||||
activity,
|
||||
"xyz.waozi.inbe.fileprovider",
|
||||
cacheFile
|
||||
);
|
||||
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.setType(mimeType != null ? mimeType : "application/octet-stream");
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
Intent shareIntent = Intent.createChooser(sendIntent, chooserTitle);
|
||||
activity.startActivity(shareIntent);
|
||||
|
||||
Log.i(TAG, "Share sheet shown");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Share failed", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void shareZipFile(Activity activity, byte[] zipData, String filename, String chooserTitle) {
|
||||
if (activity == null || zipData == null) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
### Changed
|
||||
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
|
||||
- Split the meditation manual into an image intro page and a shorter music/gong setup page.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Fixed Tickmate `.db` imports so zero-based months map correctly and long habit histories load without dropping later dates.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Added
|
||||
- optional sync client, offline account creation
|
||||
@@ -204,13 +204,16 @@ EOF
|
||||
libgbm
|
||||
libglvnd
|
||||
libglvnd.dev
|
||||
alsa-lib
|
||||
appimagetool
|
||||
libpulseaudio
|
||||
linuxdeploy
|
||||
linuxdeployPluginAppImage
|
||||
mesa
|
||||
ncurses
|
||||
ninja
|
||||
pkg-config
|
||||
pipewire
|
||||
rsync
|
||||
zlib
|
||||
zip
|
||||
|
||||
@@ -216,6 +216,8 @@ int ui_draw_slider_vertical_with_marks(int id, int x, int y, int h,
|
||||
int ui_draw_toggle_switch(int x, int y, int w, int h, int *value,
|
||||
const char *off_label, const char *on_label);
|
||||
int ui_draw_checkbox_toggle(int x, int y, const char *label, int *value);
|
||||
int ui_draw_checkbox_toggle_disabled(int x, int y, const char *label,
|
||||
int *value, int disabled);
|
||||
int ui_draw_dropdown_button(int id, int x, int y, int w, int h, const char **options, int option_count, int *selected_index);
|
||||
int ui_draw_dropdown_menu(int id);
|
||||
int ui_dropdown_captures_click(Vector2 point);
|
||||
|
||||
@@ -38,6 +38,10 @@ void flint_file_dialog_set_theme_scope(const char *scope) {
|
||||
|
||||
static FlintFileDialogInternal *create_internal(void) {
|
||||
FlintFileDialogInternal *internal = calloc(1, sizeof(FlintFileDialogInternal));
|
||||
if(internal != NULL) {
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
}
|
||||
return internal;
|
||||
}
|
||||
|
||||
@@ -214,6 +218,9 @@ static int scan_directory(FlintFileDialogInternal *internal) {
|
||||
qsort(internal->entries, internal->file_count,
|
||||
sizeof(DirEntry), compare_entries);
|
||||
}
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->last_click_time = 0.0f;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -306,7 +313,7 @@ static void render_file_list(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
int list_x = dialog_rect.x + flint_px(16);
|
||||
int scrollbar_w = flint_px(12);
|
||||
int list_width = dialog_rect.width - flint_px(32);
|
||||
int bottom_y = dialog_rect.y + internal->dialog_height - flint_px(72);
|
||||
int bottom_y = dialog_rect.y + internal->dialog_height - flint_px(112);
|
||||
int list_height = bottom_y - list_y;
|
||||
if(list_height < FILE_DIALOG_ITEM_HEIGHT)
|
||||
list_height = FILE_DIALOG_ITEM_HEIGHT;
|
||||
@@ -401,12 +408,11 @@ static void render_scrollbar(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
static void render_filename_input(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
FlintFileDialogInternal *internal = (FlintFileDialogInternal *)dlg->_internal;
|
||||
|
||||
int input_y = dialog_rect.y + internal->dialog_height - flint_px(58);
|
||||
int input_y = dialog_rect.y + internal->dialog_height - flint_px(96);
|
||||
int input_x = dialog_rect.x + flint_px(16);
|
||||
int font = flint_ui_font_small();
|
||||
int label_width = flint_text_measure("Filename:", font) + flint_px(8);
|
||||
int button_area_width = flint_px(176);
|
||||
int input_width = dialog_rect.width - flint_px(32) - label_width - button_area_width;
|
||||
int input_width = dialog_rect.width - flint_px(32) - label_width;
|
||||
int input_height = flint_px(24);
|
||||
if(input_width < flint_px(24))
|
||||
input_width = flint_px(24);
|
||||
@@ -575,9 +581,10 @@ static int handle_mouse_input(FlintFileDialog *dlg) {
|
||||
if(hover_idx >= 0 && hover_idx < internal->file_count) {
|
||||
float current_time = GetTime();
|
||||
if(current_time - internal->last_click_time < 0.5 &&
|
||||
internal->hover_index == hover_idx) {
|
||||
internal->last_clicked_index == hover_idx) {
|
||||
if(internal->entries[hover_idx].is_dir) {
|
||||
navigate_into(internal, internal->entries[hover_idx].name);
|
||||
internal->last_clicked_index = -1;
|
||||
} else {
|
||||
copy_text(internal->selected_file, sizeof(internal->selected_file),
|
||||
internal->entries[hover_idx].name);
|
||||
@@ -595,6 +602,7 @@ static int handle_mouse_input(FlintFileDialog *dlg) {
|
||||
}
|
||||
|
||||
internal->last_click_time = current_time;
|
||||
internal->last_clicked_index = hover_idx;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,7 +779,8 @@ flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title)
|
||||
scan_directory(internal);
|
||||
internal->filename_input[0] = '\0';
|
||||
internal->selected_file[0] = '\0';
|
||||
internal->hover_index = 0;
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->focus_area = 0;
|
||||
}
|
||||
|
||||
@@ -839,7 +848,8 @@ int flint_file_dialog_select_folder(FlintFileDialog *dlg, const char *title) {
|
||||
FlintFileDialogInternal *internal = (FlintFileDialogInternal *)dlg->_internal;
|
||||
internal->filename_input[0] = '\0';
|
||||
internal->selected_file[0] = '\0';
|
||||
internal->hover_index = 0;
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->focus_area = 0;
|
||||
|
||||
if(run_dialog(dlg)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ typedef struct {
|
||||
DirEntry *entries;
|
||||
int scroll_offset;
|
||||
int hover_index;
|
||||
int last_clicked_index;
|
||||
int focus_area;
|
||||
Rectangle breadcrumb_rect;
|
||||
Rectangle file_list_rect;
|
||||
|
||||
@@ -50,6 +50,7 @@ static int g_ui_text_input_codepoints[UI_TEXT_INPUT_QUEUE_MAX];
|
||||
static int g_ui_text_input_codepoint_count = 0;
|
||||
static int g_ui_text_input_backspace_count = 0;
|
||||
static int g_ui_text_input_enter_count = 0;
|
||||
static double g_ui_backspace_next_repeat_at = 0.0;
|
||||
|
||||
#define UI_INPUT_CLIP_STACK_MAX 16
|
||||
static Rectangle g_ui_input_clip_stack[UI_INPUT_CLIP_STACK_MAX];
|
||||
@@ -88,6 +89,32 @@ ui_pointer_dx(void)
|
||||
return (int)mouse.x - g_ui_pointer_start_x;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_backspace_repeat_count(void)
|
||||
{
|
||||
double now;
|
||||
int count = 0;
|
||||
|
||||
if(IsKeyPressed(KEY_BACKSPACE)) {
|
||||
g_ui_backspace_next_repeat_at = GetTime() + 0.34;
|
||||
return 1;
|
||||
}
|
||||
if(!IsKeyDown(KEY_BACKSPACE)) {
|
||||
g_ui_backspace_next_repeat_at = 0.0;
|
||||
return 0;
|
||||
}
|
||||
now = GetTime();
|
||||
if(g_ui_backspace_next_repeat_at <= 0.0) {
|
||||
g_ui_backspace_next_repeat_at = now + 0.34;
|
||||
return 0;
|
||||
}
|
||||
while(now >= g_ui_backspace_next_repeat_at && count < 8) {
|
||||
count++;
|
||||
g_ui_backspace_next_repeat_at += 0.045;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_pointer_dy(void)
|
||||
{
|
||||
@@ -650,8 +677,8 @@ flint_ui_text_edit(FlintUITextEdit edit)
|
||||
changed = 1;
|
||||
}
|
||||
|
||||
if(IsKeyPressed(KEY_BACKSPACE) || g_ui_text_input_backspace_count > 0) {
|
||||
int repeat = g_ui_text_input_backspace_count > 0 ? g_ui_text_input_backspace_count : 1;
|
||||
{
|
||||
int repeat = g_ui_text_input_backspace_count + ui_backspace_repeat_count();
|
||||
for(int i = 0; i < repeat; i++) {
|
||||
int start = ui_utf8_prev_offset(edit.text, *edit.cursor_position);
|
||||
changed |= ui_text_delete_range(edit.text, edit.text_size,
|
||||
@@ -1132,6 +1159,7 @@ ui_draw_text_btn(int x, int y, const char *label, int *hover)
|
||||
Vector2 mouse_world = ui_mouse_world();
|
||||
int mx = (int)mouse_world.x;
|
||||
int my = (int)mouse_world.y;
|
||||
int local_hover = 0;
|
||||
|
||||
int mb = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
||||
int released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
@@ -1140,6 +1168,8 @@ ui_draw_text_btn(int x, int y, const char *label, int *hover)
|
||||
int h = flint_clamp_px(30, 26, 34);
|
||||
|
||||
x = x - w / 2;
|
||||
if(!hover)
|
||||
hover = &local_hover;
|
||||
|
||||
int pressed = 0;
|
||||
|
||||
@@ -1666,37 +1696,55 @@ ui_draw_toggle_switch(int x, int y, int w, int h, int *value,
|
||||
}
|
||||
|
||||
int
|
||||
ui_draw_checkbox_toggle(int x, int y, const char *label, int *value)
|
||||
ui_draw_checkbox_toggle_disabled(int x, int y, const char *label,
|
||||
int *value, int disabled)
|
||||
{
|
||||
int font = flint_ui_font();
|
||||
int box_size = flint_px(22);
|
||||
int hover = 0;
|
||||
Rectangle bounds = {x, y, box_size, box_size};
|
||||
Vector2 mouse_world = ui_mouse_world();
|
||||
Color box_color = disabled ? flint_darken(c_button, 18) : c_button;
|
||||
Color mark_color = disabled ? flint_darken(c_text, 35) : c_text;
|
||||
Color label_color = disabled ? flint_darken(c_text, 35) : c_text;
|
||||
|
||||
if(CheckCollisionPointRec(mouse_world, bounds) && !ui_input_captures_click(mouse_world)) {
|
||||
hover = 1;
|
||||
ui_mark_clickable();
|
||||
if(disabled)
|
||||
ui_mark_disabled();
|
||||
else {
|
||||
hover = 1;
|
||||
ui_mark_clickable();
|
||||
}
|
||||
}
|
||||
|
||||
int pressed = hover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
if(pressed)
|
||||
*value = !(*value);
|
||||
|
||||
DrawRectangle(x, y, box_size, box_size, c_button);
|
||||
DrawRectangle(x, y, box_size, box_size, box_color);
|
||||
ui_draw_bevel(x, y, box_size, box_size, flint_darken(c_bg, 30), flint_lighten(c_bg, 20));
|
||||
|
||||
if(*value) {
|
||||
int padding = flint_px(4);
|
||||
DrawLine(x + padding, y + padding, x + box_size / 2, y + box_size - padding, c_text);
|
||||
DrawLine(x + box_size / 2, y + box_size - padding, x + box_size - padding, y + padding, c_text);
|
||||
DrawLine(x + padding, y + padding, x + box_size / 2,
|
||||
y + box_size - padding, mark_color);
|
||||
DrawLine(x + box_size / 2, y + box_size - padding,
|
||||
x + box_size - padding, y + padding, mark_color);
|
||||
}
|
||||
|
||||
flint_text_draw(label, x + box_size + flint_px(10), flint_ui_text_y(label, y, box_size, font), font, c_text);
|
||||
flint_text_draw(label, x + box_size + flint_px(10),
|
||||
flint_ui_text_y(label, y, box_size, font),
|
||||
font, label_color);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
int
|
||||
ui_draw_checkbox_toggle(int x, int y, const char *label, int *value)
|
||||
{
|
||||
return ui_draw_checkbox_toggle_disabled(x, y, label, value, 0);
|
||||
}
|
||||
|
||||
/* Per-dropdown state to track open/closed and click handling */
|
||||
typedef struct UIDropdownState {
|
||||
int id;
|
||||
|
||||
@@ -40,8 +40,11 @@ Meditace
|
||||
[meditation_manual_title]
|
||||
Meditace
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Vyberte hudbu, pokud pomáhá sezení zklidnit, a pohodlně se posaďte. Nechte pozornost spočinout na dechu. Když vás myšlenky odvedou, jasně si toho všimněte a vraťte se bez úsilí. Gong označí začátek i konec.
|
||||
Vyberte hudbu, pokud chcete. Gong oznaci zacatek a konec.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditační hudba
|
||||
@@ -394,21 +397,20 @@ Nikdy ho nepoužívejte při řízení,
|
||||
vestoje ani ve vodě.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Stačí postupovat ve 4 krocích:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Dýchejte rytmicky.
|
||||
2. Vydechněte a zadržte dech.
|
||||
3. Zhluboka se nadechněte a zadržte dech.
|
||||
4. Vydechněte a opakujte.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Pomocí ikony ozubeného kola %i upravíte kola, nádechy, rychlost a pauzy.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Naplňte plíce úplně a potom nechte dech volně odejít.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Tímto posuvníkem nastavíte tempo dechového kruhu.
|
||||
|
||||
Najděte rytmus, který vám připadá přirozený.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Postupná rychlost usnadňuje vstup do prvního kola.
|
||||
@@ -416,17 +418,14 @@ Postupná rychlost usnadňuje vstup do prvního kola.
|
||||
Když je zapnutá, první kolo začne rychlostí 1 pro prvních 5 nádechů a potom se postupně zvýší na vámi vybranou rychlost.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Po dechovém kole
|
||||
normálně vydechněte a zadržte dech.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Uvolněte se, až si tělo řekne
|
||||
o vzduch. Nenuťte to.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Plně se nadechněte a zadržte dech asi na 15 sekund.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Potom vydechněte a začněte další kolo.
|
||||
Časem může každé kolo působit hlouběji.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
PŘESKOČIT
|
||||
@@ -491,3 +490,90 @@ Na šířku
|
||||
[orientation_sensor]
|
||||
Senzor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditation
|
||||
[meditation_manual_title]
|
||||
Meditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Wähle Musik, wenn sie die Sitzung ruhiger macht, und setze dich bequem hin. Lass die Aufmerksamkeit auf dem Atem ruhen. Wenn Gedanken dich wegziehen, bemerke es klar und kehre ohne Druck zurück. Ein Gong markiert Anfang und Ende.
|
||||
Wahlen Sie Musik, wenn Sie mochten. Ein Gong markiert Anfang und Ende.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditationsmusik
|
||||
@@ -394,21 +397,20 @@ Benutzen Sie sie niemals beim Fahren,
|
||||
Stehen oder im Wasser.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Folgen Sie einfach 4 Schritten:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Atmen Sie rhythmisch.
|
||||
2. Atmen Sie aus und halten Sie.
|
||||
3. Atmen Sie tief ein und halten Sie.
|
||||
4. Atmen Sie aus und wiederholen Sie.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Nutzen Sie das Schraubenschlüssel-Symbol %i, um Runden, Atemzüge, Geschwindigkeit und Pausen anzupassen.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Füllen Sie Ihre Lungen vollständig, dann lassen Sie den Atem herausfließen.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Nutzen Sie diesen Schieberegler, um das Tempo des Atemkreises einzustellen.
|
||||
|
||||
Finden Sie einen Rhythmus, der sich natürlich für Sie anfühlt.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Progressive Geschwindigkeit macht den Einstieg in die erste Runde leichter.
|
||||
@@ -416,17 +418,14 @@ Progressive Geschwindigkeit macht den Einstieg in die erste Runde leichter.
|
||||
Wenn sie aktiviert ist, beginnt die erste Runde bei Geschwindigkeit 1 für die ersten 5 Atemzüge und steigt dann schrittweise auf Ihre gewählte Geschwindigkeit.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Nach der Atemrunde,
|
||||
atmen Sie normal aus und halten Sie.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Lassen Sie los, wenn Ihr Körper
|
||||
nach Luft verlangt. Zwängen Sie es nicht.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Atmen Sie vollständig ein und halten Sie etwa 15 Sekunden.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Dann atmen Sie aus und beginnen die nächste Runde.
|
||||
Mit der Zeit kann sich jede Runde tiefer anfühlen.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -491,3 +490,90 @@ Querformat
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditation
|
||||
[meditation_manual_title]
|
||||
Meditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Choose music if it helps the session feel steady, then sit comfortably. Let attention rest on the breath. When thoughts pull you away, notice that clearly and return without force. A gong marks the beginning and end.
|
||||
Choose music if you want it. A gong marks the beginning and end.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Meditation Music
|
||||
@@ -415,21 +418,20 @@ Never use it while driving,
|
||||
standing, or in water.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Simply follow 4 steps:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Breathe rhythmically.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. Inhale deeply and hold.
|
||||
4. Exhale and repeat.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Fill your lungs fully, then let the breath flow out.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use this slider to set the pace of the breathing circle.
|
||||
|
||||
Find a rhythm that feels natural for you.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Progressive speed makes the first round easier to enter.
|
||||
@@ -437,17 +439,14 @@ Progressive speed makes the first round easier to enter.
|
||||
When it is on, the first round starts slower, then gradually increases to your selected speed.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Exhale normally and hold.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
The center number keeps counting. Circle mode adds layered progress lines.
|
||||
|
||||
Release when your body asks for air.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inhale fully and hold for about 15 seconds.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Then exhale and begin the next round.
|
||||
Over time, each round may feel deeper.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -491,3 +490,90 @@ Delete this round? This cannot be undone.
|
||||
[delete_button]
|
||||
Delete
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditación
|
||||
[meditation_manual_title]
|
||||
Meditación
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Elige música si ayuda a que la sesión se sienta estable y siéntate cómodamente. Deja que la atención descanse en la respiración. Cuando los pensamientos te arrastren, obsérvalo con claridad y vuelve sin forzar. Un gong marca el inicio y el final.
|
||||
Elige musica si quieres. Un gong marca el inicio y el final.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Música de meditación
|
||||
@@ -394,21 +397,20 @@ Nunca la use mientras conduce,
|
||||
de pie o en el agua.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Simplemente siga 4 pasos:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respire rítmicamente.
|
||||
2. Exhale y retenga.
|
||||
3. Inhale profundamente y retenga.
|
||||
4. Exhale y repita.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Use el icono de llave %i para ajustar rondas, respiraciones, velocidad y pausas.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Llene sus pulmones completamente, luego deje que el respiración fluya hacia afuera.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use este control deslizante para establecer el ritmo del círculo de respiración.
|
||||
|
||||
Encuentre un ritmo que se sienta natural para usted.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La velocidad progresiva hace que la primera ronda sea más fácil de empezar.
|
||||
@@ -416,17 +418,14 @@ La velocidad progresiva hace que la primera ronda sea más fácil de empezar.
|
||||
Cuando está activada, la primera ronda comienza en velocidad 1 durante las primeras 5 respiraciones y luego aumenta gradualmente hasta la velocidad elegida.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Después de la ronda de respiración,
|
||||
exhale normalmente y retenga.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Suelte cuando su cuerpo pida
|
||||
aire. No lo fuerce.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inhale completamente y retenga unos 15 segundos.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Luego exhale y comience la siguiente ronda.
|
||||
Con el tiempo, cada ronda puede sentirse más profunda.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
OMITIR
|
||||
@@ -491,3 +490,90 @@ Horizontal
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Méditation
|
||||
[meditation_manual_title]
|
||||
Méditation
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Choisissez une musique si elle aide la séance à rester stable, puis asseyez-vous confortablement. Laissez l’attention se poser sur le souffle. Quand les pensées vous emportent, voyez-le clairement et revenez sans forcer. Un gong marque le début et la fin.
|
||||
Choisissez de la musique si vous le souhaitez. Un gong marque le debut et la fin.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musique de méditation
|
||||
@@ -394,21 +397,20 @@ Ne l'utilisez jamais en conduisant,
|
||||
debout ou dans l'eau.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Suivez simplement 4 étapes :
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respirez en rythme.
|
||||
2. Expirez et retenez.
|
||||
3. Inspirez profondément et retenez.
|
||||
4. Expirez et répétez.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Utilisez l'icône de clé %i pour régler les cycles, respirations, vitesse et pauses.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Remplissez complètement vos poumons, puis laissez le souffle sortir.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Utilisez ce curseur pour régler le rythme du cercle de respiration.
|
||||
|
||||
Trouvez un rythme naturel pour vous.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La vitesse progressive rend le premier cycle plus facile à commencer.
|
||||
@@ -416,17 +418,14 @@ La vitesse progressive rend le premier cycle plus facile à commencer.
|
||||
Quand elle est activée, le premier cycle commence à la vitesse 1 pendant les 5 premières respirations, puis augmente progressivement jusqu'à la vitesse choisie.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Après le cycle de respiration,
|
||||
expirez normalement et retenez.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Relâchez quand votre corps demande
|
||||
de l'air. Ne forcez pas.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspirez complètement et retenez environ 15 secondes.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Puis expirez et commencez le cycle suivant.
|
||||
Avec le temps, chaque cycle peut sembler plus profond.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -491,3 +490,90 @@ Paysage
|
||||
[orientation_sensor]
|
||||
Capteur
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditasi
|
||||
[meditation_manual_title]
|
||||
Meditasi
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Pilih musik jika membantu sesi terasa stabil, lalu duduk dengan nyaman. Biarkan perhatian beristirahat pada napas. Saat pikiran menarikmu pergi, sadari dengan jelas dan kembali tanpa memaksa. Gong menandai awal dan akhir.
|
||||
Pilih musik jika Anda mau. Gong menandai awal dan akhir.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musik meditasi
|
||||
@@ -394,21 +397,20 @@ Jangan gunakan saat mengemudi,
|
||||
berdiri, atau di dalam air.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Ikuti 4 langkah sederhana:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Bernapas secara ritmis.
|
||||
2. Buang napas dan tahan.
|
||||
3. Tarik napas dalam dan tahan.
|
||||
4. Buang napas dan ulangi.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Gunakan ikon kunci pas %i untuk menyesuaikan ronde, nafas, kecepatan, dan jeda.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Isi paru-paru Anda sepenuhnya, lalu biarkan napas keluar.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Gunakan slider ini untuk mengatur kecepatan lingkaran pernapasan.
|
||||
|
||||
Temukan ritme yang terasa alami bagi Anda.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Kecepatan progresif membuat ronde pertama lebih mudah dimulai.
|
||||
@@ -416,17 +418,14 @@ Kecepatan progresif membuat ronde pertama lebih mudah dimulai.
|
||||
Saat aktif, ronde pertama dimulai pada kecepatan 1 untuk 5 nafas pertama, lalu bertambah hingga kecepatan yang dipilih.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Setelah ronde pernapasan,
|
||||
buang napas secara normal dan tahan.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Lepaskan saat tubuh Anda
|
||||
meminta udara. Jangan dipaksa.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Tarik napas sepenuhnya dan tahan sekitar 15 detik.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Lalu buang napas dan mulai ronde berikutnya.
|
||||
Seiring waktu, setiap ronde mungkin terasa lebih dalam.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
LEWATI
|
||||
@@ -491,3 +490,90 @@ Lanskap
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditazione
|
||||
[meditation_manual_title]
|
||||
Meditazione
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Scegli la musica se aiuta la sessione a sentirsi stabile, poi siediti comodamente. Lascia che l'attenzione riposi sul respiro. Quando i pensieri ti portano via, notalo con chiarezza e torna senza forzare. Un gong segna l'inizio e la fine.
|
||||
Scegli la musica se vuoi. Un gong segna l inizio e la fine.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Musica Meditazione
|
||||
@@ -410,21 +413,20 @@ Non usarla mai mentre guidi,
|
||||
in piedi o in acqua.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Segui semplicemente 4 passi:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respira ritmicamente.
|
||||
2. Espira e trattieni.
|
||||
3. Inspira profondamente e trattieni.
|
||||
4. Espira e ripeti.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Usa l'icona ingranaggio %i per regolare round, respiri, velocità e pause.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Riempi completamente i polmoni, poi lascia uscire il respiro.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Usa questo slider per impostare il ritmo del cerchio respiratorio.
|
||||
|
||||
Trova un ritmo che ti sembri naturale.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La velocità progressiva rende il primo round più facile da affrontare.
|
||||
@@ -432,17 +434,14 @@ La velocità progressiva rende il primo round più facile da affrontare.
|
||||
Quando è attiva, il primo round inizia più lentamente, poi aumenta gradualmente fino alla velocità selezionata.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Espira normalmente e trattieni.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Il numero centrale continua a contare. La modalità cerchio aggiunge linee di progresso sovrapposte.
|
||||
|
||||
Rilascia quando il corpo richiede aria.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspira completamente e trattieni per circa 15 secondi.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Poi espira e inizia il prossimo round.
|
||||
Col tempo, ogni round potrebbe sembrare più profondo.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SALTA
|
||||
@@ -489,3 +488,90 @@ Elimina
|
||||
[meditation_music_attribution]
|
||||
Musica di Elijah_K.
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@
|
||||
[meditation_manual_title]
|
||||
瞑想
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
音楽が集中を支えてくれるなら選び、楽な姿勢で座ります。注意を呼吸に置きます。思考に引かれたら、はっきり気づき、力まず戻ります。ゴングが始まりと終わりを知らせます。
|
||||
必要なら音楽を選んでください。ゴングが始まりと終わりを知らせます。
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
瞑想音楽
|
||||
@@ -396,31 +399,33 @@ ON
|
||||
立っているとき、水中では行わないでください。
|
||||
---
|
||||
[tutorial_step_method]
|
||||
次の 4 つの手順に従います。
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. リズミカルに呼吸します。
|
||||
2. 吐いて止めます。
|
||||
3. 深く吸って止めます。
|
||||
4. 吐いて繰り返します。
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
歯車アイコン %i でラウンド数、呼吸数、速度、一時停止を調整できます。
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
肺をいっぱいに満たしてから、息を自然に吐き出します。
|
||||
Breathe in and out 30 times.
|
||||
|
||||
このスライダーで呼吸のテンポを設定します。
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
段階的速度は、最初のラウンドに入りやすくします。
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
呼吸ラウンドの後、
|
||||
息を吐いて止めます。
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
吸う必要を感じるまで止めます。
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
深く吸って、約 15 秒止めます。
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
スキップ
|
||||
@@ -485,3 +490,90 @@ Inner Breeze データ書き出し
|
||||
[orientation_sensor]
|
||||
センサー
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Inner Breeze
|
||||
[meditation_manual_title]
|
||||
명상
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
음악이 세션을 안정되게 해 준다면 선택한 뒤 편안하게 앉으세요. 주의를 호흡에 둡니다. 생각에 끌려가면 분명히 알아차리고 힘주지 말고 돌아오세요. 공 소리가 시작과 끝을 알립니다.
|
||||
원하면 음악을 선택하세요. 징 소리가 시작과 끝을 알립니다.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
명상 음악
|
||||
@@ -409,21 +412,20 @@ In / Out
|
||||
운전 중, 서 있거나 물속에서는 사용하지 마세요.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
다음 4단계를 따르세요:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. 리듬적으로 호흡합니다.
|
||||
2. 내뱉고 참습니다.
|
||||
3. 깊게 들이마시고 참습니다.
|
||||
4. 내뱉고 반복합니다.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
톱니바퀴 아이콘 %i을 사용하여 라운드, 호흡, 속도 및 일시정지를 조정할 수 있습니다.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
폐를 완전히 채운 후 자연스럽게 내뱉으세요.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
이 슬라이더로 호흡 원의 속도를 설정합니다.
|
||||
|
||||
자연스러운 리듬을 찾아보세요.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
점진적 속도는 첫 라운드를 쉽게 시작할 수 있게 해줍니다.
|
||||
@@ -431,17 +433,14 @@ In / Out
|
||||
켜면 첫 라운드가 느리게 시작된 후 점차 선택한 속도까지 증가합니다.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
자연스럽게 내뱉고 참습니다.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
중앙 숫자가 계속 카운트됩니다. 원형 모드는 여러 진행 막대를 표시합니다.
|
||||
|
||||
몸이 공기를 필요로 할 때 놓으세요.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
완전히 들이마시고 약 15초간 참으세요.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
그 후 내뱉고 다음 라운드를 시작하세요.
|
||||
시간이 지날수록 각 라운드가 더 깊어질 수 있습니다.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
건너뛰기
|
||||
@@ -488,3 +487,90 @@ Inner Breeze 데이터 내보내기
|
||||
[meditation_music_attribution]
|
||||
음악: Elijah_K.
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Meditação
|
||||
[meditation_manual_title]
|
||||
Meditação
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
Escolha uma música se ela ajudar a sessão a ficar estável e sente-se confortavelmente. Deixe a atenção repousar na respiração. Quando os pensamentos puxarem você, perceba com clareza e volte sem forçar. Um gongo marca o começo e o fim.
|
||||
Escolha musica se quiser. Um gongo marca o inicio e o fim.
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
Música de meditação
|
||||
@@ -394,21 +397,20 @@ Nunca use enquanto dirige,
|
||||
em pé ou na água.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Basta seguir 4 passos:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respire ritmicamente.
|
||||
2. Expire e segure.
|
||||
3. Inspire profundamente e segure.
|
||||
4. Expire e repita.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Use o ícone de chave inglesa %i para ajustar rodadas, respirações, velocidade e pausas.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Encha totalmente os pulmões e deixe o ar sair.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use este controle para definir o ritmo do círculo de respiração.
|
||||
|
||||
Encontre um ritmo que pareça natural para você.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
A velocidade progressiva torna a primeira rodada mais fácil de começar.
|
||||
@@ -416,17 +418,14 @@ A velocidade progressiva torna a primeira rodada mais fácil de começar.
|
||||
Quando ativada, a primeira rodada começa na velocidade 1 nas primeiras 5 respirações e depois aumenta gradualmente até a velocidade escolhida.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Depois da rodada de respiração,
|
||||
expire normalmente e segure.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Solte quando seu corpo pedir
|
||||
ar. Não force.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspire totalmente e segure por cerca de 15 segundos.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Depois expire e comece a próxima rodada.
|
||||
Com o tempo, cada rodada pode parecer mais profunda.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -491,3 +490,90 @@ Paisagem
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -40,8 +40,11 @@ Wim Hof 呼吸
|
||||
[meditation_manual_title]
|
||||
冥想
|
||||
---
|
||||
[meditation_manual_intro_text]
|
||||
Settle into a quiet seat and let this session be simple: arrive, breathe, and begin.
|
||||
---
|
||||
[meditation_manual_text]
|
||||
如果音乐能让练习更安稳,就先选择音乐,然后舒适地坐下。把注意力放在呼吸上。被念头带走时,清楚地觉察,再不费力地回来。钟声会提示开始和结束。
|
||||
如果需要,可以选择音乐。锣声会提示开始和结束。
|
||||
---
|
||||
[meditation_music_settings_title]
|
||||
冥想音乐
|
||||
@@ -394,31 +397,33 @@ Deleted %lld sessions
|
||||
站立或水中时进行。
|
||||
---
|
||||
[tutorial_step_method]
|
||||
按照 4 个步骤进行:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. 有节奏地呼吸。
|
||||
2. 呼气并屏息。
|
||||
3. 深吸气并屏息。
|
||||
4. 呼气并重复。
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
使用齿轮图标 %i 调整轮次、呼吸次数、速度和暂停时间。
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
充分充满肺部,然后让呼吸自然流出。
|
||||
Breathe in and out 30 times.
|
||||
|
||||
使用这个滑块设置呼吸圆的节奏。
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
递进速度会让第一轮更容易进入。
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
完成一轮呼吸后,
|
||||
呼气并屏住。
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
屏息到需要吸气为止。
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
充分吸气并屏住约 15 秒。
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
跳过
|
||||
@@ -483,3 +488,90 @@ Inner Breeze 数据导出
|
||||
[orientation_sensor]
|
||||
传感器
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
@@ -41,8 +41,9 @@ fi
|
||||
mkdir -p build
|
||||
sh flint/scripts/embed-assets.sh build/inbe_embedded_assets.c \
|
||||
locales/*.txt \
|
||||
assets/whm/1.jpg \
|
||||
assets/whm/2.jpg \
|
||||
assets/practices/whm/1.jpg \
|
||||
assets/practices/whm/2.jpg \
|
||||
assets/practices/meditation/1.jpg \
|
||||
assets/fonts/locales.png \
|
||||
assets/fonts/locales.dat \
|
||||
assets/fonts/locales-8.png \
|
||||
|
||||
@@ -5,14 +5,11 @@
|
||||
#include "screens/manual_screen.h"
|
||||
#include "screens/settings/settings_screen.h"
|
||||
#include "screens/practice_screen.h"
|
||||
#include "session.h"
|
||||
#include "practices/practice_registry.h"
|
||||
#include "device_preferences.h"
|
||||
#include "meditation_music.h"
|
||||
#include "storage.h"
|
||||
#include "sync_client.h"
|
||||
#include "theme.h"
|
||||
#if defined(LOTUS_BUILD)
|
||||
#include "lotus_settings.h"
|
||||
#endif
|
||||
#include "version.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
@@ -40,6 +37,8 @@ void set_global_inbe_app(InbeApp *app);
|
||||
|
||||
#define INBE_DEFAULT_WIDTH 320
|
||||
#define INBE_DEFAULT_HEIGHT 560
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_ENABLED_KEY "sync_enabled"
|
||||
|
||||
InbeConfig config = {
|
||||
.title = "Inner Breeze",
|
||||
@@ -49,6 +48,29 @@ InbeConfig config = {
|
||||
.title_custom = 1
|
||||
};
|
||||
|
||||
int
|
||||
inbe_app_auto_sync(InbeApp *app)
|
||||
{
|
||||
const char *saved_url;
|
||||
char url[256];
|
||||
InbeSyncClientResult result;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(inbe_storage_get_setting_int(INBE_SYNC_ENABLED_KEY, 0) == 0)
|
||||
return 0;
|
||||
saved_url = inbe_storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
if(!inbe_sync_client_normalize_url(saved_url, url, sizeof(url)))
|
||||
return 0;
|
||||
result = inbe_sync_client_sync(url);
|
||||
if(result != INBE_SYNC_CLIENT_OK) {
|
||||
TraceLog(LOG_WARNING, "INBE: auto sync failed result=%d", result);
|
||||
return 0;
|
||||
}
|
||||
TraceLog(LOG_INFO, "INBE: auto sync complete");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int view_width = INBE_DEFAULT_WIDTH;
|
||||
int view_height = INBE_DEFAULT_HEIGHT;
|
||||
/* Theme colors are now accessed via theme accessor functions */
|
||||
@@ -62,9 +84,6 @@ int view_height = INBE_DEFAULT_HEIGHT;
|
||||
#define LOCALE_FONT_8_BASE_SIZE 8
|
||||
|
||||
|
||||
/* Forward declarations for tab callbacks */
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
|
||||
static void
|
||||
app_leave_practice_config(InbeApp *app)
|
||||
{
|
||||
@@ -72,7 +91,11 @@ app_leave_practice_config(InbeApp *app)
|
||||
return;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
meditation_music_unload(app);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->leave_config != NULL)
|
||||
practice->leave_config(app);
|
||||
}
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
|
||||
@@ -219,38 +242,6 @@ mark_exercise_manual_seen(InbeApp *app, int exercise_type)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LOTUS_BUILD)
|
||||
static void
|
||||
sync_lotus_settings(InbeApp *app)
|
||||
{
|
||||
const LotusSettings *lotus;
|
||||
unsigned int version;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
version = lotus_settings_version();
|
||||
if(app->lotus_settings_version == version)
|
||||
return;
|
||||
|
||||
lotus = lotus_settings_get();
|
||||
app->theme_id = lotus->theme;
|
||||
app->theme_mode = lotus->dark_mode ? APP_THEME_DARK : APP_THEME_LIGHT;
|
||||
app->dark_mode = app_effective_dark_mode(app);
|
||||
snprintf(app->language, sizeof(app->language), "%.*s",
|
||||
(int)sizeof(app->language) - 1, lotus->language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
|
||||
app_refresh_theme(app);
|
||||
refresh_locale_dependent_text(app);
|
||||
app->lotus_settings_version = version;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ================================================================
|
||||
* TAB BAR DEFINITIONS
|
||||
* ================================================================ */
|
||||
@@ -432,33 +423,6 @@ init_web_storage(void)
|
||||
web_storage_ready = ok != 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sync_web_storage(void)
|
||||
{
|
||||
EM_ASM({
|
||||
if(typeof FS !== 'undefined' && typeof FS.syncfs === 'function') {
|
||||
if(Module.inbeSyncfsTimer)
|
||||
clearTimeout(Module.inbeSyncfsTimer);
|
||||
Module.__inbeStorageSyncPending = true;
|
||||
Module.inbeSyncfsTimer = setTimeout(function() {
|
||||
Module.inbeSyncfsTimer = 0;
|
||||
Module.__inbeStorageSyncing = true;
|
||||
try {
|
||||
FS.syncfs(false, function(err) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
if(err) console.error("IDBFS save failed:", err);
|
||||
else console.log("IDBFS synced");
|
||||
});
|
||||
} catch(e) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
console.error("IDBFS sync error:", e);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
@@ -506,173 +470,6 @@ int_from_count(const char src[CountSize])
|
||||
return a * 100 + b * 10 + c;
|
||||
}
|
||||
|
||||
void
|
||||
apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds)
|
||||
{
|
||||
speed = clampi(speed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
inbe->speed_level = speed;
|
||||
inbe->breath_half_ticks = inbe_breath_half_ticks_for_speed(speed);
|
||||
inbe->breath_animation = clampi(inbe->breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
inbe->progressive_start_speed = clampi(inbe->progressive_start_speed, SETTINGS_SPEED_MIN, speed);
|
||||
inbe->max_rounds = clampi(max_rounds, 1, MaxRounds);
|
||||
inbe->pause_seconds = clampi(pause_seconds, SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX);
|
||||
count_from_int(inbe->maxbreaths, clampi(max_breaths, SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX));
|
||||
}
|
||||
|
||||
void
|
||||
reset_settings_preview(InbeApp *app)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
int breath_animation = app->inbe.breath_animation;
|
||||
int content_w;
|
||||
|
||||
inbeinit(&app->settings_preview);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_preview.play_in_background = play_in_background;
|
||||
app->settings_preview.breath_animation = breath_animation;
|
||||
flint_centered_column(CONTENT_MAX_W, CONTENT_SIDE_PAD, NULL, &content_w);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
session_reset_round_breathe(&app->settings_preview);
|
||||
}
|
||||
|
||||
void
|
||||
save_settings(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
inbe_storage_set_setting_int("speed", app->inbe.speed_level);
|
||||
inbe_storage_set_setting_int("max_rounds", app->inbe.max_rounds);
|
||||
inbe_storage_set_setting_int("max_breaths", int_from_count(app->inbe.maxbreaths));
|
||||
inbe_storage_set_setting_int("pause_seconds", app->inbe.pause_seconds);
|
||||
inbe_storage_set_setting_int("sound_volume", app->sound_volume);
|
||||
inbe_storage_set_setting_int("tutorial_seen", app->tutorial_seen ? 1 : 0);
|
||||
inbe_storage_set_setting_int("exercise_manual_seen_mask", app->exercise_manual_seen_mask);
|
||||
inbe_storage_set_setting_int("theme", app->theme_id);
|
||||
inbe_storage_set_setting_int("dark_mode", app->dark_mode);
|
||||
inbe_storage_set_setting_int("theme_mode", app->theme_mode);
|
||||
inbe_storage_set_setting_int("orientation_mode", app->orientation_mode);
|
||||
inbe_storage_set_setting_int("main_tab", app->main_tab);
|
||||
inbe_storage_set_setting_int("fullscreen", app->fullscreen_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("on_screen_keyboard", app->on_screen_keyboard_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("progressive_speed", app->inbe.progressive_speed);
|
||||
inbe_storage_set_setting_int("progressive_start_speed", app->inbe.progressive_start_speed);
|
||||
inbe_storage_set_setting_int("breath_animation", app->inbe.breath_animation);
|
||||
inbe_storage_set_setting_int("advanced_session_controls", app->advanced_session_controls ? 1 : 0);
|
||||
inbe_storage_set_setting_int("hold_display_mode", app->hold_display_mode);
|
||||
inbe_storage_set_setting_int("exercise_type", app->exercise_type);
|
||||
inbe_storage_set_setting_int("meditation_music_enabled", app->meditation_music_enabled ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_shuffle", app->meditation_music_shuffle ? 1 : 0);
|
||||
inbe_storage_set_setting_int("meditation_music_track", app->meditation_music_track);
|
||||
inbe_storage_set_setting_int("play_in_background", app->inbe.play_in_background);
|
||||
inbe_storage_set_setting_text("language",
|
||||
(app->language_selected && app->language[0] != '\0') ? app->language : "");
|
||||
inbe_storage_set_setting_int("practice_category_tab", app->practice_category_tab);
|
||||
inbe_storage_settings_end_write();
|
||||
#if defined(PLATFORM_WEB)
|
||||
sync_web_storage();
|
||||
#endif
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_settings(InbeApp *app)
|
||||
{
|
||||
int settings_missing = inbe_storage_settings_empty();
|
||||
int speed = inbe_storage_get_setting_int("speed", DefaultSpeedLevel);
|
||||
int max_rounds = inbe_storage_get_setting_int("max_rounds", DefaultMaxRounds);
|
||||
int max_breaths = inbe_storage_get_setting_int("max_breaths", DefaultMaxBreaths);
|
||||
int pause_seconds = inbe_storage_get_setting_int("pause_seconds", DefaultPauseSeconds);
|
||||
int sound_volume = inbe_storage_get_setting_int("sound_volume", 100);
|
||||
int manual_seen_mask;
|
||||
|
||||
app->tutorial_seen = inbe_storage_get_setting_int("tutorial_seen", 0) != 0;
|
||||
manual_seen_mask = inbe_storage_get_setting_int("exercise_manual_seen_mask", -1);
|
||||
if(manual_seen_mask < 0)
|
||||
manual_seen_mask = app->tutorial_seen ? exercise_manual_seen_bit(EXERCISE_WIM_HOF) : 0;
|
||||
app->exercise_manual_seen_mask = manual_seen_mask & ((1 << EXERCISE_COUNT) - 1);
|
||||
app->theme_id = clampi(inbe_storage_get_setting_int("theme", 0), 0, FLINT_THEME_COUNT - 1);
|
||||
app->theme_mode = clampi(inbe_storage_get_setting_int("theme_mode", APP_THEME_SYSTEM),
|
||||
APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
app->dark_mode = inbe_storage_get_setting_int("dark_mode", 0) != 0;
|
||||
app->orientation_mode = clampi(inbe_storage_get_setting_int("orientation_mode", APP_ORIENTATION_SYSTEM),
|
||||
APP_ORIENTATION_SYSTEM, APP_ORIENTATION_SENSOR);
|
||||
app->main_tab = clampi(inbe_storage_get_setting_int("main_tab", APP_MAIN_TAB_PRACTICE),
|
||||
APP_MAIN_TAB_HABITS, APP_MAIN_TAB_PRACTICE);
|
||||
app->fullscreen_enabled = inbe_storage_get_setting_int("fullscreen", 0) != 0;
|
||||
#ifdef __ANDROID__
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 1) != 0;
|
||||
#else
|
||||
app->on_screen_keyboard_enabled = inbe_storage_get_setting_int("on_screen_keyboard", 0) != 0;
|
||||
#endif
|
||||
app->sound_volume = clampi(sound_volume, SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX);
|
||||
app->inbe.progressive_speed = inbe_storage_get_setting_int("progressive_speed", 1) != 0;
|
||||
app->inbe.progressive_start_speed = clampi(inbe_storage_get_setting_int("progressive_start_speed", DefaultProgressiveStartSpeed),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
app->inbe.breath_animation = clampi(inbe_storage_get_setting_int("breath_animation", InbeBreathAnimationLinear),
|
||||
InbeBreathAnimationLinear, InbeBreathAnimationCount - 1);
|
||||
app->advanced_session_controls = inbe_storage_get_setting_int("advanced_session_controls", 0) != 0;
|
||||
app->hold_display_mode = clampi(inbe_storage_get_setting_int("hold_display_mode", HOLD_DISPLAY_CIRCLE),
|
||||
HOLD_DISPLAY_CIRCLE, HOLD_DISPLAY_STOPWATCH);
|
||||
app->exercise_type = clampi(inbe_storage_get_setting_int("exercise_type", EXERCISE_WIM_HOF),
|
||||
EXERCISE_WIM_HOF, EXERCISE_COUNT - 1);
|
||||
app->meditation_music_enabled = inbe_storage_get_setting_int("meditation_music_enabled", 1) != 0;
|
||||
app->meditation_music_shuffle = inbe_storage_get_setting_int("meditation_music_shuffle", 0) != 0;
|
||||
app->meditation_music_track = clampi(inbe_storage_get_setting_int("meditation_music_track", 0),
|
||||
0, MEDITATION_MUSIC_TRACK_COUNT - 1);
|
||||
app->practice_category_tab =
|
||||
clampi(inbe_storage_get_setting_int("practice_category_tab", PRACTICE_CATEGORY_MIND),
|
||||
0, PRACTICE_CATEGORY_COUNT - 1);
|
||||
app->language_needs_save = 0;
|
||||
{
|
||||
const char *language = inbe_storage_get_setting_text("language");
|
||||
if(language != NULL && language[0] != '\0') {
|
||||
snprintf(app->language, sizeof(app->language), "%s", language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
app->language_selected = settings_missing ? 0 : 1;
|
||||
app->language_needs_save = app->language_selected;
|
||||
locale_set(app->language);
|
||||
}
|
||||
app->language_index = locale_current_index();
|
||||
if(app->language_index < 0)
|
||||
app->language_index = 0;
|
||||
}
|
||||
#if defined(LOTUS_BUILD)
|
||||
sync_lotus_settings(app);
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID__
|
||||
app->inbe.play_in_background = inbe_storage_get_setting_int("play_in_background",
|
||||
1 // Default to enabled on Android
|
||||
);
|
||||
TraceLog(LOG_INFO, "INBE: Loaded play_in_background setting = %d", app->inbe.play_in_background);
|
||||
#else
|
||||
app->inbe.play_in_background = 0;
|
||||
#endif
|
||||
app->backgrounded = 0;
|
||||
|
||||
app_device_preferences_init(app);
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
refresh_locale_dependent_text(app);
|
||||
if(settings_missing)
|
||||
save_settings(app);
|
||||
}
|
||||
|
||||
void
|
||||
app_reload_after_import(InbeApp *app, int reload_settings)
|
||||
{
|
||||
@@ -680,9 +477,10 @@ app_reload_after_import(InbeApp *app, int reload_settings)
|
||||
return;
|
||||
|
||||
if(reload_settings) {
|
||||
load_settings(app);
|
||||
if(app_load_settings(app))
|
||||
save_settings(app);
|
||||
reset_settings_preview(app);
|
||||
update_session_sounds(app);
|
||||
practice_update_session_sounds(app);
|
||||
}
|
||||
|
||||
inbe_habits_init(&app->habits);
|
||||
@@ -728,8 +526,8 @@ load_pixel_texture_from_asset(const char *path)
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
load_asset_texture(const char *name)
|
||||
Texture2D
|
||||
app_load_asset_texture(const char *name)
|
||||
{
|
||||
char path[64];
|
||||
|
||||
@@ -747,15 +545,23 @@ load_sound_asset(const char *name)
|
||||
|
||||
snprintf(path, sizeof(path), "assets/sounds/%s", name);
|
||||
asset = flint_embedded_asset(path);
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0)
|
||||
if(asset == NULL || asset->data == NULL || asset->size == 0) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Missing embedded sound asset: %s", path);
|
||||
return sound;
|
||||
}
|
||||
|
||||
wave = LoadWaveFromMemory(flint_embedded_asset_extension(path), asset->data, (int)asset->size);
|
||||
if(wave.data == NULL)
|
||||
if(wave.data == NULL) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Failed to decode embedded sound asset: %s", path);
|
||||
return sound;
|
||||
}
|
||||
|
||||
sound = LoadSoundFromWave(wave);
|
||||
UnloadWave(wave);
|
||||
if(sound.frameCount == 0)
|
||||
TraceLog(LOG_ERROR, "AUDIO: Failed to create sound from embedded asset: %s", path);
|
||||
else
|
||||
TraceLog(LOG_INFO, "AUDIO: Loaded sound asset %s (%u frames)", path, sound.frameCount);
|
||||
return sound;
|
||||
}
|
||||
|
||||
@@ -764,7 +570,17 @@ app_play_sound(InbeApp *app, Sound sound, float scale)
|
||||
{
|
||||
float volume;
|
||||
|
||||
if(app == NULL || !app->audio_ready || sound.frameCount == 0 || app->sound_volume <= 0)
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot play sound because audio device is not ready");
|
||||
return;
|
||||
}
|
||||
if(sound.frameCount == 0) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot play sound because sound is not loaded");
|
||||
return;
|
||||
}
|
||||
if(app->sound_volume <= 0)
|
||||
return;
|
||||
|
||||
volume = ((float)app->sound_volume / 100.0f) * scale;
|
||||
@@ -776,6 +592,8 @@ app_play_sound(InbeApp *app, Sound sound, float scale)
|
||||
StopSound(sound);
|
||||
SetSoundVolume(sound, volume);
|
||||
PlaySound(sound);
|
||||
if(!IsSoundPlaying(sound))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlaySound returned but sound is not playing");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -786,8 +604,11 @@ init_audio(InbeApp *app)
|
||||
|
||||
InitAudioDevice();
|
||||
app->audio_ready = IsAudioDeviceReady();
|
||||
if(!app->audio_ready)
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Audio device failed to initialize");
|
||||
return;
|
||||
}
|
||||
TraceLog(LOG_INFO, "AUDIO: Audio device initialized");
|
||||
|
||||
app->breath_in_sound = load_sound_asset("breath-in.ogg");
|
||||
app->breath_out_sound = load_sound_asset("breath-out.ogg");
|
||||
@@ -833,16 +654,15 @@ inbe_app_init(void *vapp) {
|
||||
#endif
|
||||
|
||||
inbeinit(&app->inbe);
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + flint_px(80));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + flint_px(80));
|
||||
data_init();
|
||||
load_settings(app);
|
||||
if(app_load_settings(app))
|
||||
save_settings(app);
|
||||
if(app->language_needs_save) {
|
||||
save_settings(app);
|
||||
app->language_needs_save = 0;
|
||||
}
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + 80);
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + 80);
|
||||
inbe_habits_init(&app->habits);
|
||||
app->habit_detail_index = -1;
|
||||
app->habit_detail_day = 0;
|
||||
@@ -857,7 +677,11 @@ inbe_app_init(void *vapp) {
|
||||
app->pending_bottom_tab = APP_BOTTOM_TAB_NONE;
|
||||
app_open_main_tab(app, app->main_tab, 0);
|
||||
init_audio(app);
|
||||
meditation_music_init(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->init != NULL)
|
||||
practice->init(app);
|
||||
}
|
||||
app->camera = (Camera2D){0};
|
||||
app->cursor_clickable = 0;
|
||||
app->cursor_disabled = 0;
|
||||
@@ -871,6 +695,10 @@ inbe_app_init(void *vapp) {
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
app->settings_tab = SETTINGS_TAB_DEVICE;
|
||||
app->settings_data_view = 0;
|
||||
app->sync_server_url_cursor = 0;
|
||||
app->sync_server_url_focused = 0;
|
||||
app->sync_server_url[0] = '\0';
|
||||
app->practice_config_tab = 0;
|
||||
app->practice_coming_soon_ticks = 0;
|
||||
app->habit_edit_active = 0;
|
||||
@@ -891,7 +719,7 @@ inbe_app_init(void *vapp) {
|
||||
app->backgrounded = 0;
|
||||
app->results_saved = 0;
|
||||
app->results_path[0] = '\0';
|
||||
update_session_sounds(app);
|
||||
practice_update_session_sounds(app);
|
||||
reset_settings_preview(app);
|
||||
inbeinit(&app->start_speed_preview);
|
||||
app->start_speed_preview_speed = 0;
|
||||
@@ -915,354 +743,19 @@ inbe_app_init(void *vapp) {
|
||||
|
||||
ui_set_icons(app->icons[UI_ICON_TYPE_GEAR], app->icons[UI_ICON_TYPE_X]);
|
||||
|
||||
if(app->whm_1_image.id == 0) {
|
||||
app->whm_1_image = load_asset_texture("whm/1.jpg");
|
||||
}
|
||||
if(app->whm_2_image.id == 0) {
|
||||
app->whm_2_image = load_asset_texture("whm/2.jpg");
|
||||
}
|
||||
#if !defined(LOTUS_BUILD)
|
||||
if(!app->language_selected)
|
||||
app->inbe.screen = InbeScreenLanguage;
|
||||
else
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
#else
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
#endif
|
||||
|
||||
/* Reset modal state */
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->modal.selected_button = 0;
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
}
|
||||
|
||||
static Texture2D
|
||||
sound_icon_for_volume(InbeApp *app)
|
||||
{
|
||||
int vol = app->sound_volume;
|
||||
if(vol <= 0)
|
||||
return app->icons[UI_ICON_TYPE_SOUND0];
|
||||
if(vol <= 25)
|
||||
return app->icons[UI_ICON_TYPE_SOUND1];
|
||||
if(vol <= 75)
|
||||
return app->icons[UI_ICON_TYPE_SOUND2];
|
||||
return app->icons[UI_ICON_TYPE_SOUND3];
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_start(InbeApp *app, int seconds)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->meditation_duration_seconds = seconds;
|
||||
app->meditation_remaining_seconds = seconds;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenMeditation;
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
meditation_music_start_session(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_finish(InbeApp *app)
|
||||
{
|
||||
int duration;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
duration = app->meditation_duration_seconds;
|
||||
if(duration >= 60) {
|
||||
int session_duration = duration;
|
||||
if(data_save_session_path_for_activity(&session_duration, 1, 0, EXERCISE_MEDITATION,
|
||||
NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
}
|
||||
}
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
meditation_music_stop(app);
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_elapsed_seconds(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = app->meditation_duration_seconds - app->meditation_remaining_seconds;
|
||||
if(elapsed < 0)
|
||||
elapsed = 0;
|
||||
if(elapsed > app->meditation_duration_seconds)
|
||||
elapsed = app->meditation_duration_seconds;
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_save_elapsed(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = meditation_elapsed_seconds(app);
|
||||
if(elapsed < 60)
|
||||
return 0;
|
||||
if(data_save_session_path_for_activity(&elapsed, 1, 0, EXERCISE_MEDITATION, NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_exit_to_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
meditation_music_stop(app);
|
||||
app->meditation_duration_seconds = 0;
|
||||
app->meditation_remaining_seconds = 0;
|
||||
app->meditation_frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_request_exit(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmExitSession;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
format_meditation_time(char *dst, size_t dst_size, int seconds)
|
||||
{
|
||||
int hours;
|
||||
int minutes;
|
||||
int secs;
|
||||
|
||||
if(dst == NULL || dst_size == 0)
|
||||
return;
|
||||
if(seconds < 0)
|
||||
seconds = 0;
|
||||
|
||||
hours = seconds / 3600;
|
||||
minutes = (seconds / 60) % 60;
|
||||
secs = seconds % 60;
|
||||
|
||||
if(hours > 0)
|
||||
snprintf(dst, dst_size, "%d:%02d:%02d", hours, minutes, secs);
|
||||
else
|
||||
snprintf(dst, dst_size, "%d:%02d", minutes, secs);
|
||||
}
|
||||
|
||||
static int
|
||||
draw_meditation_duration_button(int x, int y, int w, int h, const char *label)
|
||||
{
|
||||
int hover = 0;
|
||||
return ui_draw_generic_button(x, y, w, h, label, UI_BUTTON_STYLE_PRIMARY, 0, &hover);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_setup_modal(InbeApp *app)
|
||||
{
|
||||
static const int durations[] = {5 * 60, 15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60};
|
||||
const char *labels[] = {
|
||||
locale_get("duration_5m"),
|
||||
locale_get("duration_15m"),
|
||||
locale_get("duration_30m"),
|
||||
locale_get("duration_1h"),
|
||||
locale_get("duration_2h")
|
||||
};
|
||||
int modal_w = flint_px(320);
|
||||
int modal_h = flint_px(236);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_px(18);
|
||||
int title_w;
|
||||
int btn_h = flint_px(38);
|
||||
int gap = flint_px(10);
|
||||
int side = flint_px(18);
|
||||
int row_y;
|
||||
int btn_w;
|
||||
int cancel_w = flint_px(120);
|
||||
int cancel_x;
|
||||
int cancel_y;
|
||||
int cancel_hover = 0;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
btn_w = (modal_w - side * 2 - gap * 2) / 3;
|
||||
if(btn_w < flint_px(64))
|
||||
btn_w = flint_px(64);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title_w = flint_text_measure(locale_get("meditation_title"), title_font);
|
||||
flint_text_draw(locale_get("meditation_title"), modal_x + (modal_w - title_w) / 2,
|
||||
modal_y + flint_px(16), title_font, theme_get_text());
|
||||
|
||||
row_y = modal_y + flint_px(62);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int x = modal_x + side + i * (btn_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, btn_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
row_y += btn_h + gap;
|
||||
for(int i = 3; i < 5; i++) {
|
||||
int two_w = (modal_w - side * 2 - gap) / 2;
|
||||
int x = modal_x + side + (i - 3) * (two_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, two_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
cancel_y = modal_y + modal_h - btn_h - flint_px(16);
|
||||
cancel_x = modal_x + (modal_w - cancel_w) / 2;
|
||||
if(ui_draw_generic_button(cancel_x, cancel_y, cancel_w, btn_h,
|
||||
locale_get("cancel_button"), UI_BUTTON_STYLE_SECONDARY,
|
||||
0, &cancel_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_sound_controls(InbeApp *app)
|
||||
{
|
||||
int sound_btn_x = view_width - flint_px(56);
|
||||
int sound_btn_y = flint_px(12);
|
||||
int sound_btn_size = flint_px(24);
|
||||
int sound_btn_padding = flint_px(10);
|
||||
int sound_hover = 0;
|
||||
|
||||
if(ui_draw_icon_btn_padded(sound_btn_x, sound_btn_y, sound_btn_size, sound_btn_padding,
|
||||
sound_icon_for_volume(app), &sound_hover)) {
|
||||
app->volume_popup_active = !app->volume_popup_active;
|
||||
}
|
||||
|
||||
if(app->volume_popup_active) {
|
||||
int popup_w = flint_px(44);
|
||||
int popup_x = sound_btn_x;
|
||||
int popup_y = sound_btn_y + sound_btn_size + sound_btn_padding * 2;
|
||||
int popup_h = flint_px(200);
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
|
||||
(mouse.x < popup_x || mouse.x > popup_x + popup_w ||
|
||||
mouse.y < popup_y || mouse.y > popup_y + popup_h)) {
|
||||
app->volume_popup_active = 0;
|
||||
}
|
||||
|
||||
DrawRectangle(popup_x, popup_y, popup_w, popup_h, theme_get_surface());
|
||||
ui_draw_bevel(popup_x, popup_y, popup_w, popup_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
if(ui_draw_slider_vertical(501, popup_x + popup_w / 2, popup_y + flint_px(10),
|
||||
popup_h - flint_px(20), SETTINGS_VOLUME_MIN,
|
||||
SETTINGS_VOLUME_MAX, &app->sound_volume)) {
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_screen(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
char time_text[32];
|
||||
int return_hover = 0;
|
||||
int font = flint_px(48);
|
||||
int max_w;
|
||||
int text_w;
|
||||
|
||||
if(ui_draw_icon_btn_padded(flint_px(12), flint_px(12), flint_px(24),
|
||||
flint_px(10), app->icons[UI_ICON_TYPE_RETURN], &return_hover)) {
|
||||
meditation_request_exit(app);
|
||||
return;
|
||||
}
|
||||
|
||||
draw_meditation_sound_controls(app);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmExitSession) {
|
||||
int elapsed = meditation_elapsed_seconds(app);
|
||||
int modal_result;
|
||||
|
||||
if(elapsed >= 60) {
|
||||
modal_result = ui_draw_modal_3btn(locale_get("exit_session_title"),
|
||||
locale_get("meditation_save_elapsed_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("save_button"),
|
||||
locale_get("discard_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_save_elapsed(app);
|
||||
meditation_exit_to_start(app);
|
||||
} else if(modal_result == 3) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
} else {
|
||||
modal_result = ui_draw_modal(locale_get("exit_session_title"),
|
||||
locale_get("meditation_under_minute_exit_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("exit_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
format_meditation_time(time_text, sizeof(time_text), app->meditation_remaining_seconds);
|
||||
max_w = view_width - flint_px(48);
|
||||
while(font > flint_px(28) && flint_text_measure(time_text, font) > max_w)
|
||||
font--;
|
||||
text_w = flint_text_measure(time_text, font);
|
||||
flint_text_draw(time_text, center_x - text_w / 2,
|
||||
flint_ui_text_y(time_text, center_y - font, font * 2, font),
|
||||
font, theme_get_text());
|
||||
|
||||
app->meditation_frame_ticks++;
|
||||
if(app->meditation_frame_ticks >= 60) {
|
||||
app->meditation_frame_ticks = 0;
|
||||
if(app->meditation_remaining_seconds > 0)
|
||||
app->meditation_remaining_seconds--;
|
||||
if(app->meditation_remaining_seconds <= 0)
|
||||
meditation_finish(app);
|
||||
}
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1311,7 +804,7 @@ handle_back_button(InbeApp *app)
|
||||
break;
|
||||
|
||||
case InbeScreenResults:
|
||||
session_ensure_results_saved(app);
|
||||
practice_ensure_results_saved(app);
|
||||
inbe_app_init(app);
|
||||
break;
|
||||
|
||||
@@ -1334,7 +827,11 @@ handle_back_button(InbeApp *app)
|
||||
break;
|
||||
|
||||
case InbeScreenMeditation:
|
||||
meditation_request_exit(app);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->request_exit != NULL)
|
||||
practice->request_exit(app);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenStart:
|
||||
@@ -1371,14 +868,15 @@ updateapp(InbeApp *app)
|
||||
int hover = 0;
|
||||
|
||||
app_apply_pending_bottom_tab(app);
|
||||
meditation_music_update(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->update != NULL)
|
||||
practice->update(app);
|
||||
}
|
||||
if(app->practice_coming_soon_ticks > 0)
|
||||
app->practice_coming_soon_ticks--;
|
||||
|
||||
if(IsKeyPressed(KEY_BACK) ||
|
||||
(IsKeyPressed(KEY_BACKSPACE) &&
|
||||
!(app->inbe.screen == InbeScreenHabitEdit && app->habit_edit_active) &&
|
||||
!(app->inbe.screen == InbeScreenHabitSessionEdit && app->habit_session_edit_active))) {
|
||||
if(IsKeyPressed(KEY_BACK)) {
|
||||
if(app->modal.active) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
@@ -1395,7 +893,9 @@ updateapp(InbeApp *app)
|
||||
}
|
||||
|
||||
if(app->inbe.screen == InbeScreenPracticeConfig) {
|
||||
practice_config_screen_draw(app);
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->draw_config != NULL)
|
||||
practice->draw_config(app);
|
||||
goto finish_frame;
|
||||
}
|
||||
|
||||
@@ -1428,17 +928,16 @@ updateapp(InbeApp *app)
|
||||
}
|
||||
|
||||
if(app->inbe.screen == InbeScreenStart) {
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(58) + flint_px(64));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(58) + flint_px(64));
|
||||
} else if(app->inbe.screen == InbeScreenSession) {
|
||||
session_update_circle_bounds_for_view(&app->inbe, 0, 84);
|
||||
practice_update_circle_bounds(app, 0, 84);
|
||||
}
|
||||
|
||||
int play_circle_clicked = 0;
|
||||
if(app->inbe.screen == InbeScreenStart)
|
||||
play_circle_clicked = session_draw_start_preview(app, center_x, center_y);
|
||||
play_circle_clicked = practice_draw_start_preview(app, center_x, center_y);
|
||||
else if(app->inbe.screen == InbeScreenSession)
|
||||
session_draw_inbe(app, center_x, center_y);
|
||||
practice_draw_active_breathing(app, center_x, center_y);
|
||||
|
||||
|
||||
switch (app->inbe.screen) {
|
||||
@@ -1510,12 +1009,10 @@ updateapp(InbeApp *app)
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenManual;
|
||||
} else if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
session_start(app);
|
||||
const PracticeDefinition *practice = practice_get(app->exercise_type);
|
||||
if(practice->start != NULL)
|
||||
practice->start(app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1527,20 +1024,27 @@ updateapp(InbeApp *app)
|
||||
save_settings(app);
|
||||
}
|
||||
app_draw_bottom_nav(app);
|
||||
if(app->modal.active && app->modal.type == UIModalMeditationSetup)
|
||||
draw_meditation_setup_modal(app);
|
||||
if(app->modal.active && app->modal.type == UIModalMeditationSetup) {
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->draw_setup_modal != NULL)
|
||||
practice->draw_setup_modal(app);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenSession:
|
||||
session_update_screen(app, center_x, center_y, &hover);
|
||||
practice_update_active_breathing(app, center_x, center_y, &hover);
|
||||
break;
|
||||
|
||||
case InbeScreenMeditation:
|
||||
draw_meditation_screen(app, center_x, center_y);
|
||||
{
|
||||
const PracticeDefinition *practice = practice_get(PRACTICE_MEDITATION);
|
||||
if(practice->draw_active_session != NULL)
|
||||
practice->draw_active_session(app, center_x, center_y);
|
||||
}
|
||||
break;
|
||||
|
||||
case InbeScreenResults:
|
||||
session_draw_results_screen(app, center_x, center_y, &hover);
|
||||
practice_draw_results(app, center_x, center_y, &hover);
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -1565,11 +1069,7 @@ inbe_app_update_draw(void *vapp, Rectangle viewport) {
|
||||
flint_set_view_size(view_width, view_height);
|
||||
|
||||
ui_init(view_width, view_height, flint_dpi_scale());
|
||||
#if defined(LOTUS_BUILD)
|
||||
sync_lotus_settings(app);
|
||||
#endif
|
||||
session_update_circle_bounds_for_view(&app->inbe, flint_px(48),
|
||||
flint_px(56) + flint_px(80));
|
||||
practice_update_circle_bounds(app, flint_px(48), flint_px(56) + flint_px(80));
|
||||
|
||||
app->cursor_clickable = 0;
|
||||
app->cursor_disabled = 0;
|
||||
@@ -1591,7 +1091,8 @@ inbe_app_update_draw(void *vapp, Rectangle viewport) {
|
||||
flint_clip_end();
|
||||
}
|
||||
|
||||
static void SafeUnloadTexture(Texture2D texture) {
|
||||
void
|
||||
app_unload_texture(Texture2D texture) {
|
||||
if (texture.id != 0) {
|
||||
UnloadTexture(texture);
|
||||
}
|
||||
@@ -1614,15 +1115,17 @@ inbe_app_destroy(void *vapp)
|
||||
|
||||
// Unload all icons
|
||||
flint_unload_all_icons(app->icons);
|
||||
SafeUnloadTexture(app->whm_1_image);
|
||||
SafeUnloadTexture(app->whm_2_image);
|
||||
SafeUnloadTexture(app->font_shapes_texture);
|
||||
app_unload_texture(app->font_shapes_texture);
|
||||
unload_locale_font(app);
|
||||
|
||||
SafeUnloadSound(app->breath_in_sound);
|
||||
SafeUnloadSound(app->breath_out_sound);
|
||||
SafeUnloadSound(app->bell_sound);
|
||||
meditation_music_unload(app);
|
||||
for(int i = 0; i < practice_count(); i++) {
|
||||
const PracticeDefinition *practice = practice_get(i);
|
||||
if(practice->destroy != NULL)
|
||||
practice->destroy(app);
|
||||
}
|
||||
|
||||
if (app->audio_ready) {
|
||||
CloseAudioDevice();
|
||||
|
||||
@@ -61,6 +61,7 @@ typedef enum {
|
||||
UIModalEditProgressiveStartSpeed,
|
||||
UIModalMeditationNetworkError,
|
||||
UIModalConfirmImportDataSettings,
|
||||
UIModalSyncAccountBackup,
|
||||
} UIModalType;
|
||||
|
||||
typedef struct {
|
||||
@@ -79,15 +80,6 @@ typedef struct InbeConfig {
|
||||
|
||||
extern InbeConfig config;
|
||||
|
||||
typedef struct LotusAppApi {
|
||||
const char *id;
|
||||
void *(*create)(void);
|
||||
void (*init)(void *state);
|
||||
void (*init_args)(void *state, int argc, char **argv);
|
||||
void (*update_draw)(void *state, Rectangle viewport);
|
||||
void (*destroy)(void *state);
|
||||
} LotusAppApi;
|
||||
|
||||
typedef enum HoldDisplayMode {
|
||||
HOLD_DISPLAY_CIRCLE = 0,
|
||||
HOLD_DISPLAY_STOPWATCH = 1,
|
||||
@@ -96,7 +88,7 @@ typedef enum HoldDisplayMode {
|
||||
typedef enum ExerciseType {
|
||||
EXERCISE_WIM_HOF = 0,
|
||||
EXERCISE_MEDITATION = 1,
|
||||
EXERCISE_COUNT
|
||||
EXERCISE_COUNT = 2
|
||||
} ExerciseType;
|
||||
|
||||
typedef enum AppThemeMode {
|
||||
@@ -123,6 +115,30 @@ typedef enum AppMainTab {
|
||||
APP_MAIN_TAB_PRACTICE = 1,
|
||||
} AppMainTab;
|
||||
|
||||
typedef struct WhmPracticeState {
|
||||
Texture2D image_1;
|
||||
Texture2D image_2;
|
||||
} WhmPracticeState;
|
||||
|
||||
typedef struct MeditationPracticeState {
|
||||
Texture2D image_1;
|
||||
int duration_seconds;
|
||||
int remaining_seconds;
|
||||
int frame_ticks;
|
||||
int music_enabled;
|
||||
int music_shuffle;
|
||||
int music_track;
|
||||
int music_loaded;
|
||||
int music_playing;
|
||||
int music_test_playing;
|
||||
int music_archive_extracted;
|
||||
int music_network_error_notified;
|
||||
Music music;
|
||||
FlintRuntimeAssetDownload music_download;
|
||||
char music_cache_dir[FS_PATH_MAX];
|
||||
char music_status[128];
|
||||
} MeditationPracticeState;
|
||||
|
||||
struct InbeApp {
|
||||
Inbe inbe;
|
||||
Inbe settings_preview;
|
||||
@@ -133,8 +149,8 @@ struct InbeApp {
|
||||
int cursor_disabled;
|
||||
Texture2D icons[UI_ICON_TYPE_COUNT];
|
||||
|
||||
Texture2D whm_1_image;
|
||||
Texture2D whm_2_image;
|
||||
WhmPracticeState whm;
|
||||
MeditationPracticeState meditation;
|
||||
Texture2D font_shapes_texture;
|
||||
Font locale_font;
|
||||
Font locale_font_8;
|
||||
@@ -155,6 +171,10 @@ struct InbeApp {
|
||||
int settings_dirty;
|
||||
int settings_save_delay_ticks;
|
||||
int settings_tab;
|
||||
int settings_data_view;
|
||||
int sync_server_url_cursor;
|
||||
int sync_server_url_focused;
|
||||
char sync_server_url[256];
|
||||
int device_picker_open;
|
||||
int device_picker_scroll;
|
||||
int fullscreen_enabled;
|
||||
@@ -178,9 +198,6 @@ struct InbeApp {
|
||||
int android_orientation;
|
||||
int main_tab;
|
||||
int pending_bottom_tab;
|
||||
#if defined(LOTUS_BUILD)
|
||||
unsigned int lotus_settings_version;
|
||||
#endif
|
||||
InbeHabits habits;
|
||||
int habit_detail_index;
|
||||
int habit_detail_day;
|
||||
@@ -201,6 +218,13 @@ struct InbeApp {
|
||||
Color habit_edit_color;
|
||||
int habit_edit_sync_mode;
|
||||
int habit_edit_sync_activity;
|
||||
int habit_edit_counter_enabled;
|
||||
int habit_counter_press_day;
|
||||
int habit_counter_press_index;
|
||||
int habit_counter_press_frames;
|
||||
int habit_counter_press_long_done;
|
||||
int habit_counter_press_start_x;
|
||||
int habit_counter_press_start_y;
|
||||
int advanced_session_controls;
|
||||
int hold_display_mode;
|
||||
int exercise_type;
|
||||
@@ -214,21 +238,6 @@ struct InbeApp {
|
||||
char results_path[FS_PATH_MAX];
|
||||
int saved_pause_seconds;
|
||||
int volume_popup_active;
|
||||
int meditation_duration_seconds;
|
||||
int meditation_remaining_seconds;
|
||||
int meditation_frame_ticks;
|
||||
int meditation_music_enabled;
|
||||
int meditation_music_shuffle;
|
||||
int meditation_music_track;
|
||||
int meditation_music_loaded;
|
||||
int meditation_music_playing;
|
||||
int meditation_music_test_playing;
|
||||
int meditation_music_archive_extracted;
|
||||
int meditation_music_network_error_notified;
|
||||
Music meditation_music;
|
||||
FlintRuntimeAssetDownload meditation_music_download;
|
||||
char meditation_music_cache_dir[FS_PATH_MAX];
|
||||
char meditation_music_status[128];
|
||||
UIModal modal;
|
||||
int play_circle_hover;
|
||||
float play_circle_scale;
|
||||
@@ -237,17 +246,16 @@ struct InbeApp {
|
||||
void inbe_app_init(void *app);
|
||||
void inbe_app_update_draw(void *app, Rectangle viewport);
|
||||
void inbe_app_destroy(void *app);
|
||||
void update_session_sounds(InbeApp *app);
|
||||
int inbe_app_auto_sync(InbeApp *app);
|
||||
void app_play_sound(InbeApp *app, Sound sound, float scale);
|
||||
Texture2D app_load_asset_texture(const char *name);
|
||||
void app_unload_texture(Texture2D texture);
|
||||
|
||||
int clampi(int x, int min, int max);
|
||||
int int_from_count(const char src[4]);
|
||||
void count_from_int(char dst[4], int value);
|
||||
void save_settings(InbeApp *app);
|
||||
void app_reload_after_import(InbeApp *app, int reload_settings);
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
void update_preview_bounds(Inbe *inbe, int content_w, int max_h);
|
||||
void apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds);
|
||||
void refresh_theme_colors(int theme_id, int dark_mode);
|
||||
void refresh_locale_dependent_text(InbeApp *app);
|
||||
void apply_language_selection(InbeApp *app, int language_index, int save_now);
|
||||
@@ -255,7 +263,7 @@ int exercise_manual_seen(InbeApp *app, int exercise_type);
|
||||
void mark_exercise_manual_seen(InbeApp *app, int exercise_type);
|
||||
void sync_habits_for_activity(InbeApp *app, int exercise_type);
|
||||
void draw_preview_inbe(Inbe *inbe, int center_x, int center_y);
|
||||
int draw_hold_display_mode_selector(InbeApp *app, int x, int y, int w);
|
||||
void settings_draw_progressive_start_speed_editor(InbeApp *app);
|
||||
|
||||
#include "app_settings.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
#include "app_settings.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "device_preferences.h"
|
||||
#include "locale.h"
|
||||
#include "practices/meditation/meditation_music.h"
|
||||
#include "practices/whm/whm_session.h"
|
||||
#include "storage.h"
|
||||
#include "theme.h"
|
||||
#include "flint_dpi.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
typedef struct IntSetting {
|
||||
const char *key;
|
||||
int value;
|
||||
} IntSetting;
|
||||
|
||||
typedef struct LoadedIntSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
} LoadedIntSetting;
|
||||
|
||||
typedef struct LoadedBoolSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
} LoadedBoolSetting;
|
||||
|
||||
typedef struct LoadedClampedSetting {
|
||||
int *dst;
|
||||
const char *key;
|
||||
int fallback;
|
||||
int min_value;
|
||||
int max_value;
|
||||
} LoadedClampedSetting;
|
||||
|
||||
static int
|
||||
exercise_manual_bit(int exercise_type)
|
||||
{
|
||||
if(exercise_type < 0 || exercise_type >= EXERCISE_COUNT)
|
||||
return 0;
|
||||
return 1 << exercise_type;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
static void
|
||||
sync_web_storage(void)
|
||||
{
|
||||
EM_ASM({
|
||||
if(typeof FS !== 'undefined' && typeof FS.syncfs === 'function') {
|
||||
if(Module.inbeSyncfsTimer)
|
||||
clearTimeout(Module.inbeSyncfsTimer);
|
||||
Module.__inbeStorageSyncPending = true;
|
||||
Module.inbeSyncfsTimer = setTimeout(function() {
|
||||
Module.inbeSyncfsTimer = 0;
|
||||
Module.__inbeStorageSyncing = true;
|
||||
try {
|
||||
FS.syncfs(false, function(err) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
if(err) console.error("IDBFS save failed:", err);
|
||||
else console.log("IDBFS synced");
|
||||
});
|
||||
} catch(e) {
|
||||
Module.__inbeStorageSyncing = false;
|
||||
Module.__inbeStorageSyncPending = false;
|
||||
console.error("IDBFS sync error:", e);
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
save_int_settings(const IntSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
inbe_storage_set_setting_int(settings[i].key, settings[i].value);
|
||||
}
|
||||
|
||||
static void
|
||||
load_int_settings(const LoadedIntSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
*settings[i].dst = inbe_storage_get_setting_int(settings[i].key,
|
||||
settings[i].fallback);
|
||||
}
|
||||
|
||||
static void
|
||||
load_bool_settings(const LoadedBoolSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++)
|
||||
*settings[i].dst = inbe_storage_get_setting_int(settings[i].key,
|
||||
settings[i].fallback) != 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_clamped_settings(const LoadedClampedSetting *settings, size_t count)
|
||||
{
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
int value = inbe_storage_get_setting_int(settings[i].key, settings[i].fallback);
|
||||
*settings[i].dst = clampi(value, settings[i].min_value, settings[i].max_value);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds)
|
||||
{
|
||||
speed = clampi(speed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX);
|
||||
inbe->speed_level = speed;
|
||||
inbe->breath_half_ticks = inbe_breath_half_ticks_for_speed(speed);
|
||||
inbe->breath_animation = clampi(inbe->breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
inbe->progressive_start_speed = clampi(inbe->progressive_start_speed,
|
||||
SETTINGS_SPEED_MIN, speed);
|
||||
inbe->max_rounds = clampi(max_rounds, 1, MaxRounds);
|
||||
inbe->pause_seconds = clampi(pause_seconds, SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX);
|
||||
count_from_int(inbe->maxbreaths,
|
||||
clampi(max_breaths, SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX));
|
||||
}
|
||||
|
||||
void
|
||||
reset_settings_preview(InbeApp *app)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
int breath_animation = app->inbe.breath_animation;
|
||||
int content_w;
|
||||
|
||||
inbeinit(&app->settings_preview);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_preview.play_in_background = play_in_background;
|
||||
app->settings_preview.breath_animation = breath_animation;
|
||||
flint_centered_column(CONTENT_MAX_W, CONTENT_SIDE_PAD, NULL, &content_w);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
session_reset_round_breathe(&app->settings_preview);
|
||||
}
|
||||
|
||||
void
|
||||
save_settings(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
const IntSetting int_settings[] = {
|
||||
{"speed", app->inbe.speed_level},
|
||||
{"max_rounds", app->inbe.max_rounds},
|
||||
{"max_breaths", int_from_count(app->inbe.maxbreaths)},
|
||||
{"pause_seconds", app->inbe.pause_seconds},
|
||||
{"sound_volume", app->sound_volume},
|
||||
{"tutorial_seen", app->tutorial_seen ? 1 : 0},
|
||||
{"exercise_manual_seen_mask", app->exercise_manual_seen_mask},
|
||||
{"theme", app->theme_id},
|
||||
{"dark_mode", app->dark_mode},
|
||||
{"theme_mode", app->theme_mode},
|
||||
{"orientation_mode", app->orientation_mode},
|
||||
{"main_tab", app->main_tab},
|
||||
{"fullscreen", app->fullscreen_enabled ? 1 : 0},
|
||||
{"on_screen_keyboard", app->on_screen_keyboard_enabled ? 1 : 0},
|
||||
{"progressive_speed", app->inbe.progressive_speed},
|
||||
{"progressive_start_speed", app->inbe.progressive_start_speed},
|
||||
{"breath_animation", app->inbe.breath_animation},
|
||||
{"advanced_session_controls", app->advanced_session_controls ? 1 : 0},
|
||||
{"hold_display_mode", app->hold_display_mode},
|
||||
{"exercise_type", app->exercise_type},
|
||||
{"meditation_music_enabled", app->meditation.music_enabled ? 1 : 0},
|
||||
{"meditation_music_shuffle", app->meditation.music_shuffle ? 1 : 0},
|
||||
{"meditation_music_track", app->meditation.music_track},
|
||||
{"play_in_background", app->inbe.play_in_background},
|
||||
{"practice_category_tab", app->practice_category_tab},
|
||||
};
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
save_int_settings(int_settings, sizeof(int_settings) / sizeof(int_settings[0]));
|
||||
inbe_storage_set_setting_text("language",
|
||||
(app->language_selected && app->language[0] != '\0') ?
|
||||
app->language : "");
|
||||
inbe_storage_settings_end_write();
|
||||
#if defined(PLATFORM_WEB)
|
||||
sync_web_storage();
|
||||
#endif
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
load_language_setting(InbeApp *app, int settings_missing)
|
||||
{
|
||||
const char *language = inbe_storage_get_setting_text("language");
|
||||
|
||||
app->language_needs_save = 0;
|
||||
if(language != NULL && language[0] != '\0') {
|
||||
snprintf(app->language, sizeof(app->language), "%s", language);
|
||||
app->language_selected = 1;
|
||||
if(!locale_set(app->language)) {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
locale_set(app->language);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->language, sizeof(app->language), "%s", "en");
|
||||
app->language_selected = settings_missing ? 0 : 1;
|
||||
app->language_needs_save = app->language_selected;
|
||||
locale_set(app->language);
|
||||
}
|
||||
|
||||
app->language_index = locale_current_index();
|
||||
if(app->language_index < 0)
|
||||
app->language_index = 0;
|
||||
}
|
||||
|
||||
int
|
||||
app_load_settings(InbeApp *app)
|
||||
{
|
||||
int settings_missing;
|
||||
int speed;
|
||||
int max_rounds;
|
||||
int max_breaths;
|
||||
int pause_seconds;
|
||||
int manual_seen_mask;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
|
||||
settings_missing = inbe_storage_settings_empty();
|
||||
|
||||
{
|
||||
LoadedIntSetting settings[] = {
|
||||
{&speed, "speed", DefaultSpeedLevel},
|
||||
{&max_rounds, "max_rounds", DefaultMaxRounds},
|
||||
{&max_breaths, "max_breaths", DefaultMaxBreaths},
|
||||
{&pause_seconds, "pause_seconds", DefaultPauseSeconds},
|
||||
};
|
||||
load_int_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
{
|
||||
LoadedBoolSetting settings[] = {
|
||||
{&app->tutorial_seen, "tutorial_seen", 0},
|
||||
{&app->dark_mode, "dark_mode", 0},
|
||||
{&app->fullscreen_enabled, "fullscreen", 0},
|
||||
#ifdef __ANDROID__
|
||||
{&app->on_screen_keyboard_enabled, "on_screen_keyboard", 1},
|
||||
#else
|
||||
{&app->on_screen_keyboard_enabled, "on_screen_keyboard", 0},
|
||||
#endif
|
||||
{&app->inbe.progressive_speed, "progressive_speed", 1},
|
||||
{&app->advanced_session_controls, "advanced_session_controls", 0},
|
||||
{&app->meditation.music_enabled, "meditation_music_enabled", 1},
|
||||
{&app->meditation.music_shuffle, "meditation_music_shuffle", 0},
|
||||
};
|
||||
load_bool_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
{
|
||||
LoadedClampedSetting settings[] = {
|
||||
{&app->sound_volume, "sound_volume", 100,
|
||||
SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX},
|
||||
{&app->theme_id, "theme", 0, 0, FLINT_THEME_COUNT - 1},
|
||||
{&app->theme_mode, "theme_mode", APP_THEME_SYSTEM,
|
||||
APP_THEME_SYSTEM, APP_THEME_DARK},
|
||||
{&app->orientation_mode, "orientation_mode", APP_ORIENTATION_SYSTEM,
|
||||
APP_ORIENTATION_SYSTEM, APP_ORIENTATION_SENSOR},
|
||||
{&app->main_tab, "main_tab", APP_MAIN_TAB_PRACTICE,
|
||||
APP_MAIN_TAB_HABITS, APP_MAIN_TAB_PRACTICE},
|
||||
{&app->inbe.progressive_start_speed, "progressive_start_speed",
|
||||
DefaultProgressiveStartSpeed, SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX},
|
||||
{&app->inbe.breath_animation, "breath_animation", InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationLinear, InbeBreathAnimationCount - 1},
|
||||
{&app->hold_display_mode, "hold_display_mode", HOLD_DISPLAY_CIRCLE,
|
||||
HOLD_DISPLAY_CIRCLE, HOLD_DISPLAY_STOPWATCH},
|
||||
{&app->exercise_type, "exercise_type", EXERCISE_WIM_HOF,
|
||||
EXERCISE_WIM_HOF, EXERCISE_COUNT - 1},
|
||||
{&app->meditation.music_track, "meditation_music_track", 0,
|
||||
0, MEDITATION_MUSIC_TRACK_COUNT - 1},
|
||||
{&app->practice_category_tab, "practice_category_tab", PRACTICE_CATEGORY_MIND,
|
||||
0, PRACTICE_CATEGORY_COUNT - 1},
|
||||
};
|
||||
load_clamped_settings(settings, sizeof(settings) / sizeof(settings[0]));
|
||||
}
|
||||
|
||||
manual_seen_mask = inbe_storage_get_setting_int("exercise_manual_seen_mask", -1);
|
||||
if(manual_seen_mask < 0)
|
||||
manual_seen_mask = app->tutorial_seen ? exercise_manual_bit(EXERCISE_WIM_HOF) : 0;
|
||||
app->exercise_manual_seen_mask = manual_seen_mask & ((1 << EXERCISE_COUNT) - 1);
|
||||
|
||||
load_language_setting(app, settings_missing);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
app->inbe.play_in_background =
|
||||
inbe_storage_get_setting_int("play_in_background", 1) != 0;
|
||||
TraceLog(LOG_INFO, "INBE: Loaded play_in_background setting = %d",
|
||||
app->inbe.play_in_background);
|
||||
#else
|
||||
app->inbe.play_in_background = 0;
|
||||
#endif
|
||||
app->backgrounded = 0;
|
||||
|
||||
app_device_preferences_init(app);
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
refresh_locale_dependent_text(app);
|
||||
|
||||
return settings_missing;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef INBE_APP_SETTINGS_H
|
||||
#define INBE_APP_SETTINGS_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
#include "breath_engine.h"
|
||||
|
||||
void save_settings(InbeApp *app);
|
||||
int app_load_settings(InbeApp *app);
|
||||
void reset_settings_preview(InbeApp *app);
|
||||
void apply_settings(Inbe *inbe, int speed, int max_rounds, int max_breaths, int pause_seconds);
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "device_preferences.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#if defined(LOTUS_BUILD)
|
||||
#include "lotus_settings.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_device.h"
|
||||
#endif
|
||||
@@ -17,18 +14,9 @@ void
|
||||
refresh_theme_colors(int theme_id, int dark_mode)
|
||||
{
|
||||
theme_set_current(theme_id, dark_mode);
|
||||
#if defined(LOTUS_BUILD)
|
||||
(void)theme_id;
|
||||
(void)dark_mode;
|
||||
ui_set_colors(theme_get_text(), theme_get_bg(), theme_get_surface(),
|
||||
theme_get_circle(), theme_get_button(), theme_get_button_hover(),
|
||||
theme_get_icon());
|
||||
return;
|
||||
#else
|
||||
ui_set_colors(theme_get_text(), theme_get_bg(), theme_get_surface(),
|
||||
theme_get_circle(), theme_get_button(), theme_get_button_hover(),
|
||||
theme_get_icon());
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define INBE_VERSION_H
|
||||
|
||||
#define INBE_VERSION_MAJOR 1
|
||||
#define INBE_VERSION_MINOR 3
|
||||
#define INBE_VERSION_PATCH 3
|
||||
#define INBE_VERSION_STRING "1.3.3"
|
||||
#define INBE_VERSION_MINOR 4
|
||||
#define INBE_VERSION_PATCH 0
|
||||
#define INBE_VERSION_STRING "1.4.0"
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,93 @@
|
||||
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
|
||||
static jclass
|
||||
android_share_helper_class(JNIEnv *env, jobject activity)
|
||||
{
|
||||
jclass activity_class;
|
||||
jmethodID get_class_loader;
|
||||
jobject class_loader;
|
||||
jclass class_loader_class;
|
||||
jmethodID load_class;
|
||||
jstring class_name;
|
||||
jclass share_helper_class;
|
||||
|
||||
activity_class = (*env)->FindClass(env, "android/app/Activity");
|
||||
if(!activity_class)
|
||||
return NULL;
|
||||
get_class_loader = (*env)->GetMethodID(env, activity_class, "getClassLoader",
|
||||
"()Ljava/lang/ClassLoader;");
|
||||
if(!get_class_loader)
|
||||
return NULL;
|
||||
class_loader = (*env)->CallObjectMethod(env, activity, get_class_loader);
|
||||
if(!class_loader)
|
||||
return NULL;
|
||||
class_loader_class = (*env)->FindClass(env, "java/lang/ClassLoader");
|
||||
if(!class_loader_class)
|
||||
return NULL;
|
||||
load_class = (*env)->GetMethodID(env, class_loader_class, "loadClass",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
if(!load_class)
|
||||
return NULL;
|
||||
class_name = (*env)->NewStringUTF(env, "xyz.waozi.inbe.ShareHelper");
|
||||
share_helper_class = (jclass)(*env)->CallObjectMethod(env, class_loader, load_class, class_name);
|
||||
(*env)->DeleteLocalRef(env, class_name);
|
||||
(*env)->DeleteLocalRef(env, class_loader);
|
||||
return share_helper_class;
|
||||
}
|
||||
|
||||
int
|
||||
android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type)
|
||||
{
|
||||
struct android_app *app = GetAndroidApp();
|
||||
ANativeActivity *native_activity;
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jclass share_helper_class;
|
||||
jmethodID method;
|
||||
jbyteArray jarr;
|
||||
jstring jname;
|
||||
jstring jmime;
|
||||
jstring jtitle;
|
||||
|
||||
if(app == NULL || app->activity == NULL || data == NULL || data_size == 0 ||
|
||||
filename == NULL || filename[0] == '\0')
|
||||
return 0;
|
||||
|
||||
native_activity = app->activity;
|
||||
jvm = native_activity->vm;
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK)
|
||||
return 0;
|
||||
|
||||
share_helper_class = android_share_helper_class(env, native_activity->clazz);
|
||||
if(!share_helper_class) {
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 0;
|
||||
}
|
||||
method = (*env)->GetStaticMethodID(env, share_helper_class, "shareFile",
|
||||
"(Landroid/app/Activity;[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
if(!method) {
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
jarr = (*env)->NewByteArray(env, data_size);
|
||||
(*env)->SetByteArrayRegion(env, jarr, 0, data_size, (const jbyte *)data);
|
||||
jname = (*env)->NewStringUTF(env, filename);
|
||||
jmime = (*env)->NewStringUTF(env, mime_type != NULL ? mime_type : "application/octet-stream");
|
||||
jtitle = (*env)->NewStringUTF(env, locale_get("share_sheet_title"));
|
||||
(*env)->CallStaticVoidMethod(env, share_helper_class, method, native_activity->clazz,
|
||||
jarr, jname, jmime, jtitle);
|
||||
|
||||
(*env)->DeleteLocalRef(env, jarr);
|
||||
(*env)->DeleteLocalRef(env, jname);
|
||||
(*env)->DeleteLocalRef(env, jmime);
|
||||
(*env)->DeleteLocalRef(env, jtitle);
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int android_share_export(const char *filename)
|
||||
{
|
||||
struct android_app *app;
|
||||
@@ -163,4 +250,12 @@ int android_share_export(const char *filename) {
|
||||
(void)filename;
|
||||
return 0;
|
||||
}
|
||||
int android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type) {
|
||||
(void)data;
|
||||
(void)data_size;
|
||||
(void)filename;
|
||||
(void)mime_type;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,8 +1,12 @@
|
||||
#ifndef ANDROID_SHARE_H
|
||||
#define ANDROID_SHARE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* Export data using Android share sheet
|
||||
* Returns: 1 on success (share sheet shown), 0 on failure */
|
||||
int android_share_export(const char *filename);
|
||||
int android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "android_timer.h"
|
||||
#include "app.h"
|
||||
#include "practices/practice_registry.h"
|
||||
#include <time.h>
|
||||
|
||||
#include <raylib.h>
|
||||
@@ -41,15 +42,15 @@ timer_thread_func(void *arg) {
|
||||
if (should_run) {
|
||||
// Log every 60 frames (1 second)
|
||||
if (frame_count % 60 == 0) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Running meditation step + sounds");
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Running background practice step + sounds");
|
||||
}
|
||||
frame_count++;
|
||||
|
||||
// Update meditation state and sounds with mutex protection
|
||||
// Update practice state and sounds with mutex protection
|
||||
pthread_mutex_lock(&inbe_state_mutex);
|
||||
InbeApp *app = (InbeApp*)g_app;
|
||||
inbestep(&app->inbe);
|
||||
update_session_sounds(app);
|
||||
practice_update_session_sounds(app);
|
||||
pthread_mutex_unlock(&inbe_state_mutex);
|
||||
|
||||
// Sleep for exact frame time (60fps = ~16.666ms)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "meditation_music.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static int
|
||||
meditation_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
return meditation_music_measure_settings(app, content_w, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_config_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int scroll_y;
|
||||
int scroll_h;
|
||||
int content_h;
|
||||
int controls_w;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIHeader header;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
header = ui_draw_title_header(title_h, locale_get("exercise_meditation"),
|
||||
(Texture2D){0}, app->icons[UI_ICON_TYPE_X]);
|
||||
if(header.right_clicked) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
meditation_practice_leave_config(app);
|
||||
app->settings_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
scroll_y = title_h + flint_px(16);
|
||||
scroll_h = view_height - scroll_y;
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
controls_w = content_w;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
FlintUIScrollView measured;
|
||||
content_h = meditation_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == controls_w)
|
||||
break;
|
||||
controls_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_h = meditation_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
{
|
||||
int y = scroll_view.content_y;
|
||||
meditation_music_draw_settings(app, scroll_view.content_x, scroll_view.content_w,
|
||||
&y, 1, 1);
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
MEDITATION_MANUAL_PAGES = 2
|
||||
};
|
||||
|
||||
static void
|
||||
meditation_manual_start(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
meditation_practice_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_manual_close(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_intro_page(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
int img_h = flint_px(190);
|
||||
FlintUIParagraph paragraph;
|
||||
|
||||
ui_draw_tutorial_image(app->meditation.image_1, "practices/meditation/1.jpg",
|
||||
content_x, *y, content_w, img_h);
|
||||
*y += img_h + flint_px(22);
|
||||
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_intro_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
flint_ui_paragraph_draw(paragraph, content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
intro_page_height(int content_w)
|
||||
{
|
||||
FlintUIParagraph paragraph = {
|
||||
.text = locale_get("meditation_manual_intro_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
|
||||
return flint_px(190) + flint_px(22) + flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_page_height(InbeApp *app, int content_w)
|
||||
{
|
||||
FlintUIParagraph paragraph = {
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
|
||||
return meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) + flint_ui_paragraph_height(paragraph) + flint_px(20);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int button_h = flint_px(36);
|
||||
int footer_y = view_height - flint_px(42);
|
||||
int content_y = title_h + flint_px(16);
|
||||
int content_h = footer_y - content_y - flint_px(28);
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.90f);
|
||||
int max_content_w = flint_px(520);
|
||||
int page = clampi(app->tutorial_step, 0, MEDITATION_MANUAL_PAGES - 1);
|
||||
int content_total_h;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < flint_px(280))
|
||||
responsive_max_w = flint_px(280);
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
app->tutorial_step = page;
|
||||
if(ui_draw_screen_header(locale_get("meditation_manual_title"), 1))
|
||||
meditation_manual_close(app, 0);
|
||||
|
||||
if(content_h < flint_px(120))
|
||||
content_h = flint_px(120);
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
content_total_h = page == 0 ? intro_page_height(content_w)
|
||||
: settings_page_height(app, content_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y, (float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_total_h = page == 0 ? intro_page_height(content_w)
|
||||
: settings_page_height(app, content_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y, (float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
{
|
||||
int y = scroll_view.content_y;
|
||||
if(page == 0) {
|
||||
draw_intro_page(app, scroll_view.content_x, scroll_view.content_w, &y);
|
||||
} else {
|
||||
FlintUIParagraph paragraph;
|
||||
meditation_music_draw_settings(app, scroll_view.content_x, scroll_view.content_w,
|
||||
&y, 0, 1);
|
||||
y += flint_px(34);
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = scroll_view.content_w,
|
||||
.font = flint_ui_font(),
|
||||
.line_gap = flint_px(8),
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
flint_ui_paragraph_draw(paragraph, scroll_view.content_x, &y);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
if(page == 1)
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
|
||||
{
|
||||
int gap = flint_px(10);
|
||||
int button_w = (content_w - gap) / 2;
|
||||
int hover = 0;
|
||||
const char *left = page == 0 ? locale_get("tutorial_skip_button")
|
||||
: locale_get("tutorial_back_button");
|
||||
const char *right = page == 0 ? locale_get("tutorial_next_button")
|
||||
: locale_get("tutorial_start_button");
|
||||
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left, UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(page == 0)
|
||||
meditation_manual_start(app);
|
||||
else {
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
if(ui_draw_generic_button(content_x + button_w + gap, footer_y, button_w,
|
||||
button_h, right, UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(page == 0) {
|
||||
app->tutorial_step = 1;
|
||||
app->manual_scroll = 0;
|
||||
} else {
|
||||
meditation_manual_start(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
@@ -143,11 +143,31 @@ set_status(InbeApp *app, const char *message)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
copy_text_checked(app->meditation_music_status,
|
||||
sizeof(app->meditation_music_status),
|
||||
copy_text_checked(app->meditation.music_status,
|
||||
sizeof(app->meditation.music_status),
|
||||
message);
|
||||
}
|
||||
|
||||
static int
|
||||
download_supported(void)
|
||||
{
|
||||
#if defined(PLATFORM_WEB)
|
||||
return 0;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *
|
||||
missing_audio_message(void)
|
||||
{
|
||||
#if defined(PLATFORM_WEB)
|
||||
return "Audio is unavailable";
|
||||
#else
|
||||
return "Download audio before playing music";
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
is_network_download_error(const FlintRuntimeAssetDownload *download)
|
||||
{
|
||||
@@ -207,7 +227,7 @@ draw_download_progress(InbeApp *app, int x, int y, int w)
|
||||
if(app == NULL || w <= 0)
|
||||
return;
|
||||
|
||||
download = &app->meditation_music_download;
|
||||
download = &app->meditation.music_download;
|
||||
if(download->status != FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
return;
|
||||
|
||||
@@ -264,7 +284,7 @@ draw_music_attribution(int content_x, int content_w, int *y)
|
||||
static void
|
||||
music_archive_path(InbeApp *app, char *out, size_t out_size)
|
||||
{
|
||||
if(!join_path2(out, out_size, app->meditation_music_cache_dir,
|
||||
if(!join_path2(out, out_size, app->meditation.music_cache_dir,
|
||||
"/inbe-meditation-audio-v1.zip"))
|
||||
set_status(app, "Audio cache path is too long");
|
||||
}
|
||||
@@ -281,7 +301,7 @@ music_track_path(InbeApp *app, int track, char *out, size_t out_size)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if(join_path2(out, out_size, app->meditation_music_cache_dir, "/audio/") &&
|
||||
if(join_path2(out, out_size, app->meditation.music_cache_dir, "/audio/") &&
|
||||
append_text_checked(out, out_size, g_tracks[track].file) &&
|
||||
file_exists(out))
|
||||
return;
|
||||
@@ -302,10 +322,10 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
flint_runtime_asset_ensure_dir(app->meditation_music_cache_dir);
|
||||
flint_runtime_asset_ensure_dir(app->meditation.music_cache_dir);
|
||||
{
|
||||
char audio_dir[FS_PATH_MAX];
|
||||
if(join_path2(audio_dir, sizeof(audio_dir), app->meditation_music_cache_dir, "/audio"))
|
||||
if(join_path2(audio_dir, sizeof(audio_dir), app->meditation.music_cache_dir, "/audio"))
|
||||
flint_runtime_asset_ensure_dir(audio_dir);
|
||||
else
|
||||
set_status(app, "Audio cache path is too long");
|
||||
@@ -325,7 +345,7 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
if(!known_track_archive_member(stat.m_filename))
|
||||
continue;
|
||||
|
||||
if(!join_path2(out_path, sizeof(out_path), app->meditation_music_cache_dir, "/audio/") ||
|
||||
if(!join_path2(out_path, sizeof(out_path), app->meditation.music_cache_dir, "/audio/") ||
|
||||
!append_text_checked(out_path, sizeof(out_path), stat.m_filename)) {
|
||||
set_status(app, "Audio file path is too long");
|
||||
continue;
|
||||
@@ -346,7 +366,7 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
|
||||
}
|
||||
|
||||
mz_zip_reader_end(&archive);
|
||||
snprintf(app->meditation_music_status, sizeof(app->meditation_music_status),
|
||||
snprintf(app->meditation.music_status, sizeof(app->meditation.music_status),
|
||||
"Installed %d audio files", extracted);
|
||||
return extracted > 0;
|
||||
}
|
||||
@@ -374,7 +394,7 @@ meditation_music_selected_label(InbeApp *app)
|
||||
int track;
|
||||
if(app == NULL)
|
||||
return "";
|
||||
track = app->meditation_music_track;
|
||||
track = app->meditation.music_track;
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
return g_tracks[track].title;
|
||||
@@ -387,18 +407,18 @@ meditation_music_init(InbeApp *app)
|
||||
return;
|
||||
|
||||
flint_runtime_assets_init("inbe");
|
||||
if(!flint_runtime_asset_cache_root("inbe", app->meditation_music_cache_dir,
|
||||
sizeof(app->meditation_music_cache_dir))) {
|
||||
snprintf(app->meditation_music_cache_dir, sizeof(app->meditation_music_cache_dir),
|
||||
if(!flint_runtime_asset_cache_root("inbe", app->meditation.music_cache_dir,
|
||||
sizeof(app->meditation.music_cache_dir))) {
|
||||
snprintf(app->meditation.music_cache_dir, sizeof(app->meditation.music_cache_dir),
|
||||
"runtime-assets");
|
||||
flint_runtime_asset_ensure_dir(app->meditation_music_cache_dir);
|
||||
flint_runtime_asset_ensure_dir(app->meditation.music_cache_dir);
|
||||
}
|
||||
|
||||
if(app->meditation_music_track < 0 ||
|
||||
app->meditation_music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation_music_track = 0;
|
||||
if(app->meditation.music_track < 0 ||
|
||||
app->meditation.music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation.music_track = 0;
|
||||
|
||||
if(app->meditation_music_status[0] == '\0') {
|
||||
if(app->meditation.music_status[0] == '\0') {
|
||||
set_status(app, meditation_music_available(app) ? "Audio installed" : "Audio not installed");
|
||||
}
|
||||
}
|
||||
@@ -408,13 +428,13 @@ meditation_music_unload(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_loaded) {
|
||||
StopMusicStream(app->meditation_music);
|
||||
UnloadMusicStream(app->meditation_music);
|
||||
app->meditation_music_loaded = 0;
|
||||
if(app->meditation.music_loaded) {
|
||||
StopMusicStream(app->meditation.music);
|
||||
UnloadMusicStream(app->meditation.music);
|
||||
app->meditation.music_loaded = 0;
|
||||
}
|
||||
app->meditation_music_playing = 0;
|
||||
app->meditation_music_test_playing = 0;
|
||||
app->meditation.music_playing = 0;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -422,10 +442,10 @@ meditation_music_stop(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_loaded)
|
||||
StopMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 0;
|
||||
app->meditation_music_test_playing = 0;
|
||||
if(app->meditation.music_loaded)
|
||||
StopMusicStream(app->meditation.music);
|
||||
app->meditation.music_playing = 0;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -435,25 +455,27 @@ meditation_music_test_track(InbeApp *app)
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_playing) {
|
||||
if(app->meditation.music_playing) {
|
||||
meditation_music_unload(app);
|
||||
set_status(app, "Test audio stopped");
|
||||
return;
|
||||
}
|
||||
if(!meditation_music_available(app)) {
|
||||
set_status(app, "Download audio before testing");
|
||||
set_status(app, missing_audio_message());
|
||||
return;
|
||||
}
|
||||
|
||||
track = app->meditation_music_track;
|
||||
track = app->meditation.music_track;
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
if(!load_track(app, track))
|
||||
return;
|
||||
|
||||
PlayMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 1;
|
||||
app->meditation_music_test_playing = 1;
|
||||
PlayMusicStream(app->meditation.music);
|
||||
if(!IsMusicStreamPlaying(app->meditation.music))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlayMusicStream returned but test music is not playing");
|
||||
app->meditation.music_playing = 1;
|
||||
app->meditation.music_test_playing = 1;
|
||||
set_status(app, "Playing test audio");
|
||||
}
|
||||
|
||||
@@ -462,8 +484,13 @@ load_track(InbeApp *app, int track)
|
||||
{
|
||||
char path[FS_PATH_MAX];
|
||||
|
||||
if(app == NULL || !app->audio_ready)
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(!app->audio_ready) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Cannot load meditation music because audio device is not ready");
|
||||
set_status(app, "Audio device is not ready");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(track < 0 || track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
track = 0;
|
||||
@@ -475,16 +502,18 @@ load_track(InbeApp *app, int track)
|
||||
return 0;
|
||||
}
|
||||
|
||||
app->meditation_music = LoadMusicStream(path);
|
||||
if(app->meditation_music.ctxData == NULL) {
|
||||
app->meditation.music = LoadMusicStream(path);
|
||||
if(app->meditation.music.ctxData == NULL) {
|
||||
TraceLog(LOG_ERROR, "AUDIO: Could not load meditation track: %s", path);
|
||||
set_status(app, "Could not load track");
|
||||
app->meditation_music_loaded = 0;
|
||||
app->meditation.music_loaded = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
app->meditation_music_loaded = 1;
|
||||
app->meditation_music_track = track;
|
||||
SetMusicVolume(app->meditation_music, (float)app->sound_volume / 100.0f);
|
||||
app->meditation.music_loaded = 1;
|
||||
app->meditation.music_track = track;
|
||||
SetMusicVolume(app->meditation.music, (float)app->sound_volume / 100.0f);
|
||||
TraceLog(LOG_INFO, "AUDIO: Loaded meditation track: %s", path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -493,21 +522,23 @@ meditation_music_start_session(InbeApp *app)
|
||||
{
|
||||
int track;
|
||||
|
||||
if(app == NULL || !app->meditation_music_enabled)
|
||||
if(app == NULL || !app->meditation.music_enabled)
|
||||
return;
|
||||
if(!meditation_music_available(app)) {
|
||||
set_status(app, "Download audio before playing music");
|
||||
set_status(app, missing_audio_message());
|
||||
return;
|
||||
}
|
||||
|
||||
track = app->meditation_music_track;
|
||||
if(app->meditation_music_shuffle)
|
||||
track = app->meditation.music_track;
|
||||
if(app->meditation.music_shuffle)
|
||||
track = GetRandomValue(0, MEDITATION_MUSIC_TRACK_COUNT - 1);
|
||||
if(!load_track(app, track))
|
||||
return;
|
||||
PlayMusicStream(app->meditation_music);
|
||||
app->meditation_music_playing = 1;
|
||||
app->meditation_music_test_playing = 0;
|
||||
PlayMusicStream(app->meditation.music);
|
||||
if(!IsMusicStreamPlaying(app->meditation.music))
|
||||
TraceLog(LOG_ERROR, "AUDIO: PlayMusicStream returned but session music is not playing");
|
||||
app->meditation.music_playing = 1;
|
||||
app->meditation.music_test_playing = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -517,7 +548,7 @@ meditation_music_update(InbeApp *app)
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->meditation_music_test_playing &&
|
||||
if(app->meditation.music_test_playing &&
|
||||
(app->exercise_type != EXERCISE_MEDITATION ||
|
||||
(app->inbe.screen != InbeScreenPracticeConfig &&
|
||||
app->inbe.screen != InbeScreenManual))) {
|
||||
@@ -525,29 +556,29 @@ meditation_music_update(InbeApp *app)
|
||||
return;
|
||||
}
|
||||
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_READY &&
|
||||
!app->meditation_music_archive_extracted) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_READY &&
|
||||
!app->meditation.music_archive_extracted) {
|
||||
music_archive_path(app, archive_path, sizeof(archive_path));
|
||||
app->meditation_music_archive_extracted = 1;
|
||||
app->meditation.music_archive_extracted = 1;
|
||||
extract_audio_archive(app, archive_path);
|
||||
} else if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_ERROR ||
|
||||
app->meditation_music_download.status == FLINT_RUNTIME_ASSET_UNSUPPORTED) {
|
||||
if(is_network_download_error(&app->meditation_music_download)) {
|
||||
} else if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_ERROR ||
|
||||
app->meditation.music_download.status == FLINT_RUNTIME_ASSET_UNSUPPORTED) {
|
||||
if(is_network_download_error(&app->meditation.music_download)) {
|
||||
set_status(app, locale_get("meditation_music_network_error_title"));
|
||||
if(!app->meditation_music_network_error_notified && !app->modal.active) {
|
||||
if(!app->meditation.music_network_error_notified && !app->modal.active) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationNetworkError;
|
||||
app->modal.selected_button = 0;
|
||||
app->meditation_music_network_error_notified = 1;
|
||||
app->meditation.music_network_error_notified = 1;
|
||||
}
|
||||
} else if(app->meditation_music_download.error[0] != '\0') {
|
||||
set_status(app, app->meditation_music_download.error);
|
||||
} else if(app->meditation.music_download.error[0] != '\0') {
|
||||
set_status(app, app->meditation.music_download.error);
|
||||
}
|
||||
}
|
||||
|
||||
if(app->meditation_music_loaded) {
|
||||
SetMusicVolume(app->meditation_music, (float)app->sound_volume / 100.0f);
|
||||
UpdateMusicStream(app->meditation_music);
|
||||
if(app->meditation.music_loaded) {
|
||||
SetMusicVolume(app->meditation.music, (float)app->sound_volume / 100.0f);
|
||||
UpdateMusicStream(app->meditation.music);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,17 +591,17 @@ start_download(InbeApp *app)
|
||||
return;
|
||||
|
||||
music_archive_path(app, archive_path, sizeof(archive_path));
|
||||
app->meditation_music_archive_extracted = 0;
|
||||
app->meditation_music_network_error_notified = 0;
|
||||
app->meditation.music_archive_extracted = 0;
|
||||
app->meditation.music_network_error_notified = 0;
|
||||
set_status(app, "Downloading audio...");
|
||||
flint_runtime_asset_download(&app->meditation_music_download,
|
||||
flint_runtime_asset_download(&app->meditation.music_download,
|
||||
INBE_MEDITATION_AUDIO_URL,
|
||||
archive_path);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status)
|
||||
void
|
||||
meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status)
|
||||
{
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
@@ -584,29 +615,29 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
if(app == NULL || y == NULL)
|
||||
return;
|
||||
|
||||
if(app->meditation_music_track < 0 ||
|
||||
app->meditation_music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation_music_track = 0;
|
||||
if(app->meditation.music_track < 0 ||
|
||||
app->meditation.music_track >= MEDITATION_MUSIC_TRACK_COUNT)
|
||||
app->meditation.music_track = 0;
|
||||
|
||||
if(!app->meditation_music_enabled) {
|
||||
app->meditation_music_enabled = 1;
|
||||
if(!app->meditation.music_enabled) {
|
||||
app->meditation.music_enabled = 1;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("meditation_music_shuffle_label"), content_x, *y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&app->meditation_music_shuffle,
|
||||
&app->meditation.music_shuffle,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->settings_dirty = 1;
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
*y += flint_px(76);
|
||||
|
||||
if(!app->meditation_music_shuffle) {
|
||||
if(!app->meditation.music_shuffle) {
|
||||
flint_text_draw(locale_get("meditation_music_track_label"), content_x, *y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_dropdown_button(401, content_x, *y + flint_px(24), content_w, flint_px(36),
|
||||
g_track_options, MEDITATION_MUSIC_TRACK_COUNT,
|
||||
&app->meditation_music_track)) {
|
||||
&app->meditation.music_track)) {
|
||||
app->settings_dirty = 1;
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
@@ -615,7 +646,7 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
|
||||
installed = meditation_music_available(app);
|
||||
if(installed) {
|
||||
test_label = app->meditation_music_playing ?
|
||||
test_label = app->meditation.music_playing ?
|
||||
locale_get("meditation_music_stop_test_button") :
|
||||
locale_get("meditation_music_test_button");
|
||||
button_w = flint_text_measure(test_label, flint_ui_font()) + flint_px(24);
|
||||
@@ -628,7 +659,7 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
*y += button_h + flint_px(12);
|
||||
}
|
||||
|
||||
if(!installed || show_installed_download) {
|
||||
if(download_supported() && (!installed || show_installed_download)) {
|
||||
button_w = flint_text_measure(locale_get(installed ? "meditation_music_redownload_button"
|
||||
: "meditation_music_download_button"),
|
||||
flint_ui_font()) + flint_px(24);
|
||||
@@ -642,16 +673,16 @@ draw_music_picker(InbeApp *app, int content_x, int content_w, int *y,
|
||||
*y += button_h + flint_px(12);
|
||||
}
|
||||
|
||||
if(show_status && (!installed || app->meditation_music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING) {
|
||||
if(show_status && (!installed || app->meditation.music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING) {
|
||||
format_download_status(download_status, sizeof(download_status),
|
||||
&app->meditation_music_download);
|
||||
&app->meditation.music_download);
|
||||
flint_text_draw(download_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
*y += flint_px(28);
|
||||
draw_download_progress(app, content_x, *y, content_w);
|
||||
*y += flint_px(22);
|
||||
} else {
|
||||
flint_text_draw(app->meditation_music_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
flint_text_draw(app->meditation.music_status, content_x, *y, flint_ui_font(), theme_get_text());
|
||||
*y += flint_px(34);
|
||||
}
|
||||
}
|
||||
@@ -670,17 +701,17 @@ meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
|
||||
if(!app->meditation_music_shuffle)
|
||||
if(!app->meditation.music_shuffle)
|
||||
h += flint_px(74);
|
||||
|
||||
installed = meditation_music_available(app);
|
||||
if(installed)
|
||||
h += flint_px(48);
|
||||
if(!installed || show_installed_download)
|
||||
if(download_supported() && (!installed || show_installed_download))
|
||||
h += flint_px(48);
|
||||
|
||||
if(show_status && (!installed || app->meditation_music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation_music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
if(show_status && (!installed || app->meditation.music_download.status != FLINT_RUNTIME_ASSET_IDLE)) {
|
||||
if(app->meditation.music_download.status == FLINT_RUNTIME_ASSET_DOWNLOADING)
|
||||
h += flint_px(50);
|
||||
else
|
||||
h += flint_px(34);
|
||||
@@ -691,18 +722,6 @@ meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
return h;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
draw_music_picker(app, content_x, content_w, y, 1, 1);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_music_draw_guide_settings(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
draw_music_picker(app, content_x, content_w, y, 0, 1);
|
||||
}
|
||||
|
||||
int
|
||||
meditation_music_draw_dropdown_menu(InbeApp *app)
|
||||
{
|
||||
@@ -14,8 +14,8 @@ void meditation_music_start_session(InbeApp *app);
|
||||
void meditation_music_stop(InbeApp *app);
|
||||
int meditation_music_measure_settings(InbeApp *app, int content_w,
|
||||
int show_installed_download, int show_status);
|
||||
void meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y);
|
||||
void meditation_music_draw_guide_settings(InbeApp *app, int content_x, int content_w, int *y);
|
||||
void meditation_music_draw_settings(InbeApp *app, int content_x, int content_w, int *y,
|
||||
int show_installed_download, int show_status);
|
||||
int meditation_music_draw_dropdown_menu(InbeApp *app);
|
||||
int meditation_music_available(InbeApp *app);
|
||||
const char *meditation_music_selected_label(InbeApp *app);
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "meditation_music.h"
|
||||
|
||||
void
|
||||
meditation_practice_init(InbeApp *app)
|
||||
{
|
||||
if(app != NULL && app->meditation.image_1.id == 0)
|
||||
app->meditation.image_1 = app_load_asset_texture("practices/meditation/1.jpg");
|
||||
meditation_music_init(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_destroy(InbeApp *app)
|
||||
{
|
||||
if(app != NULL)
|
||||
app_unload_texture(app->meditation.image_1);
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
mark_exercise_manual_seen(app, EXERCISE_MEDITATION);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_update(InbeApp *app)
|
||||
{
|
||||
meditation_music_update(app);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_practice_leave_config(InbeApp *app)
|
||||
{
|
||||
meditation_music_unload(app);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef INBE_MEDITATION_PRACTICE_H
|
||||
#define INBE_MEDITATION_PRACTICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
void meditation_practice_init(InbeApp *app);
|
||||
void meditation_practice_destroy(InbeApp *app);
|
||||
void meditation_practice_start(InbeApp *app);
|
||||
void meditation_practice_update(InbeApp *app);
|
||||
void meditation_practice_leave_config(InbeApp *app);
|
||||
void meditation_manual_draw(InbeApp *app);
|
||||
void meditation_manual_close(InbeApp *app, int mark_seen);
|
||||
void meditation_config_screen_draw(InbeApp *app);
|
||||
void meditation_draw_setup_modal(InbeApp *app);
|
||||
void meditation_draw_screen(InbeApp *app, int center_x, int center_y);
|
||||
void meditation_request_exit(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,342 @@
|
||||
#include "meditation_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static Texture2D
|
||||
meditation_sound_icon_for_volume(InbeApp *app)
|
||||
{
|
||||
int vol = app->sound_volume;
|
||||
if(vol <= 0)
|
||||
return app->icons[UI_ICON_TYPE_SOUND0];
|
||||
if(vol <= 25)
|
||||
return app->icons[UI_ICON_TYPE_SOUND1];
|
||||
if(vol <= 75)
|
||||
return app->icons[UI_ICON_TYPE_SOUND2];
|
||||
return app->icons[UI_ICON_TYPE_SOUND3];
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_start(InbeApp *app, int seconds)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->meditation.duration_seconds = seconds;
|
||||
app->meditation.remaining_seconds = seconds;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenMeditation;
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
meditation_music_start_session(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_finish(InbeApp *app)
|
||||
{
|
||||
int duration;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
duration = app->meditation.duration_seconds;
|
||||
if(duration >= 60) {
|
||||
int session_duration = duration;
|
||||
if(data_save_session_path_for_activity(&session_duration, 1, 0, EXERCISE_MEDITATION,
|
||||
NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
meditation_music_stop(app);
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_elapsed_seconds(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = app->meditation.duration_seconds - app->meditation.remaining_seconds;
|
||||
if(elapsed < 0)
|
||||
elapsed = 0;
|
||||
if(elapsed > app->meditation.duration_seconds)
|
||||
elapsed = app->meditation.duration_seconds;
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
static int
|
||||
meditation_save_elapsed(InbeApp *app)
|
||||
{
|
||||
int elapsed;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
elapsed = meditation_elapsed_seconds(app);
|
||||
if(elapsed < 60)
|
||||
return 0;
|
||||
if(data_save_session_path_for_activity(&elapsed, 1, 0, EXERCISE_MEDITATION, NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
inbe_app_auto_sync(app);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_exit_to_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
meditation_music_stop(app);
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
app->session_paused = 0;
|
||||
app->volume_popup_active = 0;
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
void
|
||||
meditation_request_exit(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmExitSession;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
format_meditation_time(char *dst, size_t dst_size, int seconds)
|
||||
{
|
||||
int hours;
|
||||
int minutes;
|
||||
int secs;
|
||||
|
||||
if(dst == NULL || dst_size == 0)
|
||||
return;
|
||||
if(seconds < 0)
|
||||
seconds = 0;
|
||||
|
||||
hours = seconds / 3600;
|
||||
minutes = (seconds / 60) % 60;
|
||||
secs = seconds % 60;
|
||||
|
||||
if(hours > 0)
|
||||
snprintf(dst, dst_size, "%d:%02d:%02d", hours, minutes, secs);
|
||||
else
|
||||
snprintf(dst, dst_size, "%d:%02d", minutes, secs);
|
||||
}
|
||||
|
||||
static int
|
||||
draw_meditation_duration_button(int x, int y, int w, int h, const char *label)
|
||||
{
|
||||
int hover = 0;
|
||||
return ui_draw_generic_button(x, y, w, h, label, UI_BUTTON_STYLE_PRIMARY, 0, &hover);
|
||||
}
|
||||
|
||||
void
|
||||
meditation_draw_setup_modal(InbeApp *app)
|
||||
{
|
||||
static const int durations[] = {5 * 60, 15 * 60, 30 * 60, 60 * 60, 2 * 60 * 60};
|
||||
const char *labels[] = {
|
||||
locale_get("duration_5m"),
|
||||
locale_get("duration_15m"),
|
||||
locale_get("duration_30m"),
|
||||
locale_get("duration_1h"),
|
||||
locale_get("duration_2h")
|
||||
};
|
||||
int modal_w = flint_px(320);
|
||||
int modal_h = flint_px(236);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_px(18);
|
||||
int title_w;
|
||||
int btn_h = flint_px(38);
|
||||
int gap = flint_px(10);
|
||||
int side = flint_px(18);
|
||||
int row_y;
|
||||
int btn_w;
|
||||
int cancel_w = flint_px(120);
|
||||
int cancel_x;
|
||||
int cancel_y;
|
||||
int cancel_hover = 0;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
btn_w = (modal_w - side * 2 - gap * 2) / 3;
|
||||
if(btn_w < flint_px(64))
|
||||
btn_w = flint_px(64);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title_w = flint_text_measure(locale_get("meditation_title"), title_font);
|
||||
flint_text_draw(locale_get("meditation_title"), modal_x + (modal_w - title_w) / 2,
|
||||
modal_y + flint_px(16), title_font, theme_get_text());
|
||||
|
||||
row_y = modal_y + flint_px(62);
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int x = modal_x + side + i * (btn_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, btn_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
row_y += btn_h + gap;
|
||||
for(int i = 3; i < 5; i++) {
|
||||
int two_w = (modal_w - side * 2 - gap) / 2;
|
||||
int x = modal_x + side + (i - 3) * (two_w + gap);
|
||||
if(draw_meditation_duration_button(x, row_y, two_w, btn_h, labels[i]))
|
||||
meditation_start(app, durations[i]);
|
||||
}
|
||||
|
||||
cancel_y = modal_y + modal_h - btn_h - flint_px(16);
|
||||
cancel_x = modal_x + (modal_w - cancel_w) / 2;
|
||||
if(ui_draw_generic_button(cancel_x, cancel_y, cancel_w, btn_h,
|
||||
locale_get("cancel_button"), UI_BUTTON_STYLE_SECONDARY,
|
||||
0, &cancel_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
draw_meditation_sound_controls(InbeApp *app)
|
||||
{
|
||||
int sound_btn_x = view_width - flint_px(56);
|
||||
int sound_btn_y = flint_px(12);
|
||||
int sound_btn_size = flint_px(24);
|
||||
int sound_btn_padding = flint_px(10);
|
||||
int sound_hover = 0;
|
||||
|
||||
if(ui_draw_icon_btn_padded(sound_btn_x, sound_btn_y, sound_btn_size, sound_btn_padding,
|
||||
meditation_sound_icon_for_volume(app), &sound_hover)) {
|
||||
app->volume_popup_active = !app->volume_popup_active;
|
||||
}
|
||||
|
||||
if(app->volume_popup_active) {
|
||||
int popup_w = flint_px(44);
|
||||
int popup_x = sound_btn_x;
|
||||
int popup_y = sound_btn_y + sound_btn_size + sound_btn_padding * 2;
|
||||
int popup_h = flint_px(200);
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) &&
|
||||
(mouse.x < popup_x || mouse.x > popup_x + popup_w ||
|
||||
mouse.y < popup_y || mouse.y > popup_y + popup_h)) {
|
||||
app->volume_popup_active = 0;
|
||||
}
|
||||
|
||||
DrawRectangle(popup_x, popup_y, popup_w, popup_h, theme_get_surface());
|
||||
ui_draw_bevel(popup_x, popup_y, popup_w, popup_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
if(ui_draw_slider_vertical(501, popup_x + popup_w / 2, popup_y + flint_px(10),
|
||||
popup_h - flint_px(20), SETTINGS_VOLUME_MIN,
|
||||
SETTINGS_VOLUME_MAX, &app->sound_volume)) {
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
meditation_draw_screen(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
char time_text[32];
|
||||
int return_hover = 0;
|
||||
int font = flint_px(48);
|
||||
int max_w;
|
||||
int text_w;
|
||||
|
||||
if(ui_draw_icon_btn_padded(flint_px(12), flint_px(12), flint_px(24),
|
||||
flint_px(10), app->icons[UI_ICON_TYPE_RETURN], &return_hover)) {
|
||||
meditation_request_exit(app);
|
||||
return;
|
||||
}
|
||||
|
||||
draw_meditation_sound_controls(app);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmExitSession) {
|
||||
int elapsed = meditation_elapsed_seconds(app);
|
||||
int modal_result;
|
||||
|
||||
if(elapsed >= 60) {
|
||||
modal_result = ui_draw_modal_3btn(locale_get("exit_session_title"),
|
||||
locale_get("meditation_save_elapsed_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("save_button"),
|
||||
locale_get("discard_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_save_elapsed(app);
|
||||
meditation_exit_to_start(app);
|
||||
} else if(modal_result == 3) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
} else {
|
||||
modal_result = ui_draw_modal(locale_get("exit_session_title"),
|
||||
locale_get("meditation_under_minute_exit_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("exit_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
} else if(modal_result == 2) {
|
||||
meditation_exit_to_start(app);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
format_meditation_time(time_text, sizeof(time_text), app->meditation.remaining_seconds);
|
||||
max_w = view_width - flint_px(48);
|
||||
while(font > flint_px(28) && flint_text_measure(time_text, font) > max_w)
|
||||
font--;
|
||||
text_w = flint_text_measure(time_text, font);
|
||||
flint_text_draw(time_text, center_x - text_w / 2,
|
||||
flint_ui_text_y(time_text, center_y - font, font * 2, font),
|
||||
font, theme_get_text());
|
||||
|
||||
app->meditation.frame_ticks++;
|
||||
if(app->meditation.frame_ticks >= 60) {
|
||||
app->meditation.frame_ticks = 0;
|
||||
if(app->meditation.remaining_seconds > 0)
|
||||
app->meditation.remaining_seconds--;
|
||||
if(app->meditation.remaining_seconds <= 0)
|
||||
meditation_finish(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "practice_registry.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "practices/whm/whm_practice.h"
|
||||
#include "practices/whm/whm_session.h"
|
||||
#include "practices/meditation/meditation_practice.h"
|
||||
|
||||
static const PracticeDefinition g_practices[PRACTICE_COUNT] = {
|
||||
{
|
||||
.id = PRACTICE_WHM,
|
||||
.label_key = "exercise_wim_hof",
|
||||
.init = whm_practice_init,
|
||||
.destroy = whm_practice_destroy,
|
||||
.start = whm_practice_start,
|
||||
.draw_manual = whm_manual_draw,
|
||||
.close_manual = whm_manual_close,
|
||||
.draw_config = whm_config_screen_draw,
|
||||
.leave_config = whm_practice_leave_config,
|
||||
.update = NULL,
|
||||
.draw_setup_modal = NULL,
|
||||
.draw_active_session = NULL,
|
||||
.request_exit = NULL,
|
||||
},
|
||||
{
|
||||
.id = PRACTICE_MEDITATION,
|
||||
.label_key = "exercise_meditation",
|
||||
.init = meditation_practice_init,
|
||||
.destroy = meditation_practice_destroy,
|
||||
.start = meditation_practice_start,
|
||||
.draw_manual = meditation_manual_draw,
|
||||
.close_manual = meditation_manual_close,
|
||||
.draw_config = meditation_config_screen_draw,
|
||||
.leave_config = meditation_practice_leave_config,
|
||||
.update = meditation_practice_update,
|
||||
.draw_setup_modal = meditation_draw_setup_modal,
|
||||
.draw_active_session = meditation_draw_screen,
|
||||
.request_exit = meditation_request_exit,
|
||||
},
|
||||
};
|
||||
|
||||
const PracticeDefinition *
|
||||
practice_get(int id)
|
||||
{
|
||||
id = practice_clamp_id(id);
|
||||
return &g_practices[id];
|
||||
}
|
||||
|
||||
int
|
||||
practice_count(void)
|
||||
{
|
||||
return PRACTICE_COUNT;
|
||||
}
|
||||
|
||||
int
|
||||
practice_clamp_id(int id)
|
||||
{
|
||||
if(id < 0 || id >= PRACTICE_COUNT)
|
||||
return PRACTICE_WHM;
|
||||
return id;
|
||||
}
|
||||
|
||||
const char *
|
||||
practice_label(int id)
|
||||
{
|
||||
return locale_get(practice_get(id)->label_key);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_circle_bounds(InbeApp *app, int top_reserve, int bottom_reserve)
|
||||
{
|
||||
if(app != NULL)
|
||||
session_update_circle_bounds_for_view(&app->inbe, top_reserve, bottom_reserve);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_session_sounds(InbeApp *app)
|
||||
{
|
||||
update_session_sounds(app);
|
||||
}
|
||||
|
||||
int
|
||||
practice_ensure_results_saved(InbeApp *app)
|
||||
{
|
||||
return session_ensure_results_saved(app);
|
||||
}
|
||||
|
||||
int
|
||||
practice_draw_start_preview(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
return session_draw_start_preview(app, center_x, center_y);
|
||||
}
|
||||
|
||||
void
|
||||
practice_draw_active_breathing(InbeApp *app, int center_x, int center_y)
|
||||
{
|
||||
session_draw_inbe(app, center_x, center_y);
|
||||
}
|
||||
|
||||
void
|
||||
practice_update_active_breathing(InbeApp *app, int center_x, int center_y, int *hover)
|
||||
{
|
||||
session_update_screen(app, center_x, center_y, hover);
|
||||
}
|
||||
|
||||
void
|
||||
practice_draw_results(InbeApp *app, int center_x, int center_y, int *hover)
|
||||
{
|
||||
session_draw_results_screen(app, center_x, center_y, hover);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef INBE_PRACTICE_REGISTRY_H
|
||||
#define INBE_PRACTICE_REGISTRY_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef enum PracticeId {
|
||||
PRACTICE_WHM = 0,
|
||||
PRACTICE_MEDITATION = 1,
|
||||
PRACTICE_COUNT = 2
|
||||
} PracticeId;
|
||||
|
||||
typedef struct PracticeDefinition {
|
||||
PracticeId id;
|
||||
const char *label_key;
|
||||
void (*init)(InbeApp *app);
|
||||
void (*destroy)(InbeApp *app);
|
||||
void (*start)(InbeApp *app);
|
||||
void (*draw_manual)(InbeApp *app);
|
||||
void (*close_manual)(InbeApp *app, int mark_seen);
|
||||
void (*draw_config)(InbeApp *app);
|
||||
void (*leave_config)(InbeApp *app);
|
||||
void (*update)(InbeApp *app);
|
||||
void (*draw_setup_modal)(InbeApp *app);
|
||||
void (*draw_active_session)(InbeApp *app, int center_x, int center_y);
|
||||
void (*request_exit)(InbeApp *app);
|
||||
} PracticeDefinition;
|
||||
|
||||
const PracticeDefinition *practice_get(int id);
|
||||
int practice_count(void);
|
||||
int practice_clamp_id(int id);
|
||||
const char *practice_label(int id);
|
||||
void practice_update_circle_bounds(InbeApp *app, int top_reserve, int bottom_reserve);
|
||||
void practice_update_session_sounds(InbeApp *app);
|
||||
int practice_ensure_results_saved(InbeApp *app);
|
||||
int practice_draw_start_preview(InbeApp *app, int center_x, int center_y);
|
||||
void practice_draw_active_breathing(InbeApp *app, int center_x, int center_y);
|
||||
void practice_update_active_breathing(InbeApp *app, int center_x, int center_y, int *hover);
|
||||
void practice_draw_results(InbeApp *app, int center_x, int center_y, int *hover);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,418 @@
|
||||
#include "whm_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "whm_session.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
static void
|
||||
whm_draw_exact_speed_preview(Inbe *preview, int *preview_speed,
|
||||
int speed, int max_rounds, int max_breaths,
|
||||
int pause_seconds, int content_w, int content_h,
|
||||
int center_x, int center_y)
|
||||
{
|
||||
if(preview == NULL || preview_speed == NULL)
|
||||
return;
|
||||
|
||||
if(preview->phase != InbePhaseBreathe) {
|
||||
inbeinit(preview);
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
session_reset_round_breathe(preview);
|
||||
} else if(*preview_speed != speed) {
|
||||
apply_settings(preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
preview->progressive_speed = 0;
|
||||
}
|
||||
|
||||
if(*preview_speed != speed)
|
||||
*preview_speed = speed;
|
||||
|
||||
update_preview_bounds(preview, content_w, content_h);
|
||||
inbestep(preview);
|
||||
draw_preview_inbe(preview, center_x, center_y);
|
||||
}
|
||||
|
||||
static void
|
||||
whm_draw_progressive_start_speed_editor(InbeApp *app)
|
||||
{
|
||||
int modal_w = flint_px(340);
|
||||
int modal_h = flint_px(360);
|
||||
int modal_x;
|
||||
int modal_y;
|
||||
int title_font = flint_ui_font();
|
||||
int title_y;
|
||||
int close_size = flint_px(22);
|
||||
int close_padding = flint_px(8);
|
||||
int close_w = close_size + close_padding * 2;
|
||||
int close_hover = 0;
|
||||
int max_speed = app->inbe.speed_level;
|
||||
int start_speed = clampi(app->inbe.progressive_start_speed, SETTINGS_SPEED_MIN, max_speed);
|
||||
const char *title;
|
||||
int title_w;
|
||||
int title_max_w;
|
||||
|
||||
if(modal_w > view_width - flint_px(24))
|
||||
modal_w = view_width - flint_px(24);
|
||||
if(modal_h > view_height - flint_px(24))
|
||||
modal_h = view_height - flint_px(24);
|
||||
modal_x = (view_width - modal_w) / 2;
|
||||
modal_y = (view_height - modal_h) / 2;
|
||||
title_y = modal_y + flint_px(14);
|
||||
|
||||
DrawRectangle(0, 0, view_width, view_height, (Color){0, 0, 0, 180});
|
||||
DrawRectangle(modal_x, modal_y, modal_w, modal_h, theme_get_surface());
|
||||
ui_draw_bevel(modal_x, modal_y, modal_w, modal_h,
|
||||
flint_lighten(theme_get_surface(), 40), flint_darken(theme_get_surface(), 40));
|
||||
|
||||
title = locale_get("progressive_start_speed_editor_title");
|
||||
title_w = flint_text_measure(title, title_font);
|
||||
title_max_w = modal_w - close_w * 2 - flint_px(24);
|
||||
while(title_font > flint_px(12) && title_w > title_max_w) {
|
||||
title_font--;
|
||||
title_w = flint_text_measure(title, title_font);
|
||||
}
|
||||
flint_text_draw(title, modal_x + (modal_w - title_w) / 2, title_y, title_font, theme_get_text());
|
||||
|
||||
if(ui_draw_icon_btn_padded(modal_x + modal_w - close_w - flint_px(6), modal_y + flint_px(6),
|
||||
close_size, close_padding, app->icons[UI_ICON_TYPE_X], &close_hover)) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
return;
|
||||
}
|
||||
|
||||
whm_draw_exact_speed_preview(&app->start_speed_preview,
|
||||
&app->start_speed_preview_speed,
|
||||
start_speed,
|
||||
app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths),
|
||||
app->inbe.pause_seconds,
|
||||
modal_w - flint_px(48),
|
||||
flint_px(210),
|
||||
modal_x + modal_w / 2,
|
||||
modal_y + flint_px(150));
|
||||
|
||||
if(ui_draw_slider(12, modal_x + flint_px(24), modal_y + flint_px(250),
|
||||
modal_w - flint_px(48), locale_get("progressive_start_speed_label"),
|
||||
SETTINGS_SPEED_MIN, max_speed, &start_speed, "")) {
|
||||
app->inbe.progressive_start_speed = start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
whm_draw_subtab_bar(int y, int h, const char **tab_names, int tab_count,
|
||||
int selected_tab)
|
||||
{
|
||||
enum { WHM_SUBTAB_RENDER_MAX = 8 };
|
||||
FlintUISubtab tabs[WHM_SUBTAB_RENDER_MAX];
|
||||
|
||||
if(tab_count <= 0 || tab_count > WHM_SUBTAB_RENDER_MAX)
|
||||
return -1;
|
||||
for(int i = 0; i < tab_count; i++) {
|
||||
tabs[i].label = tab_names[i];
|
||||
tabs[i].disabled = 0;
|
||||
}
|
||||
return ui_draw_subtab_bar((FlintUISubtabBar){
|
||||
.bounds = {0, (float)y, (float)view_width, (float)h},
|
||||
.tabs = tabs,
|
||||
.count = tab_count,
|
||||
.selected_index = selected_tab,
|
||||
.font = flint_ui_font()
|
||||
});
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_draw_breathing_tab(InbeApp *app, int content_x, int content_w, int y,
|
||||
int *draw_breath_animation_menu)
|
||||
{
|
||||
static const char *animation_options[InbeBreathAnimationCount];
|
||||
int preview_h = flint_px(240);
|
||||
int preview_radius;
|
||||
int preview_padding = flint_px(12);
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
animation_options[InbeBreathAnimationLinear] = locale_get("breath_animation_linear");
|
||||
animation_options[InbeBreathAnimationInOut] = locale_get("breath_animation_in_out");
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
|
||||
flint_text_draw(locale_get("breath_animation_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(104, content_x, y + flint_px(26), content_w, flint_px(36),
|
||||
animation_options, InbeBreathAnimationCount,
|
||||
&app->inbe.breath_animation);
|
||||
if(draw_breath_animation_menu != NULL)
|
||||
*draw_breath_animation_menu = 1;
|
||||
y += flint_px(76);
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, preview_h);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
|
||||
preview_radius = (int)((float)app->settings_preview.rmax * 0.72f + 1.0f);
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2,
|
||||
y + preview_padding + preview_radius);
|
||||
if(ui_draw_slider(1, content_x, y + preview_padding + preview_radius * 2 + flint_px(28),
|
||||
content_w, locale_get("speed_label"),
|
||||
SETTINGS_SPEED_MIN, SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += preview_padding + preview_radius * 2 + flint_px(102);
|
||||
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &progressive_speed,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
|
||||
if(app->inbe.progressive_speed) {
|
||||
int modify_w = flint_text_measure(locale_get("modify_start_speed_button"), flint_ui_font()) + flint_px(24);
|
||||
int modify_hover = 0;
|
||||
if(modify_w > content_w)
|
||||
modify_w = content_w;
|
||||
if(progressive_start_speed != clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed)) {
|
||||
app->inbe.progressive_start_speed = clampi(progressive_start_speed, SETTINGS_SPEED_MIN, speed);
|
||||
app->settings_preview.progressive_start_speed = app->inbe.progressive_start_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
if(ui_draw_generic_button(content_x, y, modify_w, flint_px(36),
|
||||
locale_get("modify_start_speed_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &modify_hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalEditProgressiveStartSpeed;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
y += flint_px(58);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_draw_session_tab(InbeApp *app, int content_x, int content_w, int y)
|
||||
{
|
||||
int speed = app->inbe.speed_level;
|
||||
int max_rounds = app->inbe.max_rounds;
|
||||
int max_breaths = int_from_count(app->inbe.maxbreaths);
|
||||
int pause_seconds = app->inbe.pause_seconds;
|
||||
int advanced_session_controls = app->advanced_session_controls;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
int reset_w = flint_text_measure(locale_get("reset_to_defaults_label"), flint_ui_font()) + flint_px(24);
|
||||
int reset_h = flint_px(36);
|
||||
int reset_hover = 0;
|
||||
|
||||
if(ui_draw_slider(2, content_x, y, content_w, locale_get("max_rounds_label"),
|
||||
1, MaxRounds, &max_rounds, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(3, content_x, y, content_w, locale_get("max_breaths_label"),
|
||||
SETTINGS_BREATHS_MIN, SETTINGS_BREATHS_MAX, &max_breaths, "")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
if(ui_draw_slider(4, content_x, y, content_w, locale_get("pause_after_round_label"),
|
||||
SETTINGS_PAUSE_MIN, SETTINGS_PAUSE_MAX, &pause_seconds, "s")) {
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(66);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(52);
|
||||
flint_text_draw(locale_get("advanced_session_controls_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(content_x, y + flint_px(26), toggle_w, toggle_h, &advanced_session_controls,
|
||||
locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->advanced_session_controls = advanced_session_controls;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(76);
|
||||
if(reset_w > content_w)
|
||||
reset_w = content_w;
|
||||
if(ui_draw_generic_button(content_x + content_w - reset_w, y, reset_w, reset_h,
|
||||
locale_get("reset_to_defaults_label"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &reset_hover)) {
|
||||
speed = DefaultSpeedLevel;
|
||||
max_rounds = DefaultMaxRounds;
|
||||
max_breaths = DefaultMaxBreaths;
|
||||
pause_seconds = DefaultPauseSeconds;
|
||||
app->inbe.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->settings_preview.progressive_start_speed = DefaultProgressiveStartSpeed;
|
||||
app->inbe.breath_animation = InbeBreathAnimationLinear;
|
||||
app->settings_preview.breath_animation = InbeBreathAnimationLinear;
|
||||
app->advanced_session_controls = 0;
|
||||
app->hold_display_mode = HOLD_DISPLAY_CIRCLE;
|
||||
apply_settings(&app->inbe, speed, max_rounds, max_breaths, pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, max_rounds, max_breaths, pause_seconds);
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += reset_h + flint_px(28);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
static int
|
||||
whm_config_content_height(InbeApp *app, int content_w)
|
||||
{
|
||||
if(app->practice_config_tab == 0) {
|
||||
int span = content_w < flint_px(240) ? content_w : flint_px(240);
|
||||
int preview_radius = span / 2;
|
||||
int h;
|
||||
if(preview_radius < flint_px(60))
|
||||
preview_radius = flint_px(60);
|
||||
if(preview_radius > flint_px(120))
|
||||
preview_radius = flint_px(120);
|
||||
preview_radius = (int)((float)preview_radius * 0.72f + 1.0f);
|
||||
h = flint_px(12) + preview_radius * 2 + flint_px(102);
|
||||
h += flint_px(66);
|
||||
if(app->inbe.progressive_speed)
|
||||
h += flint_px(58);
|
||||
h += flint_px(76);
|
||||
return h;
|
||||
}
|
||||
|
||||
return flint_px(66) * 3 +
|
||||
flint_px(26) + flint_px(52) +
|
||||
flint_px(76) +
|
||||
flint_px(36) + flint_px(28);
|
||||
}
|
||||
|
||||
void
|
||||
whm_config_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int config_tab_h = flint_px(40);
|
||||
int config_tab_gap = flint_px(14);
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int scroll_y;
|
||||
int scroll_h;
|
||||
int content_h;
|
||||
int controls_w;
|
||||
int draw_breath_animation_menu = 0;
|
||||
int clicked_config_tab = -1;
|
||||
const char *config_tabs[] = {
|
||||
locale_get("settings_section_breathing"),
|
||||
locale_get("settings_section_session"),
|
||||
};
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIHeader header;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->practice_config_tab < 0 || app->practice_config_tab > 1)
|
||||
app->practice_config_tab = 0;
|
||||
|
||||
header = ui_draw_title_header(title_h, locale_get("exercise_wim_hof"),
|
||||
(Texture2D){0}, app->icons[UI_ICON_TYPE_X]);
|
||||
if(header.right_clicked) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
app->settings_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
clicked_config_tab = whm_draw_subtab_bar(title_h, config_tab_h, config_tabs, 2,
|
||||
app->practice_config_tab);
|
||||
if(clicked_config_tab >= 0 && clicked_config_tab != app->practice_config_tab) {
|
||||
app->practice_config_tab = clicked_config_tab;
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
scroll_y = title_h + config_tab_h + config_tab_gap;
|
||||
scroll_h = view_height - scroll_y;
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
controls_w = content_w;
|
||||
for(int i = 0; i < 3; i++) {
|
||||
FlintUIScrollView measured;
|
||||
content_h = whm_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == controls_w)
|
||||
break;
|
||||
controls_w = measured.content_w;
|
||||
}
|
||||
|
||||
content_h = whm_config_content_height(app, controls_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
|
||||
.content_height = content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->settings_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
if(app->practice_config_tab == 0) {
|
||||
whm_config_draw_breathing_tab(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y, &draw_breath_animation_menu);
|
||||
} else {
|
||||
whm_config_draw_session_tab(app, scroll_view.content_x, scroll_view.content_w,
|
||||
scroll_view.content_y);
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
if(draw_breath_animation_menu && ui_draw_dropdown_menu(104)) {
|
||||
app->inbe.breath_animation = clampi(app->inbe.breath_animation,
|
||||
InbeBreathAnimationLinear,
|
||||
InbeBreathAnimationCount - 1);
|
||||
app->settings_preview.breath_animation = app->inbe.breath_animation;
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalEditProgressiveStartSpeed)
|
||||
whm_draw_progressive_start_speed_editor(app);
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
#include "whm_practice.h"
|
||||
#include "app.h"
|
||||
#include "whm_session.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define CONTENT_MAX_W 800 /* Responsive width for tutorial text reflow */
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
/* Tutorial text content ordered by step */
|
||||
static const char *const TUTORIAL_KEYS[] = {
|
||||
"tutorial_step_intro",
|
||||
"tutorial_step_method",
|
||||
"tutorial_step_breathe",
|
||||
"tutorial_step_exhale_hold",
|
||||
"tutorial_step_inhale_hold"
|
||||
};
|
||||
|
||||
#define TUTORIAL_STEPS_COUNT (sizeof(TUTORIAL_KEYS) / sizeof(TUTORIAL_KEYS[0]))
|
||||
#define TUTORIAL_LINE_SPACING flint_px(8) /* Normal readable line spacing */
|
||||
|
||||
static Color
|
||||
manual_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_hold_preview(InbeApp *app, int center_x, int center_y, int radius)
|
||||
{
|
||||
int seconds = (app->inbe.frame / 60) % 60;
|
||||
char text[CountSize];
|
||||
int font = flint_px(16);
|
||||
int thickness = flint_px(5);
|
||||
Color text_color = theme_get_text();
|
||||
|
||||
count_from_int(text, seconds);
|
||||
if(thickness < 3)
|
||||
thickness = 3;
|
||||
|
||||
if(app->hold_display_mode == HOLD_DISPLAY_CIRCLE) {
|
||||
float sweep = 360.0f * (float)((app->inbe.frame % (60 * 60))) / (float)(60 * 60);
|
||||
|
||||
DrawRing((Vector2){center_x, center_y},
|
||||
(float)(radius + flint_px(8) - thickness / 2),
|
||||
(float)(radius + flint_px(8) + thickness / 2),
|
||||
-90.0f, -90.0f + sweep, 96, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_bg());
|
||||
} else {
|
||||
DrawCircle(center_x, center_y, radius, theme_get_circle());
|
||||
DrawCircleLines(center_x, center_y, radius, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_circle());
|
||||
}
|
||||
|
||||
flint_ui_draw_text_centered(text, center_x, center_y, font, text_color);
|
||||
}
|
||||
|
||||
static FlintUIParagraph
|
||||
tutorial_paragraph(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int has_icon = step == 1;
|
||||
return (FlintUIParagraph){
|
||||
.text = locale_get(TUTORIAL_KEYS[step]),
|
||||
.icon = has_icon ? app->icons[UI_ICON_TYPE_WRENCH] : (Texture2D){0},
|
||||
.icon_type = has_icon ? UI_ICON_TYPE_WRENCH : UI_ICON_TYPE_NONE,
|
||||
.icon_size = has_icon ? flint_px(14) : 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
tutorial_paragraph_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
return flint_ui_paragraph_height(tutorial_paragraph(app, step, content_w, body_font));
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_paragraph(InbeApp *app, int step, int content_x, int *y, int content_w, int body_font)
|
||||
{
|
||||
flint_ui_paragraph_draw(tutorial_paragraph(app, step, content_w, body_font), content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
manual_tutorial_content_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int actual_content_h = 0;
|
||||
|
||||
if(step == 0) {
|
||||
actual_content_h += flint_px(170) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 0, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 1, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
int preview_span;
|
||||
int preview_rmax;
|
||||
int slider_h = flint_px(40);
|
||||
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(20);
|
||||
preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
|
||||
preview_rmax = preview_span / 2;
|
||||
if(preview_rmax < flint_px(60)) preview_rmax = flint_px(60);
|
||||
if(preview_rmax > flint_px(120)) preview_rmax = flint_px(120);
|
||||
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
|
||||
actual_content_h += slider_h + flint_px(8);
|
||||
} else if(step == 3) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24) +
|
||||
flint_px(42) + flint_px(18);
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font);
|
||||
} else {
|
||||
actual_content_h += flint_px(80) +
|
||||
tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
}
|
||||
|
||||
return actual_content_h;
|
||||
}
|
||||
|
||||
void
|
||||
whm_manual_close(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
|
||||
static void
|
||||
manual_screen_start_exercise(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
whm_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int tab_h = flint_px(56);
|
||||
int viewport_h = view_height - title_h - tab_h;
|
||||
int body_font = flint_ui_font();
|
||||
int footer_content_pad = flint_ui_font() / 2;
|
||||
int content_area_h = viewport_h - footer_content_pad; /* For scissor mode and scroll calculations */
|
||||
int previous_step;
|
||||
int content_x;
|
||||
int content_w;
|
||||
const char *title = locale_get("tutorial_title");
|
||||
char page_label[32];
|
||||
int close_clicked = 0;
|
||||
int step = app->tutorial_step;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
|
||||
step = clampi(step, 0, (int)TUTORIAL_STEPS_COUNT - 1);
|
||||
app->tutorial_step = step;
|
||||
previous_step = step;
|
||||
|
||||
if(IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_ENTER)) {
|
||||
if(step < (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
app->tutorial_step++;
|
||||
else
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
if(IsKeyPressed(KEY_LEFT) && step > 0)
|
||||
app->tutorial_step--;
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
whm_manual_close(app, 0);
|
||||
|
||||
step = app->tutorial_step;
|
||||
if(previous_step != step) {
|
||||
app->manual_scroll = 0;
|
||||
previous_step = step;
|
||||
}
|
||||
|
||||
switch(step) {
|
||||
case 1: title = locale_get("tutorial_method_title"); break;
|
||||
case 2: title = locale_get("tutorial_step1_title"); break;
|
||||
case 3: title = locale_get("tutorial_step2_title"); break;
|
||||
case 4: title = locale_get("tutorial_step3_title"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* Calculate responsive content width */
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
int min_width = flint_px(280);
|
||||
if(responsive_max_w < min_width)
|
||||
responsive_max_w = min_width;
|
||||
|
||||
int side_padding = flint_page_side_padding();
|
||||
flint_centered_column(responsive_max_w, side_padding, &content_x, &content_w);
|
||||
|
||||
close_clicked = ui_draw_screen_header(title, 1);
|
||||
if(close_clicked)
|
||||
whm_manual_close(app, 0);
|
||||
|
||||
{
|
||||
int top_padding = flint_px(16);
|
||||
int total_content_h;
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
total_content_h = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding;
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = total_content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
}
|
||||
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
content_x = scroll_view.content_x;
|
||||
content_w = scroll_view.content_w;
|
||||
{
|
||||
int y = scroll_view.content_y + flint_px(16);
|
||||
if(step == 0) {
|
||||
int img_h = flint_px(170);
|
||||
ui_draw_tutorial_image(app->whm.image_1, "practices/whm/1.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
|
||||
draw_tutorial_paragraph(app, 0, content_x, &y, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
draw_tutorial_paragraph(app, 1, content_x, &y, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
int speed = app->inbe.speed_level;
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(20); /* Increased spacing between text and circle */
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2, y + flint_px(40));
|
||||
y += (int)(app->settings_preview.rmax * 0.72f) + flint_px(54);
|
||||
|
||||
if(ui_draw_slider(10, content_x, y, content_w, locale_get("speed_label"), SETTINGS_SPEED_MIN,
|
||||
SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
} else if(step == 3) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
int breath_button_hover = 0;
|
||||
int center_x = content_x + content_w / 2;
|
||||
y += hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, center_x, y, hold_preview_radius);
|
||||
y += hold_preview_extent + flint_px(24);
|
||||
ui_draw_text_btn(center_x, y, locale_get("breath_button"), &breath_button_hover);
|
||||
y += flint_px(42) + flint_px(18);
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
} else {
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
locale_format(page_label, sizeof(page_label), "tutorial_page_label",
|
||||
step + 1, (int)TUTORIAL_STEPS_COUNT);
|
||||
|
||||
int left_hover = 0;
|
||||
int right_hover = 0;
|
||||
const char *left_label = step == 0 ? locale_get("tutorial_skip_button") : locale_get("tutorial_back_button");
|
||||
const char *right_label = step == (int)TUTORIAL_STEPS_COUNT - 1 ? locale_get("tutorial_start_button") : locale_get("tutorial_next_button");
|
||||
int footer_gap = flint_px(10);
|
||||
int page_font = flint_ui_font();
|
||||
int button_h = flint_px(34);
|
||||
int button_w = (content_w - footer_gap) / 2;
|
||||
int footer_y = view_height - flint_px(38);
|
||||
int counter_gap = flint_px(6);
|
||||
|
||||
|
||||
flint_text_draw(page_label,
|
||||
view_width / 2 - flint_text_measure(page_label, page_font) / 2,
|
||||
footer_y - page_font - counter_gap, page_font, theme_get_text());
|
||||
|
||||
if(step == 0) {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover))
|
||||
manual_screen_start_exercise(app);
|
||||
} else {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover)) {
|
||||
app->tutorial_step--;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ui_draw_generic_button(content_x + button_w + footer_gap, footer_y, button_w, button_h,
|
||||
right_label, UI_BUTTON_STYLE_PRIMARY, 0, &right_hover)) {
|
||||
if(step == (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
manual_screen_start_exercise(app);
|
||||
else {
|
||||
app->tutorial_step++;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "whm_practice.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "whm_session.h"
|
||||
|
||||
void
|
||||
whm_practice_init(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->whm.image_1.id == 0)
|
||||
app->whm.image_1 = app_load_asset_texture("practices/whm/1.jpg");
|
||||
if(app->whm.image_2.id == 0)
|
||||
app->whm.image_2 = app_load_asset_texture("practices/whm/2.jpg");
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_destroy(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
app_unload_texture(app->whm.image_1);
|
||||
app_unload_texture(app->whm.image_2);
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_start(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
mark_exercise_manual_seen(app, EXERCISE_WIM_HOF);
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
void
|
||||
whm_practice_leave_config(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_WHM_PRACTICE_H
|
||||
#define INBE_WHM_PRACTICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
void whm_practice_init(InbeApp *app);
|
||||
void whm_practice_destroy(InbeApp *app);
|
||||
void whm_practice_start(InbeApp *app);
|
||||
void whm_practice_leave_config(InbeApp *app);
|
||||
void whm_manual_draw(InbeApp *app);
|
||||
void whm_manual_close(InbeApp *app, int mark_seen);
|
||||
void whm_config_screen_draw(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "session.h"
|
||||
#include "whm_session.h"
|
||||
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
@@ -156,25 +156,6 @@ remember_sound_state(InbeApp *app)
|
||||
cpcount(app->sound_last_count, app->inbe.count);
|
||||
}
|
||||
|
||||
static void
|
||||
play_app_sound(InbeApp *app, Sound sound, float scale)
|
||||
{
|
||||
float volume;
|
||||
|
||||
if(app == NULL || !app->audio_ready || sound.frameCount == 0 || app->sound_volume <= 0)
|
||||
return;
|
||||
|
||||
volume = ((float)app->sound_volume / 100.0f) * scale;
|
||||
if(volume < 0.0f)
|
||||
volume = 0.0f;
|
||||
if(volume > 1.0f)
|
||||
volume = 1.0f;
|
||||
|
||||
StopSound(sound);
|
||||
SetSoundVolume(sound, volume);
|
||||
PlaySound(sound);
|
||||
}
|
||||
|
||||
void
|
||||
update_session_sounds(InbeApp *app)
|
||||
{
|
||||
@@ -197,17 +178,17 @@ update_session_sounds(InbeApp *app)
|
||||
if(app->inbe.phase == InbePhaseBreathe) {
|
||||
if(screen_changed || phase_changed || dir_changed) {
|
||||
Sound breath_snd = app->inbe.dir == 0 ? app->breath_in_sound : app->breath_out_sound;
|
||||
play_app_sound(app, breath_snd, 1.0f);
|
||||
app_play_sound(app, breath_snd, 1.0f);
|
||||
}
|
||||
if(count_changed) {
|
||||
int count_value = int_from_count(app->inbe.count);
|
||||
int maxbreaths_value = int_from_count(app->inbe.maxbreaths);
|
||||
if(count_value == maxbreaths_value - 1)
|
||||
play_app_sound(app, app->bell_sound, 0.8f);
|
||||
app_play_sound(app, app->bell_sound, 0.8f);
|
||||
}
|
||||
} else if(phase_changed) {
|
||||
if(app->inbe.phase == InbePhaseNext && app->sound_last_phase == InbePhaseRecover)
|
||||
play_app_sound(app, app->breath_out_sound, 1.0f);
|
||||
app_play_sound(app, app->breath_out_sound, 1.0f);
|
||||
}
|
||||
|
||||
remember_sound_state(app);
|
||||
@@ -299,6 +280,7 @@ session_ensure_results_saved(InbeApp *app)
|
||||
app->results_path, sizeof(app->results_path))) {
|
||||
app->results_saved = 1;
|
||||
sync_habits_for_activity(app, app->exercise_type);
|
||||
inbe_app_auto_sync(app);
|
||||
TraceLog(LOG_INFO, "INBE: session saved successfully");
|
||||
return 1;
|
||||
}
|
||||
@@ -338,7 +320,7 @@ finish_hold(InbeApp *app)
|
||||
app->inbe.breath_frame = 0;
|
||||
app->inbe.breathtick = 0;
|
||||
app->inbe.sectick = 0;
|
||||
play_app_sound(app, app->breath_in_sound, 1.0f);
|
||||
app_play_sound(app, app->breath_in_sound, 1.0f);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef INBE_APP_SESSION_H
|
||||
#define INBE_APP_SESSION_H
|
||||
#ifndef INBE_WHM_SESSION_H
|
||||
#define INBE_WHM_SESSION_H
|
||||
|
||||
#include "app.h"
|
||||
|
||||
@@ -21,9 +21,11 @@ extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
HABIT_WEEKLY_INITIAL_DAYS = 7,
|
||||
HABIT_WEEKLY_LOAD_DAYS = 7,
|
||||
HABIT_WEEKLY_MAX_DAYS = INBE_HABIT_MAX_DAYS
|
||||
HABIT_WEEKLY_MONTH_DAYS = 31,
|
||||
HABIT_WEEKLY_INITIAL_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_LOAD_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_MAX_DAYS = 36500,
|
||||
HABIT_COUNTER_LONG_PRESS_FRAMES = 30
|
||||
};
|
||||
|
||||
/* Helper functions */
|
||||
@@ -43,7 +45,7 @@ copy_text(char *dst, size_t dst_size, const char *src)
|
||||
static int
|
||||
habit_find_day(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
if(habit == NULL)
|
||||
if(habit == NULL || habit->days == NULL)
|
||||
return -1;
|
||||
for(int i = 0; i < habit->day_count; i++) {
|
||||
if(habit->days[i].day_index == day_index)
|
||||
@@ -52,6 +54,112 @@ habit_find_day(const InbeHabit *habit, int day_index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_counting_enabled(const InbeHabit *habit)
|
||||
{
|
||||
return habit != NULL &&
|
||||
(habit->counter_enabled ||
|
||||
(habit->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
|
||||
habit->sync_activity != 0));
|
||||
}
|
||||
|
||||
static int
|
||||
habit_counter_day_action(InbeApp *app, int habit_index, int day_index,
|
||||
int x, int y, int w, int h, int disabled,
|
||||
int allow_left_increment)
|
||||
{
|
||||
Vector2 mouse = GetScreenToWorld2D(GetMousePosition(), app->camera);
|
||||
Rectangle bounds = {(float)x, (float)y, (float)w, (float)h};
|
||||
int inside = !disabled && CheckCollisionPointRec(mouse, bounds);
|
||||
int same = app->habit_counter_press_index == habit_index &&
|
||||
app->habit_counter_press_day == day_index;
|
||||
|
||||
if(disabled)
|
||||
return 0;
|
||||
if(inside && IsMouseButtonReleased(MOUSE_BUTTON_RIGHT))
|
||||
return -1;
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && inside) {
|
||||
app->habit_counter_press_index = habit_index;
|
||||
app->habit_counter_press_day = day_index;
|
||||
app->habit_counter_press_frames = 0;
|
||||
app->habit_counter_press_long_done = 0;
|
||||
app->habit_counter_press_start_x = (int)mouse.x;
|
||||
app->habit_counter_press_start_y = (int)mouse.y;
|
||||
same = 1;
|
||||
}
|
||||
|
||||
if(same && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
int dx = (int)mouse.x - app->habit_counter_press_start_x;
|
||||
int dy = (int)mouse.y - app->habit_counter_press_start_y;
|
||||
int threshold = flint_px(8);
|
||||
|
||||
if(dx > threshold || dx < -threshold || dy > threshold || dy < -threshold) {
|
||||
app->habit_counter_press_day = 0;
|
||||
app->habit_counter_press_index = -1;
|
||||
return 0;
|
||||
}
|
||||
app->habit_counter_press_frames++;
|
||||
if(inside && !app->habit_counter_press_long_done &&
|
||||
app->habit_counter_press_frames >= HABIT_COUNTER_LONG_PRESS_FRAMES) {
|
||||
app->habit_counter_press_long_done = 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(same && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
int action;
|
||||
if(inside && app->habit_counter_press_long_done)
|
||||
action = -2;
|
||||
else
|
||||
action = inside && allow_left_increment ? 1 : 0;
|
||||
app->habit_counter_press_day = 0;
|
||||
app->habit_counter_press_index = -1;
|
||||
app->habit_counter_press_frames = 0;
|
||||
app->habit_counter_press_long_done = 0;
|
||||
return action;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_habit_reserve_days(InbeHabit *habit, int capacity)
|
||||
{
|
||||
InbeHabitDay *days;
|
||||
int new_capacity;
|
||||
|
||||
if(habit == NULL || capacity <= habit->day_capacity)
|
||||
return habit != NULL;
|
||||
new_capacity = habit->day_capacity > 0 ? habit->day_capacity : 16;
|
||||
while(new_capacity < capacity) {
|
||||
if(new_capacity > 1073741823 / 2)
|
||||
return 0;
|
||||
new_capacity *= 2;
|
||||
}
|
||||
days = realloc(habit->days, (size_t)new_capacity * sizeof(*days));
|
||||
if(days == NULL)
|
||||
return 0;
|
||||
memset(days + habit->day_capacity, 0,
|
||||
(size_t)(new_capacity - habit->day_capacity) * sizeof(*days));
|
||||
habit->days = days;
|
||||
habit->day_capacity = new_capacity;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habits_free(InbeHabits *habits)
|
||||
{
|
||||
if(habits == NULL)
|
||||
return;
|
||||
for(int i = 0; i < INBE_HABIT_MAX; i++) {
|
||||
free(habits->items[i].days);
|
||||
habits->items[i].days = NULL;
|
||||
habits->items[i].day_count = 0;
|
||||
habits->items[i].day_capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Core habits functions from habits.c */
|
||||
int
|
||||
inbe_habits_today_index(void)
|
||||
@@ -67,7 +175,19 @@ int
|
||||
inbe_habit_completed_day(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
int index = habit_find_day(habit, day_index);
|
||||
return index >= 0 && habit->days[index].completed;
|
||||
return index >= 0 &&
|
||||
(habit->days[index].completed || habit->days[index].count > 0);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_habit_day_count(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
int index = habit_find_day(habit, day_index);
|
||||
if(index < 0)
|
||||
return 0;
|
||||
if(habit->days[index].count > 0)
|
||||
return habit->days[index].count;
|
||||
return habit->days[index].completed ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -93,10 +213,10 @@ inbe_habits_clear_days(InbeHabits *habits)
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
InbeHabit *habit = &habits->items[i];
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
if(habit->days[d].day_index > 0 || habit->days[d].completed)
|
||||
if(habit->days[d].day_index > 0 || habit->days[d].completed ||
|
||||
habit->days[d].count > 0)
|
||||
cleared++;
|
||||
}
|
||||
memset(habit->days, 0, sizeof(habit->days));
|
||||
habit->day_count = 0;
|
||||
}
|
||||
return cleared;
|
||||
@@ -123,6 +243,7 @@ inbe_habits_add_default_set(InbeHabits *habits)
|
||||
if(habits == NULL)
|
||||
return;
|
||||
|
||||
inbe_habits_free(habits);
|
||||
memset(habits, 0, sizeof(*habits));
|
||||
inbe_habits_add_seed(habits, "meditation", "Meditation", (Color){126, 183, 230, 255},
|
||||
habit_activity_mask_for(EXERCISE_WIM_HOF) |
|
||||
@@ -138,6 +259,7 @@ inbe_habits_delete(InbeHabits *habits, int index)
|
||||
if(habits == NULL || index < 0 || index >= habits->count)
|
||||
return;
|
||||
|
||||
free(habits->items[index].days);
|
||||
for(int i = index; i < habits->count - 1; i++)
|
||||
habits->items[i] = habits->items[i + 1];
|
||||
habits->count--;
|
||||
@@ -173,6 +295,7 @@ inbe_habits_add_custom(InbeHabits *habits, const char *name, Color color,
|
||||
habit->color.a = 255;
|
||||
habit->sync_mode = sync_mode;
|
||||
habit->sync_activity = sync_activity;
|
||||
habit->counter_enabled = sync_activity != 0;
|
||||
habits->selected = habits->count;
|
||||
habits->count++;
|
||||
inbe_habits_save(habits);
|
||||
@@ -195,6 +318,7 @@ inbe_habits_add_seed(InbeHabits *habits, const char *id, const char *name,
|
||||
habit->color = color;
|
||||
habit->sync_mode = INBE_HABIT_SYNC_ACTIVITIES;
|
||||
habit->sync_activity = activity_mask;
|
||||
habit->counter_enabled = 1;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -232,9 +356,37 @@ inbe_habit_set_day(InbeHabits *habits, int index, int day_index, int completed)
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].completed = completed != 0;
|
||||
} else if(completed && habit->day_count < INBE_HABIT_MAX_DAYS) {
|
||||
habit->days[existing_index].count = completed ? 1 : 0;
|
||||
} else if(completed && inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->days[habit->day_count].count = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_set_day_count(InbeHabits *habits, int index, int day_index, int count)
|
||||
{
|
||||
InbeHabit *habit;
|
||||
int existing_index;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
if(count < 0)
|
||||
count = 0;
|
||||
|
||||
habit = &habits->items[index];
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].count = count;
|
||||
habit->days[existing_index].completed = count > 0;
|
||||
} else if(count > 0 && inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].count = count;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
@@ -253,16 +405,31 @@ inbe_habit_toggle_day(InbeHabits *habits, int index, int day_index)
|
||||
habit = &habits->items[index];
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].completed = !habit->days[existing_index].completed;
|
||||
} else if(habit->day_count < INBE_HABIT_MAX_DAYS) {
|
||||
int completed = !(habit->days[existing_index].completed ||
|
||||
habit->days[existing_index].count > 0);
|
||||
habit->days[existing_index].completed = completed;
|
||||
habit->days[existing_index].count = completed ? 1 : 0;
|
||||
} else if(inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->days[habit->day_count].count = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_increment_day(InbeHabits *habits, int index, int day_index, int delta)
|
||||
{
|
||||
int count;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
count = inbe_habit_day_count(&habits->items[index], day_index) + delta;
|
||||
inbe_habit_set_day_count(habits, index, day_index, count);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_toggle_today(InbeHabits *habits, int index)
|
||||
{
|
||||
@@ -367,6 +534,7 @@ habit_edit_begin_new(InbeApp *app)
|
||||
app->habit_edit_color = (Color){99, 196, 165, 255};
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_NONE;
|
||||
app->habit_edit_sync_activity = 0;
|
||||
app->habit_edit_counter_enabled = 0;
|
||||
app->inbe.screen = InbeScreenHabitEdit;
|
||||
}
|
||||
|
||||
@@ -386,6 +554,7 @@ habit_edit_begin(InbeApp *app, int index)
|
||||
app->habit_edit_color = app->habits.items[index].color;
|
||||
app->habit_edit_sync_mode = app->habits.items[index].sync_mode;
|
||||
app->habit_edit_sync_activity = app->habits.items[index].sync_activity;
|
||||
app->habit_edit_counter_enabled = habit_counting_enabled(&app->habits.items[index]);
|
||||
app->inbe.screen = InbeScreenHabitEdit;
|
||||
}
|
||||
|
||||
@@ -401,6 +570,7 @@ habit_edit_cancel(InbeApp *app)
|
||||
app->habit_edit_cursor = 0;
|
||||
app->habit_edit_focused = 0;
|
||||
app->habit_edit_text[0] = '\0';
|
||||
app->habit_edit_counter_enabled = 0;
|
||||
ui_focus_set_text_input_active(0);
|
||||
}
|
||||
|
||||
@@ -444,10 +614,16 @@ habit_edit_commit(InbeApp *app)
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_ACTIVITIES;
|
||||
else
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_NONE;
|
||||
if(app->habit_edit_sync_activity != 0)
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
if(app->habit_edit_is_new) {
|
||||
inbe_habits_add_custom(&app->habits, text, app->habit_edit_color,
|
||||
app->habit_edit_sync_mode,
|
||||
app->habit_edit_sync_activity);
|
||||
int created = inbe_habits_add_custom(&app->habits, text, app->habit_edit_color,
|
||||
app->habit_edit_sync_mode,
|
||||
app->habit_edit_sync_activity);
|
||||
if(created >= 0 && created < app->habits.count) {
|
||||
app->habits.items[created].counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
inbe_habits_save(&app->habits);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->habits.items[index].name,
|
||||
sizeof(app->habits.items[index].name), "%s", text);
|
||||
@@ -455,9 +631,11 @@ habit_edit_commit(InbeApp *app)
|
||||
app->habits.items[index].color.a = 255;
|
||||
app->habits.items[index].sync_mode = app->habit_edit_sync_mode;
|
||||
app->habits.items[index].sync_activity = app->habit_edit_sync_activity;
|
||||
app->habits.items[index].counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
app->habits.selected = index;
|
||||
inbe_habits_save(&app->habits);
|
||||
}
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
habit_edit_cancel(app);
|
||||
app->inbe.screen = InbeScreenHabits;
|
||||
@@ -610,6 +788,7 @@ habit_refresh_detail_day_completion(InbeApp *app)
|
||||
inbe_habit_set_day(&app->habits, index, day, 0);
|
||||
app->habits.selected = selected;
|
||||
inbe_habits_save(&app->habits);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -638,6 +817,46 @@ habit_linked_has_day(const HabitLinkedContext *ctx, int day_index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_linked_session_count_for_day(const HabitLinkedContext *ctx, int day_index)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
if(ctx == NULL)
|
||||
return 0;
|
||||
for(int i = 0; i < ctx->count; i++) {
|
||||
int entry_day = ctx->entries[i].year * 10000 +
|
||||
ctx->entries[i].month * 100 +
|
||||
ctx->entries[i].day;
|
||||
if(entry_day == day_index)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_effective_day_count(const InbeHabit *habit, int day_index,
|
||||
const HabitLinkedContext *linked_ctx)
|
||||
{
|
||||
int manual_count = inbe_habit_day_count(habit, day_index);
|
||||
int session_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
return manual_count > session_count ? manual_count : session_count;
|
||||
}
|
||||
|
||||
static void
|
||||
habit_apply_count_action(InbeHabits *habits, int index, int day_index,
|
||||
int delta, int minimum_count)
|
||||
{
|
||||
int count;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
count = inbe_habit_day_count(&habits->items[index], day_index) + delta;
|
||||
if(count < minimum_count)
|
||||
count = minimum_count;
|
||||
inbe_habit_set_day_count(habits, index, day_index, count);
|
||||
}
|
||||
|
||||
static void
|
||||
habit_open_linked_edit_page(InbeApp *app, int habit_index, int day_index)
|
||||
{
|
||||
@@ -771,6 +990,26 @@ draw_habit_link_dot(int x, int y, int w, Color color)
|
||||
flint_px(3), color);
|
||||
}
|
||||
|
||||
static Color
|
||||
habit_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
habit_weekly_draw_text_line(const char *text, int x, int y, int w, int h,
|
||||
int text_size, Color color)
|
||||
{
|
||||
int font_size;
|
||||
|
||||
if(text == NULL || text[0] == '\0' || w <= 0 || h <= 0)
|
||||
return;
|
||||
font_size = flint_px(text_size);
|
||||
flint_text_draw(text, x, flint_text_y(text, y, h, font_size), font_size, color);
|
||||
}
|
||||
|
||||
static int
|
||||
habit_weekly_summary(const HabitLinkedContext *ctx, int day_index,
|
||||
char *primary, size_t primary_size,
|
||||
@@ -821,8 +1060,9 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
int hovered;
|
||||
Color fill = completed ? theme_get_button() : flint_darken(theme_get_bg(), 10);
|
||||
Color text = disabled ? flint_darken(theme_get_text(), 35) : theme_get_text();
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_px(FLINT_TEXT_8);
|
||||
int pad = flint_px(9);
|
||||
int text_x;
|
||||
int text_w;
|
||||
const char *line1 = primary != NULL ? primary : "";
|
||||
const char *line2 = secondary != NULL ? secondary : "";
|
||||
|
||||
@@ -841,25 +1081,28 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
|
||||
if(hovered)
|
||||
fill = theme_get_button_hover();
|
||||
if(!disabled && completed)
|
||||
text = habit_text_color_for_background(fill);
|
||||
DrawRectangle(x, y, w, h, fill);
|
||||
ui_draw_bevel(x, y, w, h, flint_lighten(fill, 36), flint_darken(fill, 42));
|
||||
|
||||
text_x = x + pad;
|
||||
text_w = w - pad * 2;
|
||||
|
||||
if(line1[0] != '\0') {
|
||||
if(line2[0] != '\0') {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(5),
|
||||
w - flint_px(16), flint_px(18)},
|
||||
font, FLINT_TEXT_12, text);
|
||||
flint_text_draw_fitted_in_rect(line2,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(24),
|
||||
w - flint_px(16), flint_px(12)},
|
||||
small_font, FLINT_TEXT_8,
|
||||
flint_darken(text, 16));
|
||||
int line1_h = flint_px(24);
|
||||
int line2_h = flint_px(16);
|
||||
int block_h = line1_h + line2_h;
|
||||
int block_y = y + (h - block_h) / 2;
|
||||
habit_weekly_draw_text_line(line1, text_x, block_y, text_w, line1_h,
|
||||
FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line2, text_x, block_y + line1_h, text_w, line2_h,
|
||||
FLINT_TEXT_8, flint_darken(text, 16));
|
||||
} else {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y,
|
||||
w - flint_px(16), h},
|
||||
font, FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line1, text_x, y + flint_px(3),
|
||||
text_w, h - flint_px(6),
|
||||
FLINT_TEXT_16, text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,7 +1126,7 @@ habit_weekly_visible_days(InbeHabits *habits)
|
||||
static int
|
||||
habit_weekly_content_height(int visible_days)
|
||||
{
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int load_h = flint_px(38);
|
||||
|
||||
@@ -908,7 +1151,7 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
int gap = flint_px(8);
|
||||
int button_x;
|
||||
int button_w;
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int day_font = flint_px(16);
|
||||
int date_font = flint_px(FLINT_TEXT_8);
|
||||
@@ -947,6 +1190,10 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
int completed;
|
||||
int has_linked_day;
|
||||
int future_day;
|
||||
int count = 0;
|
||||
int action = 0;
|
||||
int counting_enabled;
|
||||
int minimum_count;
|
||||
char primary[64] = "";
|
||||
char secondary[64] = "";
|
||||
int session_count;
|
||||
@@ -956,12 +1203,22 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
day_index = habit_tm_date_index(&row_tm);
|
||||
future_day = day_index > today_index;
|
||||
has_linked_day = linked_ctx != NULL && habit_linked_has_day(linked_ctx, day_index);
|
||||
counting_enabled = habit_counting_enabled(active);
|
||||
minimum_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
session_count = habit_weekly_summary(linked_ctx, day_index,
|
||||
primary, sizeof(primary),
|
||||
secondary, sizeof(secondary));
|
||||
if(counting_enabled)
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = inbe_habit_completed_day(active, day_index);
|
||||
if(!completed && !future_day && has_linked_day)
|
||||
if(!completed && !future_day && (has_linked_day || count > 0))
|
||||
completed = 1;
|
||||
if(counting_enabled && count > 0 && session_count > 0 &&
|
||||
secondary[0] != '\0') {
|
||||
size_t len = strlen(secondary);
|
||||
snprintf(secondary + len, sizeof(secondary) - len,
|
||||
" / total %d", count);
|
||||
}
|
||||
if(session_count <= 0 && completed) {
|
||||
snprintf(primary, sizeof(primary), "Completed");
|
||||
secondary[0] = '\0';
|
||||
@@ -983,17 +1240,49 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
date_font, flint_darken(theme_get_text(), 18));
|
||||
}
|
||||
|
||||
if(habit_weekly_summary_button(app, button_x, y, button_w, row_h, completed, future_day,
|
||||
primary, secondary)) {
|
||||
if(counting_enabled) {
|
||||
(void)habit_weekly_summary_button(app, button_x, y, button_w, row_h,
|
||||
completed, future_day, primary, secondary);
|
||||
action = habit_counter_day_action(app, selected, day_index,
|
||||
button_x, y, button_w, row_h,
|
||||
future_day, !has_linked_day);
|
||||
if(action == 0 && has_linked_day &&
|
||||
!future_day && CheckCollisionPointRec(GetScreenToWorld2D(GetMousePosition(), app->camera),
|
||||
(Rectangle){(float)button_x, (float)y, (float)button_w, (float)row_h}) &&
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
}
|
||||
} else if(habit_weekly_summary_button(app, button_x, y, button_w, row_h, completed, future_day,
|
||||
primary, secondary)) {
|
||||
if(has_linked_day) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
} else {
|
||||
inbe_habit_toggle_day(&app->habits, selected, day_index);
|
||||
active = &app->habits.items[selected];
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
if(action == 1 || action == -1) {
|
||||
habit_apply_count_action(&app->habits, selected, day_index, action,
|
||||
minimum_count);
|
||||
active = &app->habits.items[selected];
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = count > 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
if(completed && !future_day)
|
||||
draw_habit_completion_underline(button_x, y, button_w, row_h, active->color);
|
||||
if(counting_enabled && count > 0 && !future_day) {
|
||||
char count_label[16];
|
||||
int count_font = flint_px(8);
|
||||
int count_w;
|
||||
snprintf(count_label, sizeof(count_label), "%d", count);
|
||||
count_w = flint_text_measure(count_label, count_font);
|
||||
flint_text_draw(count_label,
|
||||
button_x + button_w - count_w - flint_px(6),
|
||||
y + flint_px(5),
|
||||
count_font, theme_get_text());
|
||||
}
|
||||
if(!future_day && has_linked_day)
|
||||
draw_habit_link_dot(button_x, y, button_w, active->color);
|
||||
|
||||
@@ -1277,6 +1566,10 @@ draw_habits_screen(InbeApp *app)
|
||||
int completed;
|
||||
int future_day;
|
||||
int has_linked_day;
|
||||
int count = 0;
|
||||
int action = 0;
|
||||
int counting_enabled;
|
||||
int minimum_count;
|
||||
|
||||
if(day < 1 || day > days_in_month) {
|
||||
DrawRectangle(cell_x, cell_y, cell_w, cell_h, flint_darken(theme_get_bg(), 5));
|
||||
@@ -1287,10 +1580,28 @@ draw_habits_screen(InbeApp *app)
|
||||
day_index = year * 10000 + mon * 100 + day;
|
||||
future_day = day_index > today_index;
|
||||
has_linked_day = linked_ctx != NULL && habit_linked_has_day(linked_ctx, day_index);
|
||||
counting_enabled = habit_counting_enabled(active);
|
||||
minimum_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
if(counting_enabled)
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = inbe_habit_completed_day(active, day_index);
|
||||
if(!completed && !future_day && has_linked_day)
|
||||
if(!completed && !future_day && (has_linked_day || count > 0))
|
||||
completed = 1;
|
||||
if(ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
if(counting_enabled) {
|
||||
(void)ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
completed ? UI_BUTTON_STYLE_PRIMARY : UI_BUTTON_STYLE_SECONDARY,
|
||||
future_day, &hover);
|
||||
action = habit_counter_day_action(app, selected, day_index,
|
||||
cell_x, cell_y, cell_w, cell_h,
|
||||
future_day, !has_linked_day);
|
||||
if(action == 0 && has_linked_day && !future_day &&
|
||||
CheckCollisionPointRec(GetScreenToWorld2D(GetMousePosition(), app->camera),
|
||||
(Rectangle){(float)cell_x, (float)cell_y,
|
||||
(float)cell_w, (float)cell_h}) &&
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
}
|
||||
} else if(ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
completed ? UI_BUTTON_STYLE_PRIMARY : UI_BUTTON_STYLE_SECONDARY,
|
||||
future_day, &hover)) {
|
||||
if(has_linked_day) {
|
||||
@@ -1298,11 +1609,31 @@ draw_habits_screen(InbeApp *app)
|
||||
} else {
|
||||
inbe_habit_toggle_day(&app->habits, selected, day_index);
|
||||
active = &app->habits.items[selected];
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
if(action == 1 || action == -1) {
|
||||
habit_apply_count_action(&app->habits, selected, day_index, action,
|
||||
minimum_count);
|
||||
active = &app->habits.items[selected];
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = count > 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
if(completed && !future_day) {
|
||||
draw_habit_completion_underline(cell_x, cell_y, cell_w, cell_h, active->color);
|
||||
}
|
||||
if(counting_enabled && count > 0 && !future_day) {
|
||||
char count_label[16];
|
||||
int count_font = flint_px(8);
|
||||
int count_w;
|
||||
snprintf(count_label, sizeof(count_label), "%d", count);
|
||||
count_w = flint_text_measure(count_label, count_font);
|
||||
flint_text_draw(count_label,
|
||||
cell_x + cell_w - count_w - flint_px(4),
|
||||
cell_y + flint_px(4),
|
||||
count_font, theme_get_text());
|
||||
}
|
||||
if(!future_day && has_linked_day) {
|
||||
draw_habit_link_dot(cell_x, cell_y, cell_w, active->color);
|
||||
}
|
||||
@@ -1416,8 +1747,10 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
habit_edit_cancel(app);
|
||||
if(index >= 0 && index < app->habits.count)
|
||||
if(index >= 0 && index < app->habits.count) {
|
||||
inbe_habits_delete(&app->habits, index);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
app->inbe.screen = InbeScreenHabits;
|
||||
}
|
||||
return;
|
||||
@@ -1468,10 +1801,30 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
app->habit_edit_sync_mode = app->habit_edit_sync_activity != 0
|
||||
? INBE_HABIT_SYNC_ACTIVITIES
|
||||
: INBE_HABIT_SYNC_NONE;
|
||||
if(app->habit_edit_sync_activity != 0)
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
}
|
||||
y += flint_px(42);
|
||||
}
|
||||
|
||||
y += flint_px(4);
|
||||
flint_text_draw("Counting", content_x, y, label_font, flint_darken(theme_get_text(), 34));
|
||||
y += flint_px(24);
|
||||
if(app->habit_edit_sync_activity != 0) {
|
||||
int forced_counter = 1;
|
||||
ui_draw_checkbox_toggle_disabled(content_x, y, "Allow multiple counts",
|
||||
&forced_counter, 1);
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
y += flint_px(30);
|
||||
flint_text_draw("Required for practice-linked habits", content_x, y,
|
||||
label_font, flint_darken(theme_get_text(), 42));
|
||||
y += flint_px(12);
|
||||
} else if(ui_draw_checkbox_toggle(content_x, y, "Allow multiple counts",
|
||||
&app->habit_edit_counter_enabled)) {
|
||||
app->habit_edit_counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
}
|
||||
y += flint_px(42);
|
||||
|
||||
if(!app->habit_edit_is_new) {
|
||||
int delete_w = flint_px(160);
|
||||
int delete_h = flint_px(38);
|
||||
@@ -1704,6 +2057,53 @@ draw_habit_session_edit_content(InbeApp *app, HabitLinkedContext *ctx, int conte
|
||||
y += section_gap;
|
||||
}
|
||||
|
||||
if(ctx->day_filter > 0 &&
|
||||
app->habit_detail_index >= 0 &&
|
||||
app->habit_detail_index < app->habits.count) {
|
||||
InbeHabit *habit = &app->habits.items[app->habit_detail_index];
|
||||
int minimum_count = ctx->count;
|
||||
int total_count = habit_effective_day_count(habit, ctx->day_filter, ctx);
|
||||
int button_h = flint_px(34);
|
||||
int step_w = flint_px(42);
|
||||
int gap = flint_px(8);
|
||||
int minus_x = content_x;
|
||||
int plus_x = content_x + content_w - step_w;
|
||||
int label_x = minus_x + step_w + gap;
|
||||
int label_w = plus_x - label_x - gap;
|
||||
int hover = 0;
|
||||
char total_text[64];
|
||||
char min_text[64];
|
||||
|
||||
y += flint_px(6);
|
||||
if(draw) {
|
||||
snprintf(total_text, sizeof(total_text), "Total count %d", total_count);
|
||||
snprintf(min_text, sizeof(min_text), "Minimum %d from session%s",
|
||||
minimum_count, minimum_count == 1 ? "" : "s");
|
||||
if(ui_draw_generic_button(minus_x, y, step_w, button_h, "-",
|
||||
UI_BUTTON_STYLE_SECONDARY,
|
||||
total_count <= minimum_count, &hover)) {
|
||||
habit_apply_count_action(&app->habits, app->habit_detail_index,
|
||||
ctx->day_filter, -1, minimum_count);
|
||||
inbe_app_auto_sync(app);
|
||||
return y;
|
||||
}
|
||||
DrawRectangle(label_x, y, label_w, button_h, flint_darken(theme_get_bg(), 5));
|
||||
flint_text_draw(total_text, label_x + flint_px(8),
|
||||
y + flint_px(4), flint_ui_font_small(), theme_get_text());
|
||||
flint_text_draw(min_text, label_x + flint_px(8),
|
||||
y + flint_px(20), flint_px(FLINT_TEXT_8),
|
||||
flint_darken(theme_get_text(), 18));
|
||||
if(ui_draw_generic_button(plus_x, y, step_w, button_h, "+",
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
habit_apply_count_action(&app->habits, app->habit_detail_index,
|
||||
ctx->day_filter, 1, minimum_count);
|
||||
inbe_app_auto_sync(app);
|
||||
return y;
|
||||
}
|
||||
}
|
||||
y += button_h + flint_px(8);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ enum {
|
||||
INBE_HABIT_MAX = 10,
|
||||
INBE_HABIT_ID_SIZE = 32,
|
||||
INBE_HABIT_NAME_SIZE = 40,
|
||||
INBE_HABIT_MAX_DAYS = 366,
|
||||
HABIT_LINKED_ENTRY_MAX = 128,
|
||||
HABIT_LINKED_PATH_SIZE = 80
|
||||
};
|
||||
@@ -37,6 +36,7 @@ typedef enum InbeHabitSyncMode {
|
||||
typedef struct InbeHabitDay {
|
||||
int day_index;
|
||||
int completed;
|
||||
int count;
|
||||
} InbeHabitDay;
|
||||
|
||||
typedef struct InbeHabit {
|
||||
@@ -45,8 +45,10 @@ typedef struct InbeHabit {
|
||||
Color color;
|
||||
int sync_mode;
|
||||
int sync_activity;
|
||||
InbeHabitDay days[INBE_HABIT_MAX_DAYS];
|
||||
int counter_enabled;
|
||||
InbeHabitDay *days;
|
||||
int day_count;
|
||||
int day_capacity;
|
||||
} InbeHabit;
|
||||
|
||||
typedef struct InbeHabits {
|
||||
@@ -87,18 +89,20 @@ typedef struct HabitLinkedContext {
|
||||
int best_seconds;
|
||||
} HabitLinkedContext;
|
||||
|
||||
/* External functions */
|
||||
void save_settings(InbeApp *app);
|
||||
|
||||
/* Core habits functions */
|
||||
void inbe_habits_init(InbeHabits *habits);
|
||||
void inbe_habits_free(InbeHabits *habits);
|
||||
void inbe_habits_save(const InbeHabits *habits);
|
||||
int inbe_habits_clear_days(InbeHabits *habits);
|
||||
int inbe_habit_reserve_days(InbeHabit *habit, int capacity);
|
||||
int inbe_habits_today_index(void);
|
||||
int inbe_habit_completed_day(const InbeHabit *habit, int day_index);
|
||||
int inbe_habit_completed_today(const InbeHabit *habit);
|
||||
void inbe_habit_set_day(InbeHabits *habits, int index, int day_index, int completed);
|
||||
void inbe_habit_set_day_count(InbeHabits *habits, int index, int day_index, int count);
|
||||
int inbe_habit_day_count(const InbeHabit *habit, int day_index);
|
||||
void inbe_habit_toggle_day(InbeHabits *habits, int index, int day_index);
|
||||
void inbe_habit_increment_day(InbeHabits *habits, int index, int day_index, int delta);
|
||||
void inbe_habit_toggle_today(InbeHabits *habits, int index);
|
||||
void inbe_habits_add_default(InbeHabits *habits);
|
||||
void inbe_habits_add_default_set(InbeHabits *habits);
|
||||
|
||||
@@ -1,510 +1,36 @@
|
||||
#include "manual_screen.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "session.h"
|
||||
#include "locale.h"
|
||||
#include "meditation_music.h"
|
||||
#include "theme.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define CONTENT_MAX_W 800 /* Responsive width for tutorial text reflow */
|
||||
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
/* Tutorial text content ordered by step */
|
||||
static const char *const TUTORIAL_KEYS[] = {
|
||||
"tutorial_step_intro",
|
||||
"tutorial_step_method",
|
||||
"tutorial_step_progressive_speed",
|
||||
"tutorial_step_breathe",
|
||||
"tutorial_step_exhale_hold",
|
||||
"tutorial_step_inhale_hold"
|
||||
};
|
||||
|
||||
#define TUTORIAL_STEPS_COUNT (sizeof(TUTORIAL_KEYS) / sizeof(TUTORIAL_KEYS[0]))
|
||||
#define TUTORIAL_LINE_SPACING flint_px(8) /* Normal readable line spacing */
|
||||
|
||||
static Color
|
||||
manual_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_hold_preview(InbeApp *app, int center_x, int center_y, int radius)
|
||||
{
|
||||
int seconds = (app->inbe.frame / 60) % 60;
|
||||
char text[CountSize];
|
||||
int font = flint_px(16);
|
||||
int thickness = flint_px(5);
|
||||
Color text_color = theme_get_text();
|
||||
|
||||
count_from_int(text, seconds);
|
||||
if(thickness < 3)
|
||||
thickness = 3;
|
||||
|
||||
if(app->hold_display_mode == HOLD_DISPLAY_CIRCLE) {
|
||||
float sweep = 360.0f * (float)((app->inbe.frame % (60 * 60))) / (float)(60 * 60);
|
||||
|
||||
DrawRing((Vector2){center_x, center_y},
|
||||
(float)(radius + flint_px(8) - thickness / 2),
|
||||
(float)(radius + flint_px(8) + thickness / 2),
|
||||
-90.0f, -90.0f + sweep, 96, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_bg());
|
||||
} else {
|
||||
DrawCircle(center_x, center_y, radius, theme_get_circle());
|
||||
DrawCircleLines(center_x, center_y, radius, theme_get_text());
|
||||
text_color = manual_text_color_for_background(theme_get_circle());
|
||||
}
|
||||
|
||||
flint_ui_draw_text_centered(text, center_x, center_y, font, text_color);
|
||||
}
|
||||
|
||||
static FlintUIParagraph
|
||||
tutorial_paragraph(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int has_icon = step == 1;
|
||||
return (FlintUIParagraph){
|
||||
.text = locale_get(TUTORIAL_KEYS[step]),
|
||||
.icon = has_icon ? app->icons[UI_ICON_TYPE_WRENCH] : (Texture2D){0},
|
||||
.icon_type = has_icon ? UI_ICON_TYPE_WRENCH : UI_ICON_TYPE_NONE,
|
||||
.icon_size = has_icon ? flint_px(14) : 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
tutorial_paragraph_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
return flint_ui_paragraph_height(tutorial_paragraph(app, step, content_w, body_font));
|
||||
}
|
||||
|
||||
static void
|
||||
draw_tutorial_paragraph(InbeApp *app, int step, int content_x, int *y, int content_w, int body_font)
|
||||
{
|
||||
flint_ui_paragraph_draw(tutorial_paragraph(app, step, content_w, body_font), content_x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
manual_tutorial_content_height(InbeApp *app, int step, int content_w, int body_font)
|
||||
{
|
||||
int actual_content_h = 0;
|
||||
|
||||
if(step == 0) {
|
||||
actual_content_h += flint_px(170) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 0, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 1, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(68);
|
||||
if(app->inbe.progressive_speed)
|
||||
actual_content_h += flint_px(66);
|
||||
} else if(step == 3) {
|
||||
int preview_span;
|
||||
int preview_rmax;
|
||||
int slider_h = flint_px(40);
|
||||
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font) + flint_px(20);
|
||||
preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
|
||||
preview_rmax = preview_span / 2;
|
||||
if(preview_rmax < flint_px(60)) preview_rmax = flint_px(60);
|
||||
if(preview_rmax > flint_px(120)) preview_rmax = flint_px(120);
|
||||
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
|
||||
actual_content_h += slider_h + flint_px(8);
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
|
||||
actual_content_h += flint_px(26) + flint_px(36) + flint_px(20);
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24);
|
||||
actual_content_h += tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
} else {
|
||||
actual_content_h += flint_px(200) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 5, content_w, body_font);
|
||||
}
|
||||
|
||||
return actual_content_h;
|
||||
}
|
||||
#include "practices/practice_registry.h"
|
||||
|
||||
void
|
||||
manual_screen_reset_layouts(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
|
||||
void
|
||||
manual_screen_close_tutorial(InbeApp *app, int mark_seen)
|
||||
{
|
||||
if(mark_seen)
|
||||
mark_exercise_manual_seen(app, app->exercise_type);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
}
|
||||
const PracticeDefinition *practice;
|
||||
|
||||
static void
|
||||
manual_screen_start_exercise(InbeApp *app)
|
||||
{
|
||||
mark_exercise_manual_seen(app, app->exercise_type);
|
||||
app->tutorial_step = 0;
|
||||
app->manual_scroll = 0;
|
||||
|
||||
if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalMeditationSetup;
|
||||
app->modal.selected_button = 0;
|
||||
app->inbe.screen = InbeScreenStart;
|
||||
if(app == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
session_start(app);
|
||||
}
|
||||
|
||||
static void
|
||||
meditation_manual_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int body_font = flint_ui_font();
|
||||
int content_x;
|
||||
int content_w;
|
||||
int responsive_max_w = (int)(view_width * 0.90f);
|
||||
int max_content_w = flint_px(520);
|
||||
int y;
|
||||
int button_w;
|
||||
int button_h = flint_px(36);
|
||||
int button_y = view_height - flint_px(52);
|
||||
int content_y = title_h + flint_px(20);
|
||||
int content_h = button_y - content_y - flint_px(16);
|
||||
int content_total_h;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
FlintUIParagraph paragraph;
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < flint_px(280))
|
||||
responsive_max_w = flint_px(280);
|
||||
|
||||
flint_centered_column(responsive_max_w, flint_page_side_padding(), &content_x, &content_w);
|
||||
|
||||
if(ui_draw_screen_header(locale_get("meditation_manual_title"), 1))
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
if(content_h < flint_px(120))
|
||||
content_h = flint_px(120);
|
||||
|
||||
paragraph = (FlintUIParagraph){
|
||||
.text = locale_get("meditation_manual_text"),
|
||||
.icon = (Texture2D){0},
|
||||
.icon_type = UI_ICON_TYPE_NONE,
|
||||
.icon_size = 0,
|
||||
.width = content_w,
|
||||
.font = body_font,
|
||||
.line_gap = TUTORIAL_LINE_SPACING,
|
||||
.color = theme_get_text(),
|
||||
};
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
paragraph.width = content_w;
|
||||
content_total_h = meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) +
|
||||
flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y,
|
||||
(float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
paragraph.width = content_w;
|
||||
content_total_h = meditation_music_measure_settings(app, content_w, 0, 1) +
|
||||
flint_px(34) +
|
||||
flint_ui_paragraph_height(paragraph) +
|
||||
flint_px(20);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)content_y,
|
||||
(float)view_width, (float)content_h},
|
||||
.content_height = content_total_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
y = scroll_view.content_y;
|
||||
meditation_music_draw_guide_settings(app, scroll_view.content_x, scroll_view.content_w, &y);
|
||||
y += flint_px(34);
|
||||
paragraph.width = scroll_view.content_w;
|
||||
flint_ui_paragraph_draw(paragraph, scroll_view.content_x, &y);
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
meditation_music_draw_dropdown_menu(app);
|
||||
|
||||
{
|
||||
int hover = 0;
|
||||
|
||||
button_w = content_w;
|
||||
if(button_w > flint_px(260))
|
||||
button_w = flint_px(260);
|
||||
|
||||
if(ui_draw_generic_button(content_x + (content_w - button_w) / 2, button_y,
|
||||
button_w, button_h, locale_get("tutorial_start_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
practice = practice_get(app->exercise_type);
|
||||
if(practice->close_manual != NULL)
|
||||
practice->close_manual(app, mark_seen);
|
||||
}
|
||||
|
||||
void
|
||||
manual_screen_draw(InbeApp *app)
|
||||
{
|
||||
int title_h = ui_screen_header_height();
|
||||
int tab_h = flint_px(56);
|
||||
int viewport_h = view_height - title_h - tab_h;
|
||||
int body_font = flint_ui_font();
|
||||
int footer_content_pad = flint_ui_font() / 2;
|
||||
int content_area_h = viewport_h - footer_content_pad; /* For scissor mode and scroll calculations */
|
||||
int previous_step;
|
||||
int content_x;
|
||||
int content_w;
|
||||
const char *title = locale_get("tutorial_title");
|
||||
char page_label[32];
|
||||
int close_clicked = 0;
|
||||
int step = app->tutorial_step;
|
||||
FlintUIScrollArea scroll_area;
|
||||
FlintUIScrollView scroll_view;
|
||||
const PracticeDefinition *practice;
|
||||
|
||||
if(app->exercise_type == EXERCISE_MEDITATION) {
|
||||
meditation_manual_draw(app);
|
||||
if(app == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
step = clampi(step, 0, (int)TUTORIAL_STEPS_COUNT - 1);
|
||||
app->tutorial_step = step;
|
||||
previous_step = step;
|
||||
|
||||
if(IsKeyPressed(KEY_RIGHT) || IsKeyPressed(KEY_ENTER)) {
|
||||
if(step < (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
app->tutorial_step++;
|
||||
else
|
||||
manual_screen_start_exercise(app);
|
||||
}
|
||||
if(IsKeyPressed(KEY_LEFT) && step > 0)
|
||||
app->tutorial_step--;
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
step = app->tutorial_step;
|
||||
if(previous_step != step) {
|
||||
app->manual_scroll = 0;
|
||||
previous_step = step;
|
||||
}
|
||||
|
||||
switch(step) {
|
||||
case 1: title = locale_get("tutorial_method_title"); break;
|
||||
case 2: title = locale_get("tutorial_progressive_speed_title"); break;
|
||||
case 3: title = locale_get("tutorial_step1_title"); break;
|
||||
case 4: title = locale_get("tutorial_step2_title"); break;
|
||||
case 5: title = locale_get("tutorial_step3_title"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* Calculate responsive content width */
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
int min_width = flint_px(280);
|
||||
if(responsive_max_w < min_width)
|
||||
responsive_max_w = min_width;
|
||||
|
||||
int side_padding = flint_page_side_padding();
|
||||
flint_centered_column(responsive_max_w, side_padding, &content_x, &content_w);
|
||||
|
||||
close_clicked = ui_draw_screen_header(title, 1);
|
||||
if(close_clicked)
|
||||
manual_screen_close_tutorial(app, 0);
|
||||
|
||||
{
|
||||
int top_padding = flint_px(16);
|
||||
int total_content_h;
|
||||
|
||||
for(int pass = 0; pass < 3; pass++) {
|
||||
FlintUIScrollView measured;
|
||||
|
||||
total_content_h = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding;
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = total_content_h,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
measured = ui_scroll_container_measure(scroll_area);
|
||||
if(measured.content_w == content_w)
|
||||
break;
|
||||
content_w = measured.content_w;
|
||||
}
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)title_h, (float)view_width, (float)content_area_h},
|
||||
.content_height = manual_tutorial_content_height(app, step, content_w, body_font) +
|
||||
top_padding,
|
||||
.content_x = content_x,
|
||||
.content_width = content_w,
|
||||
.scroll_offset = &app->manual_scroll,
|
||||
.wheel_step = flint_px(42),
|
||||
.scrollbar_x = view_width - flint_px(8)
|
||||
};
|
||||
}
|
||||
|
||||
scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
content_x = scroll_view.content_x;
|
||||
content_w = scroll_view.content_w;
|
||||
{
|
||||
int y = scroll_view.content_y + flint_px(16);
|
||||
if(step == 0) {
|
||||
int img_h = flint_px(170);
|
||||
ui_draw_tutorial_image(app->whm_1_image, "whm/1.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
|
||||
draw_tutorial_paragraph(app, 0, content_x, &y, content_w, body_font);
|
||||
} else if(step == 1) {
|
||||
draw_tutorial_paragraph(app, 1, content_x, &y, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(18);
|
||||
{
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
if(ui_draw_toggle_switch(content_x, y, toggle_w, toggle_h,
|
||||
&progressive_speed, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = progressive_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += toggle_h + flint_px(20);
|
||||
}
|
||||
} else if(step == 3) {
|
||||
int speed = app->inbe.speed_level;
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
y += flint_px(20); /* Increased spacing between text and circle */
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
inbestep(&app->settings_preview);
|
||||
if(app->settings_preview.phase != InbePhaseBreathe) {
|
||||
reset_settings_preview(app);
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
}
|
||||
draw_preview_inbe(&app->settings_preview, content_x + content_w / 2, y + flint_px(40));
|
||||
y += (int)(app->settings_preview.rmax * 0.72f) + flint_px(54);
|
||||
|
||||
if(ui_draw_slider(10, content_x, y, content_w, locale_get("speed_label"), SETTINGS_SPEED_MIN,
|
||||
SETTINGS_SPEED_MAX, &speed, "")) {
|
||||
apply_settings(&app->inbe, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
apply_settings(&app->settings_preview, speed, app->inbe.max_rounds,
|
||||
int_from_count(app->inbe.maxbreaths), app->inbe.pause_seconds);
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
} else if(step == 4) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(36) + flint_px(20) + hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, content_x + content_w / 2, y, hold_preview_radius);
|
||||
y += hold_preview_extent + flint_px(24);
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
} else {
|
||||
int img_h = flint_px(200);
|
||||
ui_draw_tutorial_image(app->whm_2_image, "whm/2.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
draw_tutorial_paragraph(app, 5, content_x, &y, content_w, body_font);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
locale_format(page_label, sizeof(page_label), "tutorial_page_label",
|
||||
step + 1, (int)TUTORIAL_STEPS_COUNT);
|
||||
|
||||
int left_hover = 0;
|
||||
int right_hover = 0;
|
||||
const char *left_label = step == 0 ? locale_get("tutorial_skip_button") : locale_get("tutorial_back_button");
|
||||
const char *right_label = step == (int)TUTORIAL_STEPS_COUNT - 1 ? locale_get("tutorial_start_button") : locale_get("tutorial_next_button");
|
||||
int footer_gap = flint_px(10);
|
||||
int page_font = flint_ui_font();
|
||||
int button_h = flint_px(34);
|
||||
int button_w = (content_w - footer_gap) / 2;
|
||||
int footer_y = view_height - flint_px(38);
|
||||
int counter_gap = flint_px(6);
|
||||
|
||||
|
||||
flint_text_draw(page_label,
|
||||
view_width / 2 - flint_text_measure(page_label, page_font) / 2,
|
||||
footer_y - page_font - counter_gap, page_font, theme_get_text());
|
||||
|
||||
if(step == 0) {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover))
|
||||
manual_screen_start_exercise(app);
|
||||
} else {
|
||||
if(ui_draw_generic_button(content_x, footer_y, button_w, button_h,
|
||||
left_label, UI_BUTTON_STYLE_PRIMARY, 0, &left_hover)) {
|
||||
app->tutorial_step--;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(ui_draw_generic_button(content_x + button_w + footer_gap, footer_y, button_w, button_h,
|
||||
right_label, UI_BUTTON_STYLE_PRIMARY, 0, &right_hover)) {
|
||||
if(step == (int)TUTORIAL_STEPS_COUNT - 1)
|
||||
manual_screen_start_exercise(app);
|
||||
else {
|
||||
app->tutorial_step++;
|
||||
app->manual_scroll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
app->settings_drag_slider = 0;
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
practice = practice_get(app->exercise_type);
|
||||
if(practice->draw_manual != NULL)
|
||||
practice->draw_manual(app);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "practice_screen.h"
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "practices/practice_registry.h"
|
||||
|
||||
void
|
||||
on_practice_tab_click(void *user_data)
|
||||
@@ -15,7 +15,7 @@ int
|
||||
practice_activity_count_for_tab(int tab)
|
||||
{
|
||||
(void)tab;
|
||||
return EXERCISE_COUNT;
|
||||
return practice_count();
|
||||
}
|
||||
|
||||
int
|
||||
@@ -24,30 +24,22 @@ practice_activity_for_tab(int tab, int index)
|
||||
(void)tab;
|
||||
if(index < 0)
|
||||
return EXERCISE_WIM_HOF;
|
||||
if(index >= EXERCISE_COUNT)
|
||||
return EXERCISE_COUNT - 1;
|
||||
if(index >= practice_count())
|
||||
return practice_count() - 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
const char *
|
||||
practice_activity_label(int exercise)
|
||||
{
|
||||
switch(exercise) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return locale_get("exercise_meditation");
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return locale_get("exercise_wim_hof");
|
||||
}
|
||||
return practice_label(exercise);
|
||||
}
|
||||
|
||||
int
|
||||
practice_activity_index_for_tab(int tab, int exercise)
|
||||
{
|
||||
(void)tab;
|
||||
if(exercise < 0 || exercise >= EXERCISE_COUNT)
|
||||
return EXERCISE_WIM_HOF;
|
||||
return exercise;
|
||||
return practice_clamp_id(exercise);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -55,6 +47,5 @@ practice_clamp_activity_to_tab(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(app->exercise_type < 0 || app->exercise_type >= EXERCISE_COUNT)
|
||||
app->exercise_type = EXERCISE_WIM_HOF;
|
||||
app->exercise_type = practice_clamp_id(app->exercise_type);
|
||||
}
|
||||
@@ -0,0 +1,679 @@
|
||||
#include "settings_data.h"
|
||||
|
||||
#include "settings_screen.h"
|
||||
#include "settings_sync_account.h"
|
||||
#include "app.h"
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "theme.h"
|
||||
#include "version.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "flint_ui.h"
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(_WIN32) && !defined(PLATFORM_WEB)
|
||||
#define INBE_HAS_FLINT_FILE_DIALOG 1
|
||||
#include "flint_file_dialog.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_import.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
SETTINGS_DATA_ACTION_NONE = 0,
|
||||
SETTINGS_DATA_ACTION_IMPORT,
|
||||
SETTINGS_DATA_ACTION_EXPORT,
|
||||
SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT
|
||||
};
|
||||
|
||||
enum {
|
||||
SETTINGS_DATA_VIEW_MAIN = 0,
|
||||
SETTINGS_DATA_VIEW_SYNC_ACCOUNT = 1
|
||||
};
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_SERVER_URL_DEFAULT "https://api.waozi.xyz"
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static FlintFileDialog export_dlg;
|
||||
static FlintFileDialog import_dlg;
|
||||
static int data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
#endif
|
||||
|
||||
static char pending_import_path[FS_PATH_MAX] = "";
|
||||
static DataImportInfo pending_import_info;
|
||||
|
||||
static void settings_import_data(InbeApp *app);
|
||||
static void settings_export_data(InbeApp *app);
|
||||
static void settings_request_delete_all_data(InbeApp *app);
|
||||
static void settings_sync_server_load(InbeApp *app);
|
||||
|
||||
static void
|
||||
settings_clear_pending_import(void)
|
||||
{
|
||||
pending_import_path[0] = '\0';
|
||||
memset(&pending_import_info, 0, sizeof(pending_import_info));
|
||||
}
|
||||
|
||||
static void
|
||||
settings_import_success(InbeApp *app, int imported_settings)
|
||||
{
|
||||
app_reload_after_import(app, imported_settings);
|
||||
settings_screen_set_status_success(locale_get("imported_data"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Import successful");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_perform_import(InbeApp *app, const char *path, DataImportMode mode)
|
||||
{
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data_import_with_mode(path, mode)) {
|
||||
settings_import_success(app, mode == DATA_IMPORT_DATA_AND_SETTINGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Import failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_begin_import_for_path(InbeApp *app, const char *path)
|
||||
{
|
||||
DataImportInfo info;
|
||||
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if(!data_inspect_import(path, &info) || !info.valid) {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: Invalid import file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
if((info.has_sessions || info.has_habits) && info.has_settings) {
|
||||
snprintf(pending_import_path, sizeof(pending_import_path), "%s", path);
|
||||
pending_import_info = info;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmImportDataSettings;
|
||||
app->modal.selected_button = 0;
|
||||
settings_screen_clear_status();
|
||||
return;
|
||||
}
|
||||
|
||||
settings_perform_import(app, path, DATA_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_draw_import_choice_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
int font = flint_ui_font();
|
||||
int msg_y;
|
||||
int msg_x;
|
||||
const char *message = locale_get("import_choice_message");
|
||||
int row_gap = flint_px(10);
|
||||
int btn_h = flint_px(36);
|
||||
int btn_y;
|
||||
int btn_w;
|
||||
int hover = 0;
|
||||
|
||||
(void)app;
|
||||
frame = ui_draw_modal_frame(flint_px(320), flint_px(232),
|
||||
locale_get("import_choice_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
msg_x = frame.content_x;
|
||||
msg_y = frame.content_y;
|
||||
flint_text_draw(message, msg_x, msg_y, font, theme_get_text());
|
||||
|
||||
btn_y = frame.y + frame.h - flint_px(24) - btn_h * 2 - row_gap;
|
||||
btn_w = (frame.content_w - row_gap) / 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y, btn_w, btn_h,
|
||||
locale_get("cancel_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
if(ui_draw_generic_button(frame.content_x + btn_w + row_gap, btn_y, btn_w, btn_h,
|
||||
locale_get("import_data_only_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y + btn_h + row_gap,
|
||||
frame.content_w, btn_h,
|
||||
locale_get("import_data_settings_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icon_columns(int content_w)
|
||||
{
|
||||
int max_columns = 5;
|
||||
int min_columns = 2;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
|
||||
for(int columns = max_columns; columns > min_columns; columns--) {
|
||||
int total_w = icon_btn_w * columns + icon_spacing * (columns - 1);
|
||||
if(total_w <= content_w)
|
||||
return columns;
|
||||
}
|
||||
|
||||
return min_columns;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icons_height(int content_w)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int row_spacing = flint_px(16);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int rows = (link_count + columns - 1) / columns;
|
||||
|
||||
return flint_px(8) + rows * icon_btn_w + (rows - 1) * row_spacing;
|
||||
}
|
||||
|
||||
int
|
||||
settings_data_content_height(int content_w)
|
||||
{
|
||||
int data_button_h = flint_px(36);
|
||||
|
||||
return data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
flint_px(42) +
|
||||
settings_link_icons_height(content_w) +
|
||||
flint_px(8) + flint_px(22) +
|
||||
flint_px(40);
|
||||
}
|
||||
|
||||
int
|
||||
settings_data_is_configuring(const InbeApp *app)
|
||||
{
|
||||
return app != NULL && app->settings_tab == SETTINGS_TAB_DATA &&
|
||||
app->settings_data_view == SETTINGS_DATA_VIEW_SYNC_ACCOUNT;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_server_load(InbeApp *app)
|
||||
{
|
||||
const char *saved;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
saved = inbe_storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
snprintf(app->sync_server_url, sizeof(app->sync_server_url), "%s",
|
||||
saved != NULL && saved[0] != '\0'
|
||||
? saved
|
||||
: INBE_SYNC_SERVER_URL_DEFAULT);
|
||||
app->sync_server_url_cursor = (int)strlen(app->sync_server_url);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_open_sync_account_config(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
settings_sync_server_load(app);
|
||||
app->settings_data_view = SETTINGS_DATA_VIEW_SYNC_ACCOUNT;
|
||||
app->settings_scroll = 0;
|
||||
app->sync_server_url_focused = 0;
|
||||
settings_screen_clear_status();
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static void
|
||||
settings_apply_file_dialog_theme(InbeApp *app)
|
||||
{
|
||||
int theme_id = app != NULL ? app->theme_id : FLINT_THEME_SKY;
|
||||
int dark_mode = app != NULL && app->dark_mode != 0;
|
||||
|
||||
if(theme_id < 0 || theme_id >= FLINT_THEME_COUNT)
|
||||
theme_id = FLINT_THEME_SKY;
|
||||
flint_file_dialog_set_theme_scope(flint_theme_scope_for((FlintThemeId)theme_id,
|
||||
dark_mode != 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
settings_start_sync_key_export_dialog(InbeApp *app, const char *filename)
|
||||
{
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_save(&export_dlg, locale_get("sync_save_key_dialog_title"), filename);
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT;
|
||||
return 4;
|
||||
#else
|
||||
(void)app;
|
||||
(void)filename;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_link_icons(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int grid_w = icon_btn_w * columns + icon_spacing * (columns - 1);
|
||||
int links_start_x = content_x + (content_w - grid_w) / 2;
|
||||
int row_spacing = flint_px(16);
|
||||
Texture2D icons[5] = {
|
||||
app->icons[UI_ICON_TYPE_DISCORD],
|
||||
app->icons[UI_ICON_TYPE_TELEGRAM],
|
||||
app->icons[UI_ICON_TYPE_GITHUB],
|
||||
app->icons[UI_ICON_TYPE_BTC],
|
||||
app->icons[UI_ICON_TYPE_MONERO]
|
||||
};
|
||||
const char *urls[5] = {
|
||||
"https://discord.com/invite/JbGZ4yENDt",
|
||||
"https://t.me/lotusinbe",
|
||||
"https://github.com/waozixyz/inbe",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=btc&network_to=Mainnet&address=bc1qxzcetg50f6epgddc09n82xqn3zswlmk44235y5&donation=True&simple_mode=True&amount=0.001&name=Inner+Breeze&[email protected]&ticker_from=btc&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=xmr&network_to=Mainnet&address=86CbC3d4a2GhT9auh6X99JhmhTMFKVVk8Q9cLrKTHkBu8LLkoNWgkBeAT3YZrvDM6NczYe8brUJNsTiFmwpWDZYnFG5kzSH&donation=True&simple_mode=True&amount=0.1&name=Inner+Breeze&[email protected]&ticker_from=xmr&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff"
|
||||
};
|
||||
|
||||
*y += flint_px(8);
|
||||
for(int i = 0; i < link_count; i++) {
|
||||
int col = i % columns;
|
||||
int row = i / columns;
|
||||
int icon_x = links_start_x + col * (icon_btn_w + icon_spacing) + icon_padding;
|
||||
int icon_y = *y + row * (icon_btn_w + row_spacing);
|
||||
ui_draw_icon_link(icon_x, icon_y, icon_size, icons[i], urls[i]);
|
||||
}
|
||||
*y += settings_link_icons_height(content_w) - flint_px(8);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_version_centered(int x, int w, int *y)
|
||||
{
|
||||
char version_text[32];
|
||||
int font = flint_ui_font_small();
|
||||
int text_w;
|
||||
|
||||
snprintf(version_text, sizeof(version_text), "v%s", INBE_VERSION_STRING);
|
||||
text_w = flint_text_measure(version_text, font);
|
||||
flint_text_draw(version_text, x + (w - text_w) / 2, *y, font,
|
||||
flint_darken(theme_get_text(), 40));
|
||||
*y += flint_px(22);
|
||||
}
|
||||
|
||||
void
|
||||
settings_data_draw(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
int data_button_h = flint_px(36);
|
||||
InbeSyncAccount account;
|
||||
int has_account;
|
||||
int hover_account = 0;
|
||||
int hover_import = 0;
|
||||
int hover_export = 0;
|
||||
int hover_delete = 0;
|
||||
|
||||
settings_sync_account_set_save_dialog(settings_start_sync_key_export_dialog);
|
||||
if(app != NULL && app->settings_data_view == SETTINGS_DATA_VIEW_SYNC_ACCOUNT) {
|
||||
settings_sync_account_draw_config(app, x, w, y);
|
||||
return;
|
||||
}
|
||||
|
||||
has_account = inbe_sync_account_load(&account);
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
has_account ? locale_get("sync_configure_account_button")
|
||||
: locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_account)) {
|
||||
if(has_account) {
|
||||
settings_open_sync_account_config(app);
|
||||
} else if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("import_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_import))
|
||||
settings_import_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("export_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_export))
|
||||
settings_export_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("delete_all_data_button"),
|
||||
UI_BUTTON_STYLE_DANGER, 0, &hover_delete))
|
||||
settings_request_delete_all_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
settings_screen_draw_status_reserved(x, y, flint_px(42));
|
||||
settings_draw_link_icons(app, x, w, y);
|
||||
*y += flint_px(8);
|
||||
settings_draw_version_centered(x, w, y);
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
void
|
||||
settings_data_handle_android_import(InbeApp *app)
|
||||
{
|
||||
char import_path[FS_PATH_MAX];
|
||||
int import_result = android_import_poll_result(import_path, sizeof(import_path));
|
||||
|
||||
if(import_result == ANDROID_IMPORT_RESULT_NONE)
|
||||
return;
|
||||
if(import_result == ANDROID_IMPORT_RESULT_CANCELLED) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
settings_begin_import_for_path(app, import_path);
|
||||
}
|
||||
#else
|
||||
void settings_data_handle_android_import(InbeApp *app) { (void)app; }
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#define SETTINGS_WEB_IMPORT_PATH "/tmp/inbe-web-import.zip"
|
||||
|
||||
static void
|
||||
settings_web_import_open_picker(void)
|
||||
{
|
||||
EM_ASM({
|
||||
const importPath = UTF8ToString($0);
|
||||
Module.__inbeImportResult = 0;
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".zip,.db,application/zip,application/x-sqlite3,application/octet-stream";
|
||||
input.style.display = "none";
|
||||
|
||||
input.onchange = async function() {
|
||||
try {
|
||||
if(!input.files || input.files.length === 0) {
|
||||
Module.__inbeImportResult = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
const file = input.files[0];
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
try {
|
||||
FS.mkdir("/tmp");
|
||||
} catch(e) {}
|
||||
FS.writeFile(importPath, bytes);
|
||||
Module.__inbeImportResult = 1;
|
||||
} catch(e) {
|
||||
console.error("Inbe web import failed:", e);
|
||||
Module.__inbeImportResult = 3;
|
||||
} finally {
|
||||
input.remove();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
}, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
|
||||
void
|
||||
settings_data_handle_web_import(InbeApp *app)
|
||||
{
|
||||
int import_result = EM_ASM_INT({
|
||||
const result = Module.__inbeImportResult || 0;
|
||||
if(result !== 0)
|
||||
Module.__inbeImportResult = 0;
|
||||
return result;
|
||||
});
|
||||
|
||||
if(import_result == 0)
|
||||
return;
|
||||
if(import_result == 2) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_result != 1) {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
return;
|
||||
}
|
||||
settings_begin_import_for_path(app, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
#else
|
||||
void settings_data_handle_web_import(InbeApp *app) { (void)app; }
|
||||
#endif
|
||||
|
||||
static void
|
||||
settings_import_data(InbeApp *app)
|
||||
{
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
if(android_import_open_picker())
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
else
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#elif defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
settings_web_import_open_picker();
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_load(&import_dlg, locale_get("import_data_dialog_title"));
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_IMPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_export_data(InbeApp *app)
|
||||
{
|
||||
char export_filename[64];
|
||||
data_default_export_filename(export_filename, sizeof(export_filename));
|
||||
|
||||
if(!data_has_any()) {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_export"));
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
(void)app;
|
||||
if(data_export(export_filename)) {
|
||||
settings_screen_set_status_success(locale_get("exported_label"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful (share sheet shown)");
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_save(&export_dlg, locale_get("export_data_dialog_title"), export_filename);
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_EXPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_request_delete_all_data(InbeApp *app)
|
||||
{
|
||||
if(data_has_any()) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmDeleteData;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
int
|
||||
settings_data_draw_pending_file_dialog(InbeApp *app)
|
||||
{
|
||||
FlintFileDialog *dlg;
|
||||
int result;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_NONE)
|
||||
return 0;
|
||||
|
||||
settings_apply_file_dialog_theme(app);
|
||||
dlg = data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT ? &import_dlg : &export_dlg;
|
||||
result = flint_file_dialog_update(dlg);
|
||||
if(result < 0)
|
||||
return 1;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT) {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&import_dlg);
|
||||
if(path != NULL && path[0] != '\0') {
|
||||
settings_begin_import_for_path(app, path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: No file selected for import");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
}
|
||||
} else if(data_file_dialog_action == SETTINGS_DATA_ACTION_EXPORT) {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&export_dlg);
|
||||
if(path != NULL && data_export(path)) {
|
||||
const char *filename = GetFileName(path);
|
||||
settings_screen_set_status_success(locale_get("exported_label"), filename);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful to %s", path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_cancelled"));
|
||||
}
|
||||
} else if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT) {
|
||||
if(result == 1) {
|
||||
InbeSyncAccount account;
|
||||
const char *path = flint_file_dialog_get_path(&export_dlg);
|
||||
if(path != NULL && path[0] != '\0' &&
|
||||
inbe_sync_account_load(&account) &&
|
||||
inbe_sync_account_export_private_key(&account, path)) {
|
||||
settings_screen_set_status_success(locale_get("sync_private_key_backup_saved"), GetFileName(path));
|
||||
TraceLog(LOG_INFO, "SYNC: Private key backup saved to %s", path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_failed"));
|
||||
TraceLog(LOG_ERROR, "SYNC: Private key backup failed");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_cancelled"));
|
||||
}
|
||||
}
|
||||
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
int settings_data_draw_pending_file_dialog(InbeApp *app) { (void)app; return 0; }
|
||||
#endif
|
||||
|
||||
int
|
||||
settings_data_draw_modals(InbeApp *app)
|
||||
{
|
||||
if(app == NULL || !app->modal.active)
|
||||
return 0;
|
||||
|
||||
if(app->modal.type == UIModalConfirmImportDataSettings) {
|
||||
int modal_result = settings_draw_import_choice_modal(app);
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
} else if(modal_result == 2 || modal_result == 3) {
|
||||
char import_path[FS_PATH_MAX];
|
||||
DataImportMode mode = modal_result == 3
|
||||
? DATA_IMPORT_DATA_AND_SETTINGS
|
||||
: DATA_IMPORT_DATA_ONLY;
|
||||
snprintf(import_path, sizeof(import_path), "%s", pending_import_path);
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_perform_import(app, import_path, mode);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(app->modal.type == UIModalConfirmDeleteData) {
|
||||
int modal_result = ui_draw_modal(locale_get("delete_all_data_title"),
|
||||
locale_get("delete_all_data_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("delete_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_screen_set_status_error(locale_get("delete_cancelled"));
|
||||
} else if(modal_result == 2) {
|
||||
long long deleted = data_delete_all();
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
if(deleted > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_add_default_set(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message),
|
||||
"deleted_sessions", deleted);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
int cleared = inbe_habits_clear_days(&app->habits);
|
||||
if(cleared > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_save(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message),
|
||||
"deleted_sessions", cleared);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(app->modal.type == UIModalSyncAccountBackup) {
|
||||
int modal_result = settings_sync_account_draw_backup_modal(app);
|
||||
if(modal_result == 1 || modal_result == 2 || modal_result == 3 || modal_result == 4) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
if(modal_result == 2)
|
||||
settings_screen_set_status_success(locale_get("sync_private_key_backup_saved"), NULL);
|
||||
else if(modal_result == 3)
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_failed"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_SETTINGS_DATA_H
|
||||
#define INBE_SETTINGS_DATA_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
int settings_data_content_height(int content_w);
|
||||
int settings_data_is_configuring(const InbeApp *app);
|
||||
void settings_data_draw(InbeApp *app, int x, int w, int *y);
|
||||
int settings_data_draw_pending_file_dialog(InbeApp *app);
|
||||
int settings_data_draw_modals(InbeApp *app);
|
||||
void settings_data_handle_android_import(InbeApp *app);
|
||||
void settings_data_handle_web_import(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "settings_device.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_settings.h"
|
||||
#include "device_preferences.h"
|
||||
#include "language_screen.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
static int
|
||||
settings_device_orientation_option_count(void)
|
||||
{
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
return 4;
|
||||
#else
|
||||
return 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
settings_device_content_height(void)
|
||||
{
|
||||
int height = flint_px(74) + flint_px(74) + flint_px(76) + flint_px(40);
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
height += flint_px(76);
|
||||
#endif
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
height += flint_px(50);
|
||||
#endif
|
||||
height += flint_px(72);
|
||||
return height;
|
||||
}
|
||||
|
||||
void
|
||||
settings_device_draw(InbeApp *app, int x, int w, int *y, SettingsDeviceState *state)
|
||||
{
|
||||
int sound_volume;
|
||||
int keyboard_toggle;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
const char *orientation_options[] = {
|
||||
locale_get("orientation_system"),
|
||||
locale_get("orientation_portrait"),
|
||||
locale_get("orientation_landscape"),
|
||||
locale_get("orientation_sensor")
|
||||
};
|
||||
int orientation_option_count = settings_device_orientation_option_count();
|
||||
|
||||
if(app == NULL || y == NULL || state == NULL)
|
||||
return;
|
||||
|
||||
sound_volume = app->sound_volume;
|
||||
keyboard_toggle = app->on_screen_keyboard_enabled;
|
||||
|
||||
if(language_dropdown_button(app, 101, x, *y, w, flint_px(36), &app->language_index))
|
||||
state->language_menu_changed = 1;
|
||||
state->draw_language_menu = 1;
|
||||
*y += flint_px(74);
|
||||
|
||||
if(ui_draw_slider(6, x, *y, w, locale_get("volume_label"),
|
||||
SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX, &sound_volume, "")) {
|
||||
app->sound_volume = sound_volume;
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
*y += flint_px(74);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
{
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
flint_text_draw(locale_get("play_in_background_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&play_in_background, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.play_in_background = play_in_background;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(76);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode,
|
||||
APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
flint_text_draw(locale_get("orientation_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(103, x, *y + flint_px(26), w, flint_px(36),
|
||||
orientation_options, orientation_option_count,
|
||||
&app->orientation_mode);
|
||||
state->draw_orientation_menu = 1;
|
||||
*y += flint_px(76);
|
||||
}
|
||||
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
if(ui_draw_checkbox_toggle(x, *y, locale_get("fullscreen_label"), &app->fullscreen_enabled)) {
|
||||
if(app->fullscreen_enabled && !IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
else if(!app->fullscreen_enabled && IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(50);
|
||||
#endif
|
||||
|
||||
flint_text_draw(locale_get("on_screen_keyboard_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&keyboard_toggle, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->on_screen_keyboard_enabled = keyboard_toggle;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(76);
|
||||
}
|
||||
|
||||
void
|
||||
settings_device_handle_overlays(InbeApp *app, SettingsDeviceState *state)
|
||||
{
|
||||
int orientation_option_count = settings_device_orientation_option_count();
|
||||
|
||||
if(app == NULL || state == NULL)
|
||||
return;
|
||||
if(state->draw_language_menu && language_dropdown_menu(app, 101))
|
||||
state->language_menu_changed = 1;
|
||||
if(state->draw_orientation_menu && ui_draw_dropdown_menu(103))
|
||||
state->orientation_changed = 1;
|
||||
if(state->language_menu_changed)
|
||||
apply_language_selection(app, app->language_index, 1);
|
||||
if(state->orientation_changed) {
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode, APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
app_apply_orientation_preference(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef INBE_SETTINGS_DEVICE_H
|
||||
#define INBE_SETTINGS_DEVICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef struct SettingsDeviceState {
|
||||
int draw_language_menu;
|
||||
int language_menu_changed;
|
||||
int draw_orientation_menu;
|
||||
int orientation_changed;
|
||||
} SettingsDeviceState;
|
||||
|
||||
int settings_device_content_height(void);
|
||||
void settings_device_draw(InbeApp *app, int x, int w, int *y, SettingsDeviceState *state);
|
||||
void settings_device_handle_overlays(InbeApp *app, SettingsDeviceState *state);
|
||||
|
||||
#endif
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
/* Draw the settings screen. Returns non-zero when it consumed the whole frame. */
|
||||
int settings_screen_draw(InbeApp *app);
|
||||
void practice_config_screen_draw(InbeApp *app);
|
||||
void settings_screen_clear_status(void);
|
||||
void settings_screen_set_status_success(const char *message, const char *detail);
|
||||
void settings_screen_set_status_error(const char *message);
|
||||
void settings_screen_draw_status_reserved(int x, int *y, int reserved_h);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,382 @@
|
||||
#include "settings_sync_account.h"
|
||||
|
||||
#include "settings_screen.h"
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "sync_client.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_SERVER_URL_DEFAULT "https://api.waozi.xyz"
|
||||
#define INBE_SYNC_ENABLED_KEY "sync_enabled"
|
||||
#define INBE_SYNC_CONNECTED_URL_KEY "sync_connected_url"
|
||||
|
||||
static SettingsSyncKeySaveDialog save_dialog_callback = NULL;
|
||||
|
||||
void
|
||||
settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback)
|
||||
{
|
||||
save_dialog_callback = callback;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_hex_groups(const char *text, int x, int *y, int font, Color color,
|
||||
int groups, int group_chars)
|
||||
{
|
||||
char line[128];
|
||||
int offset = 0;
|
||||
|
||||
if(text == NULL || y == NULL)
|
||||
return;
|
||||
for(int i = 0; i < groups && text[offset] != '\0'; i++) {
|
||||
int len = group_chars;
|
||||
if((int)strlen(text + offset) < len)
|
||||
len = (int)strlen(text + offset);
|
||||
snprintf(line, sizeof(line), "%.*s", len, text + offset);
|
||||
flint_text_draw(line, x, *y, font, color);
|
||||
*y += flint_px(17);
|
||||
offset += len;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_backup_filename(char *out, size_t out_size)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
snprintf(out, out_size, "inbe-sync.key");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_start_sync_key_export(InbeApp *app, const InbeSyncAccount *account)
|
||||
{
|
||||
char filename[64];
|
||||
|
||||
settings_backup_filename(filename, sizeof(filename));
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID) || defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
return inbe_sync_account_export_private_key(account, filename) ? 2 : 3;
|
||||
#else
|
||||
if(save_dialog_callback != NULL)
|
||||
return save_dialog_callback(app, filename);
|
||||
return inbe_sync_account_export_private_key(account, filename) ? 2 : 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_url_filter(int codepoint, void *user_data)
|
||||
{
|
||||
(void)user_data;
|
||||
return codepoint >= 33 && codepoint <= 126 && !isspace(codepoint);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_server_normalize(InbeApp *app, char *out, size_t out_size)
|
||||
{
|
||||
if(app == NULL || out == NULL || out_size == 0)
|
||||
return 0;
|
||||
if(!inbe_sync_client_normalize_url(app->sync_server_url, out, out_size))
|
||||
return 0;
|
||||
snprintf(app->sync_server_url, sizeof(app->sync_server_url), "%s", out);
|
||||
app->sync_server_url_cursor = (int)strlen(app->sync_server_url);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_server_save(InbeApp *app)
|
||||
{
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
const char *connected_url;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!settings_sync_server_normalize(app, url, sizeof(url))) {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
return;
|
||||
}
|
||||
inbe_storage_set_setting_text(INBE_SYNC_SERVER_URL_KEY, url);
|
||||
connected_url = inbe_storage_get_setting_text(INBE_SYNC_CONNECTED_URL_KEY);
|
||||
if(connected_url == NULL || strcmp(connected_url, url) != 0)
|
||||
inbe_storage_set_setting_int(INBE_SYNC_ENABLED_KEY, 0);
|
||||
settings_screen_set_status_success(locale_get("sync_server_saved"), url);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_server_connected(InbeApp *app)
|
||||
{
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
const char *connected_url;
|
||||
|
||||
if(app == NULL || inbe_storage_get_setting_int(INBE_SYNC_ENABLED_KEY, 0) == 0)
|
||||
return 0;
|
||||
if(!inbe_sync_client_normalize_url(app->sync_server_url, url, sizeof(url)))
|
||||
return 0;
|
||||
connected_url = inbe_storage_get_setting_text(INBE_SYNC_CONNECTED_URL_KEY);
|
||||
return connected_url != NULL && strcmp(connected_url, url) == 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
settings_sync_result_key(InbeSyncClientResult result)
|
||||
{
|
||||
switch(result) {
|
||||
case INBE_SYNC_CLIENT_OK:
|
||||
return "sync_connected";
|
||||
case INBE_SYNC_CLIENT_UNAVAILABLE:
|
||||
return "sync_unavailable";
|
||||
case INBE_SYNC_CLIENT_INVALID_URL:
|
||||
return "sync_server_url_invalid";
|
||||
case INBE_SYNC_CLIENT_NO_ACCOUNT:
|
||||
return "sync_no_account";
|
||||
case INBE_SYNC_CLIENT_AUTH_FAILED:
|
||||
return "sync_auth_failed";
|
||||
case INBE_SYNC_CLIENT_PAYLOAD_FAILED:
|
||||
case INBE_SYNC_CLIENT_CHALLENGE_FAILED:
|
||||
case INBE_SYNC_CLIENT_SIGN_FAILED:
|
||||
case INBE_SYNC_CLIENT_REQUEST_FAILED:
|
||||
default:
|
||||
return "sync_failed";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_run_connect(InbeApp *app)
|
||||
{
|
||||
InbeSyncClientResult result;
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!settings_sync_server_normalize(app, url, sizeof(url))) {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
return;
|
||||
}
|
||||
inbe_storage_set_setting_text(INBE_SYNC_SERVER_URL_KEY, url);
|
||||
result = inbe_sync_client_sync(url);
|
||||
if(result == INBE_SYNC_CLIENT_OK) {
|
||||
inbe_storage_set_setting_int(INBE_SYNC_ENABLED_KEY, 1);
|
||||
inbe_storage_set_setting_text(INBE_SYNC_CONNECTED_URL_KEY, url);
|
||||
settings_screen_set_status_success(locale_get(settings_sync_result_key(result)), NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get(settings_sync_result_key(result)));
|
||||
}
|
||||
}
|
||||
|
||||
static FlintUITextInputStyle
|
||||
settings_sync_text_style(void)
|
||||
{
|
||||
return (FlintUITextInputStyle){
|
||||
.background = flint_darken(theme_get_bg(), 4),
|
||||
.border = theme_get_button(),
|
||||
.focus_border = theme_get_button_hover(),
|
||||
.text = theme_get_text(),
|
||||
.cursor = theme_get_text(),
|
||||
.radius = 0.08f,
|
||||
.padding_x = flint_px(10)
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
settings_sync_account_draw(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
int has_account = inbe_sync_account_load(&account);
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int half_w = (w - gap) / 2;
|
||||
int hover = 0;
|
||||
|
||||
flint_text_draw(locale_get("sync_account_title"), x, *y, font, theme_get_text());
|
||||
*y += flint_px(26);
|
||||
|
||||
if(!inbe_sync_account_available()) {
|
||||
flint_text_draw(locale_get("sync_liboqs_unavailable"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 35));
|
||||
*y += flint_px(32);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!has_account) {
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h, locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(18);
|
||||
return;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("sync_public_id_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
settings_draw_hex_groups(account.public_id, x, y, small_font, theme_get_text(), 2, 32);
|
||||
*y += flint_px(4);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, half_w, btn_h, locale_get("sync_copy_id_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
SetClipboardText(account.public_id);
|
||||
settings_screen_set_status_success(locale_get("sync_public_id_copied"), NULL);
|
||||
}
|
||||
if(ui_draw_generic_button(x + half_w + gap, *y, half_w, btn_h,
|
||||
locale_get("sync_backup_key_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
*y += btn_h + flint_px(16);
|
||||
}
|
||||
|
||||
void
|
||||
settings_sync_account_draw_config(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
int has_account = inbe_sync_account_load(&account);
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int half_w = (w - gap) / 2;
|
||||
int hover = 0;
|
||||
int commit = 0;
|
||||
FlintUITextInputStyle input_style = settings_sync_text_style();
|
||||
|
||||
if(!inbe_sync_account_available()) {
|
||||
flint_text_draw(locale_get("sync_liboqs_unavailable"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 35));
|
||||
*y += flint_px(32);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!has_account) {
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h, locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(18);
|
||||
return;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("sync_public_id_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
settings_draw_hex_groups(account.public_id, x, y, small_font, theme_get_text(), 2, 32);
|
||||
*y += flint_px(8);
|
||||
|
||||
flint_text_draw(locale_get("sync_remote_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
flint_ui_text_field((FlintUITextField){
|
||||
.bounds = {(float)x, (float)*y, (float)w, (float)btn_h},
|
||||
.text = app->sync_server_url,
|
||||
.text_size = sizeof(app->sync_server_url),
|
||||
.cursor_position = &app->sync_server_url_cursor,
|
||||
.focused = &app->sync_server_url_focused,
|
||||
.max_codepoints = 255,
|
||||
.font = small_font,
|
||||
.style = input_style,
|
||||
.filter = settings_sync_url_filter,
|
||||
.commit_pressed = &commit
|
||||
});
|
||||
if(commit)
|
||||
settings_sync_server_save(app);
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h,
|
||||
settings_sync_server_connected(app)
|
||||
? locale_get("sync_connected_button")
|
||||
: locale_get("sync_connect_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
settings_sync_run_connect(app);
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, half_w, btn_h, locale_get("sync_copy_id_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
SetClipboardText(account.public_id);
|
||||
settings_screen_set_status_success(locale_get("sync_public_id_copied"), NULL);
|
||||
}
|
||||
if(ui_draw_generic_button(x + half_w + gap, *y, half_w, btn_h,
|
||||
locale_get("sync_backup_key_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
settings_screen_draw_status_reserved(x, y, flint_px(42));
|
||||
(void)font;
|
||||
}
|
||||
|
||||
int
|
||||
settings_sync_account_draw_backup_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
InbeSyncAccount account;
|
||||
int font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int pad_bottom = flint_px(24);
|
||||
int text_button_gap = flint_px(40);
|
||||
int hover = 0;
|
||||
int y;
|
||||
int modal_h;
|
||||
int button_y;
|
||||
FlintUIParagraph warning;
|
||||
|
||||
memset(&account, 0, sizeof(account));
|
||||
inbe_sync_account_load(&account);
|
||||
|
||||
warning = (FlintUIParagraph){
|
||||
.text = locale_get("sync_backup_warning"),
|
||||
.width = flint_px(336) - flint_px(36),
|
||||
.font = font,
|
||||
.line_gap = flint_px(4),
|
||||
.color = theme_get_text()
|
||||
};
|
||||
modal_h = flint_px(58) +
|
||||
flint_ui_paragraph_height(warning) +
|
||||
text_button_gap +
|
||||
btn_h * 2 + gap +
|
||||
pad_bottom;
|
||||
if(modal_h < flint_px(224))
|
||||
modal_h = flint_px(224);
|
||||
|
||||
frame = ui_draw_modal_frame(flint_px(336), modal_h, locale_get("sync_backup_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
y = frame.content_y;
|
||||
warning.width = frame.content_w;
|
||||
flint_ui_paragraph_draw(warning, frame.content_x, &y);
|
||||
|
||||
button_y = y + text_button_gap;
|
||||
if(button_y + btn_h * 2 + gap + pad_bottom > frame.y + frame.h)
|
||||
button_y = frame.y + frame.h - pad_bottom - btn_h * 2 - gap;
|
||||
if(ui_draw_generic_button(frame.content_x, button_y, frame.content_w, btn_h,
|
||||
locale_get("sync_save_key_file_button"), UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return settings_start_sync_key_export(app, &account);
|
||||
if(ui_draw_generic_button(frame.content_x, button_y + btn_h + gap, frame.content_w,
|
||||
btn_h, locale_get("close_button"), UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef INBE_SETTINGS_SYNC_ACCOUNT_H
|
||||
#define INBE_SETTINGS_SYNC_ACCOUNT_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef int (*SettingsSyncKeySaveDialog)(InbeApp *app, const char *filename);
|
||||
|
||||
void settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback);
|
||||
void settings_sync_account_draw(InbeApp *app, int x, int w, int *y);
|
||||
void settings_sync_account_draw_config(InbeApp *app, int x, int w, int *y);
|
||||
int settings_sync_account_draw_backup_modal(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "settings_theme.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_settings.h"
|
||||
#include "device_preferences.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
int
|
||||
settings_theme_content_height(int content_w)
|
||||
{
|
||||
return flint_px(76) + ui_theme_picker_height(content_w) + flint_px(60);
|
||||
}
|
||||
|
||||
void
|
||||
settings_theme_draw(InbeApp *app, int x, int w, int *y, SettingsThemeState *state)
|
||||
{
|
||||
const char *theme_mode_options[] = {
|
||||
locale_get("theme_system"),
|
||||
locale_get("theme_light"),
|
||||
locale_get("theme_dark")
|
||||
};
|
||||
|
||||
if(app == NULL || y == NULL || state == NULL)
|
||||
return;
|
||||
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
flint_text_draw(locale_get("theme_mode_label"), x, *y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(102, x, *y + flint_px(26), w, flint_px(36),
|
||||
theme_mode_options, 3, &app->theme_mode);
|
||||
state->draw_theme_mode_menu = 1;
|
||||
*y += flint_px(76);
|
||||
|
||||
if(ui_draw_theme_picker(x, *y, w, locale_get("theme_label"),
|
||||
app->dark_mode, &app->theme_id)) {
|
||||
app->theme_id = clampi(app->theme_id, 0, FLINT_THEME_COUNT - 1);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
*y += ui_theme_picker_height(w) + flint_px(20);
|
||||
}
|
||||
|
||||
void
|
||||
settings_theme_handle_overlays(InbeApp *app, const SettingsThemeState *state)
|
||||
{
|
||||
int theme_mode_changed = 0;
|
||||
|
||||
if(app == NULL || state == NULL)
|
||||
return;
|
||||
if(state->draw_theme_mode_menu && ui_draw_dropdown_menu(102))
|
||||
theme_mode_changed = 1;
|
||||
if(theme_mode_changed) {
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_SETTINGS_THEME_H
|
||||
#define INBE_SETTINGS_THEME_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef struct SettingsThemeState {
|
||||
int draw_theme_mode_menu;
|
||||
} SettingsThemeState;
|
||||
|
||||
int settings_theme_content_height(int content_w);
|
||||
void settings_theme_draw(InbeApp *app, int x, int w, int *y, SettingsThemeState *state);
|
||||
void settings_theme_handle_overlays(InbeApp *app, const SettingsThemeState *state);
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "raylib.h"
|
||||
#include <sqlite3.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -35,11 +36,144 @@ typedef struct StorageState {
|
||||
char root[INBE_STORAGE_PATH_SIZE];
|
||||
char db_path[INBE_STORAGE_PATH_SIZE];
|
||||
char user_id[INBE_STORAGE_ID_SIZE];
|
||||
char text_value[256];
|
||||
char text_value[8192];
|
||||
} StorageState;
|
||||
|
||||
static StorageState g_storage;
|
||||
|
||||
typedef struct JsonBuilder {
|
||||
char *data;
|
||||
size_t len;
|
||||
size_t cap;
|
||||
int ok;
|
||||
} JsonBuilder;
|
||||
|
||||
static int
|
||||
json_reserve(JsonBuilder *json, size_t extra)
|
||||
{
|
||||
char *next;
|
||||
size_t next_cap;
|
||||
|
||||
if(json == NULL || !json->ok)
|
||||
return 0;
|
||||
if(extra <= json->cap - json->len)
|
||||
return 1;
|
||||
next_cap = json->cap > 0 ? json->cap : 1024;
|
||||
while(extra > next_cap - json->len)
|
||||
next_cap *= 2;
|
||||
next = (char *)realloc(json->data, next_cap);
|
||||
if(next == NULL) {
|
||||
json->ok = 0;
|
||||
return 0;
|
||||
}
|
||||
json->data = next;
|
||||
json->cap = next_cap;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_len(JsonBuilder *json, const char *text, size_t len)
|
||||
{
|
||||
if(text == NULL || len == 0)
|
||||
return;
|
||||
if(!json_reserve(json, len + 1))
|
||||
return;
|
||||
memcpy(json->data + json->len, text, len);
|
||||
json->len += len;
|
||||
json->data[json->len] = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
json_append(JsonBuilder *json, const char *text)
|
||||
{
|
||||
if(text != NULL)
|
||||
json_append_len(json, text, strlen(text));
|
||||
}
|
||||
|
||||
static void
|
||||
json_appendf(JsonBuilder *json, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list copy;
|
||||
int needed;
|
||||
|
||||
if(json == NULL || fmt == NULL || !json->ok)
|
||||
return;
|
||||
va_start(args, fmt);
|
||||
va_copy(copy, args);
|
||||
needed = vsnprintf(NULL, 0, fmt, copy);
|
||||
va_end(copy);
|
||||
if(needed < 0) {
|
||||
json->ok = 0;
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
if(json_reserve(json, (size_t)needed + 1)) {
|
||||
vsnprintf(json->data + json->len, json->cap - json->len, fmt, args);
|
||||
json->len += (size_t)needed;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_string(JsonBuilder *json, const char *text)
|
||||
{
|
||||
const unsigned char *p = (const unsigned char *)(text != NULL ? text : "");
|
||||
|
||||
json_append(json, "\"");
|
||||
while(*p != '\0') {
|
||||
char escaped[8];
|
||||
if(*p == '"' || *p == '\\') {
|
||||
escaped[0] = '\\';
|
||||
escaped[1] = (char)*p;
|
||||
json_append_len(json, escaped, 2);
|
||||
} else if(*p == '\b') {
|
||||
json_append(json, "\\b");
|
||||
} else if(*p == '\f') {
|
||||
json_append(json, "\\f");
|
||||
} else if(*p == '\n') {
|
||||
json_append(json, "\\n");
|
||||
} else if(*p == '\r') {
|
||||
json_append(json, "\\r");
|
||||
} else if(*p == '\t') {
|
||||
json_append(json, "\\t");
|
||||
} else if(*p < 0x20) {
|
||||
snprintf(escaped, sizeof(escaped), "\\u%04x", *p);
|
||||
json_append(json, escaped);
|
||||
} else {
|
||||
json_append_len(json, (const char *)p, 1);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
json_append(json, "\"");
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_key_string(JsonBuilder *json, const char *key, const char *value)
|
||||
{
|
||||
json_append_string(json, key);
|
||||
json_append(json, ":");
|
||||
json_append_string(json, value);
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_epoch(JsonBuilder *json, long long seconds)
|
||||
{
|
||||
char formatted[32];
|
||||
struct tm tm_value;
|
||||
time_t value = (time_t)seconds;
|
||||
|
||||
if(seconds <= 0)
|
||||
value = time(NULL);
|
||||
#if defined(_WIN32)
|
||||
gmtime_s(&tm_value, &value);
|
||||
#else
|
||||
gmtime_r(&value, &tm_value);
|
||||
#endif
|
||||
strftime(formatted, sizeof(formatted), "%Y-%m-%dT%H:%M:%SZ", &tm_value);
|
||||
json_append_string(json, formatted);
|
||||
}
|
||||
|
||||
static void
|
||||
storage_schedule_persist(void)
|
||||
{
|
||||
@@ -150,29 +284,37 @@ table_has_column(const char *table, const char *column)
|
||||
static int
|
||||
migrate_schema(void)
|
||||
{
|
||||
if(!table_has_column("habits", "sync_topic"))
|
||||
return 1;
|
||||
|
||||
return exec_sql(
|
||||
"BEGIN IMMEDIATE;"
|
||||
"ALTER TABLE habits RENAME TO habits_with_sync_topic;"
|
||||
"CREATE TABLE habits("
|
||||
" id TEXT PRIMARY KEY,"
|
||||
" user_id TEXT NOT NULL,"
|
||||
" name TEXT NOT NULL,"
|
||||
" color_r INTEGER NOT NULL,"
|
||||
" color_g INTEGER NOT NULL,"
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at)"
|
||||
" SELECT id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at"
|
||||
" FROM habits_with_sync_topic;"
|
||||
"DROP TABLE habits_with_sync_topic;"
|
||||
"COMMIT;");
|
||||
if(table_has_column("habits", "sync_topic")) {
|
||||
if(!exec_sql(
|
||||
"BEGIN IMMEDIATE;"
|
||||
"ALTER TABLE habits RENAME TO habits_with_sync_topic;"
|
||||
"CREATE TABLE habits("
|
||||
" id TEXT PRIMARY KEY,"
|
||||
" user_id TEXT NOT NULL,"
|
||||
" name TEXT NOT NULL,"
|
||||
" color_r INTEGER NOT NULL,"
|
||||
" color_g INTEGER NOT NULL,"
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at)"
|
||||
" SELECT id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at"
|
||||
" FROM habits_with_sync_topic;"
|
||||
"DROP TABLE habits_with_sync_topic;"
|
||||
"COMMIT;"))
|
||||
return 0;
|
||||
}
|
||||
if(!table_has_column("habits", "counter_enabled") &&
|
||||
!exec_sql("ALTER TABLE habits ADD COLUMN counter_enabled INTEGER NOT NULL DEFAULT 0"))
|
||||
return 0;
|
||||
if(!table_has_column("habit_days", "count") &&
|
||||
!exec_sql("ALTER TABLE habit_days ADD COLUMN count INTEGER NOT NULL DEFAULT 0;"
|
||||
"UPDATE habit_days SET count=CASE WHEN completed!=0 THEN 1 ELSE 0 END WHERE count=0"))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -472,6 +614,7 @@ schema_create(void)
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" counter_enabled INTEGER NOT NULL DEFAULT 0,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
@@ -479,6 +622,7 @@ schema_create(void)
|
||||
" habit_id TEXT NOT NULL,"
|
||||
" local_date INTEGER NOT NULL,"
|
||||
" completed INTEGER NOT NULL,"
|
||||
" count INTEGER NOT NULL DEFAULT 0,"
|
||||
" updated_at INTEGER NOT NULL,"
|
||||
" PRIMARY KEY(habit_id,local_date)"
|
||||
");"
|
||||
@@ -892,6 +1036,224 @@ inbe_storage_delete_session(const char *path_or_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_preferences_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"preferences\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT key,value,updated_at FROM settings "
|
||||
"WHERE user_id=?1 AND key NOT LIKE 'sync_%' ORDER BY key",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *key = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *value = (const char *)sqlite3_column_text(stmt, 1);
|
||||
long long updated_at = sqlite3_column_int64(stmt, 2);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "key", key);
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "value", value);
|
||||
json_append(json, ",\"updated_at\":");
|
||||
json_append_epoch(json, updated_at);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_habits_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
long long exported_at = now_seconds();
|
||||
|
||||
json_append(json, "\"habits\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at "
|
||||
"FROM habits WHERE user_id=?1 ORDER BY sort_order,id",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "id", (const char *)sqlite3_column_text(stmt, 0));
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "name", (const char *)sqlite3_column_text(stmt, 1));
|
||||
json_appendf(json, ",\"color_r\":%d,\"color_g\":%d,\"color_b\":%d",
|
||||
sqlite3_column_int(stmt, 2),
|
||||
sqlite3_column_int(stmt, 3),
|
||||
sqlite3_column_int(stmt, 4));
|
||||
json_appendf(json, ",\"sync_mode\":%d,\"sync_activity\":%d,\"counter_enabled\":%d,\"sort_order\":%d,\"deleted_at\":%lld",
|
||||
sqlite3_column_int(stmt, 5),
|
||||
sqlite3_column_int(stmt, 6),
|
||||
(sqlite3_column_int(stmt, 7) != 0 ||
|
||||
sqlite3_column_int(stmt, 6) != 0) ? 1 : 0,
|
||||
sqlite3_column_int(stmt, 8),
|
||||
sqlite3_column_int64(stmt, 9));
|
||||
json_append(json, ",\"updated_at\":");
|
||||
json_append_epoch(json, exported_at);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_habit_days_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"habit_days\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT hd.habit_id,hd.local_date,hd.completed,hd.count,hd.updated_at "
|
||||
"FROM habit_days hd JOIN habits h ON h.id=hd.habit_id "
|
||||
"WHERE h.user_id=?1 ORDER BY hd.habit_id,hd.local_date",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "habit_id", (const char *)sqlite3_column_text(stmt, 0));
|
||||
json_appendf(json, ",\"local_date\":%d,\"completed\":%s,\"count\":%d,\"updated_at\":",
|
||||
sqlite3_column_int(stmt, 1),
|
||||
sqlite3_column_int(stmt, 2) != 0 ? "true" : "false",
|
||||
sqlite3_column_int(stmt, 3));
|
||||
json_append_epoch(json, sqlite3_column_int64(stmt, 4));
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_session_rounds_json(JsonBuilder *json, const char *session_id)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"rounds\":[");
|
||||
if(g_storage.db != NULL && session_id != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT round_index,seconds FROM session_rounds "
|
||||
"WHERE session_id=?1 ORDER BY round_index",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, session_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int seconds = sqlite3_column_int(stmt, 1);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_appendf(json, "{\"round_index\":%d,\"breaths\":0,\"hold_seconds\":%d}",
|
||||
sqlite3_column_int(stmt, 0), seconds);
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_sessions_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"sessions\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,started_at,local_date,topic,activity,source,rounds_hash,deleted_at,imported_at "
|
||||
"FROM sessions WHERE user_id=?1 ORDER BY started_at,id",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
long long started_at = sqlite3_column_int64(stmt, 1);
|
||||
long long imported_at = sqlite3_column_int64(stmt, 8);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "id", id);
|
||||
json_append(json, ",\"started_at\":");
|
||||
json_append_epoch(json, started_at);
|
||||
json_appendf(json, ",\"local_date\":%d,\"topic\":\"%d\",\"activity\":%d,",
|
||||
sqlite3_column_int(stmt, 2),
|
||||
sqlite3_column_int(stmt, 3),
|
||||
sqlite3_column_int(stmt, 4));
|
||||
json_append_key_string(json, "source", (const char *)sqlite3_column_text(stmt, 5));
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "rounds_hash", (const char *)sqlite3_column_text(stmt, 6));
|
||||
json_appendf(json, ",\"deleted_at\":%lld,\"updated_at\":",
|
||||
sqlite3_column_int64(stmt, 7));
|
||||
json_append_epoch(json, imported_at > started_at ? imported_at : started_at);
|
||||
json_append(json, ",");
|
||||
storage_append_session_rounds_json(json, id);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
char *
|
||||
inbe_storage_build_sync_payload_json(const char *user_id_hash, const char *public_key_hex)
|
||||
{
|
||||
JsonBuilder json = {0};
|
||||
|
||||
if(g_storage.db == NULL || user_id_hash == NULL || user_id_hash[0] == '\0')
|
||||
return NULL;
|
||||
json.ok = 1;
|
||||
json_append(&json, "{");
|
||||
json_append_key_string(&json, "user_id_hash", user_id_hash);
|
||||
if(public_key_hex != NULL && public_key_hex[0] != '\0') {
|
||||
json_append(&json, ",");
|
||||
json_append_key_string(&json, "public_key", public_key_hex);
|
||||
}
|
||||
json_append(&json, ",");
|
||||
storage_append_preferences_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_habits_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_habit_days_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_sessions_json(&json);
|
||||
json_append(&json, "}");
|
||||
|
||||
if(!json.ok || json.data == NULL) {
|
||||
free(json.data);
|
||||
return NULL;
|
||||
}
|
||||
return json.data;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_storage_free_sync_payload_json(char *payload)
|
||||
{
|
||||
free(payload);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_storage_list_session_records(InbeStorageSessionRecordCallback callback, void *user)
|
||||
{
|
||||
@@ -940,6 +1302,9 @@ inbe_storage_has_any(void)
|
||||
return 1;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
count = inbe_storage_habit_count();
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT COUNT(*) FROM habit_days", -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
@@ -980,6 +1345,7 @@ inbe_storage_delete_all_sessions(void)
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = inbe_storage_session_count();
|
||||
int habit_day_count = 0;
|
||||
int habit_count = inbe_storage_habit_count();
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
@@ -989,7 +1355,7 @@ inbe_storage_delete_all_sessions(void)
|
||||
habit_day_count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if(count <= 0 && habit_day_count <= 0)
|
||||
if(count <= 0 && habit_day_count <= 0 && habit_count <= 0)
|
||||
return 0;
|
||||
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
@@ -1006,13 +1372,17 @@ inbe_storage_delete_all_sessions(void)
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
if(!exec_sql("DELETE FROM habits")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
exec_sql("VACUUM");
|
||||
storage_schedule_persist();
|
||||
return count + habit_day_count;
|
||||
return count + habit_day_count + habit_count;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -1045,9 +1415,10 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
|
||||
if(habits == NULL || g_storage.db == NULL)
|
||||
return 0;
|
||||
inbe_habits_free(habits);
|
||||
memset(habits, 0, sizeof(*habits));
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity "
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled "
|
||||
"FROM habits WHERE deleted_at=0 ORDER BY sort_order,id LIMIT 10",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
@@ -1060,6 +1431,9 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
(unsigned char)sqlite3_column_int(stmt, 4), 255};
|
||||
habit->sync_mode = sqlite3_column_int(stmt, 5);
|
||||
habit->sync_activity = sqlite3_column_int(stmt, 6);
|
||||
habit->counter_enabled = sqlite3_column_int(stmt, 7) != 0 ||
|
||||
(habit->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
|
||||
habit->sync_activity != 0);
|
||||
index++;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
@@ -1067,14 +1441,22 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT local_date,completed FROM habit_days WHERE habit_id=?1 ORDER BY local_date LIMIT 366",
|
||||
"SELECT local_date,completed,count FROM habit_days WHERE habit_id=?1 ORDER BY local_date",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habits->items[i].id);
|
||||
while(habits->items[i].day_count < INBE_HABIT_MAX_DAYS && sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int d = habits->items[i].day_count++;
|
||||
if(!inbe_habit_reserve_days(&habits->items[i], habits->items[i].day_count)) {
|
||||
habits->items[i].day_count--;
|
||||
break;
|
||||
}
|
||||
habits->items[i].days[d].day_index = sqlite3_column_int(stmt, 0);
|
||||
habits->items[i].days[d].completed = sqlite3_column_int(stmt, 1) != 0;
|
||||
habits->items[i].days[d].count = sqlite3_column_int(stmt, 2);
|
||||
if(habits->items[i].days[d].count <= 0 &&
|
||||
habits->items[i].days[d].completed)
|
||||
habits->items[i].days[d].count = 1;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
@@ -1102,8 +1484,8 @@ inbe_storage_habits_save(const void *habits_ptr)
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
const InbeHabit *habit = &habits->items[i];
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,0)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habit->id);
|
||||
@@ -1114,19 +1496,24 @@ inbe_storage_habits_save(const void *habits_ptr)
|
||||
sqlite3_bind_int(stmt, 6, habit->color.b);
|
||||
sqlite3_bind_int(stmt, 7, habit->sync_mode);
|
||||
sqlite3_bind_int(stmt, 8, habit->sync_activity);
|
||||
sqlite3_bind_int(stmt, 9, i);
|
||||
sqlite3_bind_int(stmt, 9, habit->counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(stmt, 10, i);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) VALUES(?1,?2,?3,?4)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) VALUES(?1,?2,?3,?4,?5)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habit->id);
|
||||
sqlite3_bind_int(stmt, 2, habit->days[d].day_index);
|
||||
sqlite3_bind_int(stmt, 3, habit->days[d].completed ? 1 : 0);
|
||||
sqlite3_bind_int64(stmt, 4, now_seconds());
|
||||
sqlite3_bind_int(stmt, 3, habit->days[d].count > 0 ||
|
||||
habit->days[d].completed ? 1 : 0);
|
||||
sqlite3_bind_int(stmt, 4, habit->days[d].count > 0
|
||||
? habit->days[d].count
|
||||
: (habit->days[d].completed ? 1 : 0));
|
||||
sqlite3_bind_int64(stmt, 5, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
@@ -1448,6 +1835,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
sqlite3_stmt *write_stmt = NULL;
|
||||
int ok = 0;
|
||||
int has_multiple_entries;
|
||||
const char *track_sql;
|
||||
long long imported_at = now_seconds();
|
||||
|
||||
if(src == NULL || g_storage.db == NULL)
|
||||
@@ -1456,9 +1845,18 @@ import_tickmate_db(sqlite3 *src)
|
||||
!source_table_has_column(src, "ticks", "_track_id"))
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT _id,name,color,\"order\" FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
has_multiple_entries = source_table_has_column(src, "tracks", "multiple_entries_per_day");
|
||||
track_sql = has_multiple_entries
|
||||
? "SELECT _id,name,color,\"order\",multiple_entries_per_day,"
|
||||
"EXISTS(SELECT 1 FROM ticks WHERE ticks._track_id=tracks._id "
|
||||
"GROUP BY year,month,day HAVING COUNT(*)>1 LIMIT 1) "
|
||||
"FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id"
|
||||
: "SELECT _id,name,color,\"order\",0,"
|
||||
"EXISTS(SELECT 1 FROM ticks WHERE ticks._track_id=tracks._id "
|
||||
"GROUP BY year,month,day HAVING COUNT(*)>1 LIMIT 1) "
|
||||
"FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id";
|
||||
|
||||
if(sqlite3_prepare_v2(src, track_sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
@@ -1468,6 +1866,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
const char *name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
int track_id = sqlite3_column_int(stmt, 0);
|
||||
int sort_order = sqlite3_column_int(stmt, 3);
|
||||
int counter_enabled = sqlite3_column_int(stmt, 4) != 0 ||
|
||||
sqlite3_column_int(stmt, 5) != 0;
|
||||
Color color = tickmate_color_from_int(sqlite3_column_int(stmt, 2), track_id);
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
@@ -1477,8 +1877,9 @@ import_tickmate_db(sqlite3 *src)
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,"
|
||||
"CASE WHEN ?9!=0 THEN 1 ELSE COALESCE((SELECT counter_enabled FROM habits WHERE id=?1),0) END,?10,0)",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, local_habit_id);
|
||||
@@ -1489,7 +1890,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
sqlite3_bind_int(write_stmt, 6, color.b);
|
||||
sqlite3_bind_int(write_stmt, 7, INBE_HABIT_SYNC_NONE);
|
||||
sqlite3_bind_int(write_stmt, 8, 0);
|
||||
sqlite3_bind_int(write_stmt, 9, sort_order);
|
||||
sqlite3_bind_int(write_stmt, 9, counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(write_stmt, 10, sort_order);
|
||||
if(sqlite3_step(write_stmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(write_stmt);
|
||||
@@ -1499,9 +1901,23 @@ import_tickmate_db(sqlite3 *src)
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT ticks._track_id,tracks.name,ticks.year,ticks.month,ticks.day "
|
||||
"FROM ticks JOIN tracks ON tracks._id=ticks._track_id",
|
||||
"SELECT ticks._track_id,tracks.name,ticks.year,ticks.month,ticks.day,COUNT(*) "
|
||||
"FROM ticks JOIN tracks ON tracks._id=ticks._track_id "
|
||||
"WHERE tracks.enabled!=0 "
|
||||
"GROUP BY ticks._track_id,ticks.year,ticks.month,ticks.day",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) "
|
||||
"VALUES(?1,?2,1,?3,?4) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"count=CASE WHEN habit_days.count>excluded.count THEN habit_days.count ELSE excluded.count END,"
|
||||
"completed=CASE WHEN habit_days.count>0 OR excluded.count>0 OR habit_days.completed!=0 THEN 1 ELSE 0 END,"
|
||||
"updated_at=CASE WHEN excluded.count>habit_days.count THEN excluded.updated_at ELSE habit_days.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK) {
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
goto finish;
|
||||
}
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
char import_habit_id[64];
|
||||
char local_habit_id[INBE_STORAGE_ID_SIZE];
|
||||
@@ -1510,31 +1926,30 @@ import_tickmate_db(sqlite3 *src)
|
||||
int year = sqlite3_column_int(stmt, 2);
|
||||
int month = sqlite3_column_int(stmt, 3);
|
||||
int day = sqlite3_column_int(stmt, 4);
|
||||
int count = sqlite3_column_int(stmt, 5);
|
||||
int local_date;
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
continue;
|
||||
if(year <= 0 || month <= 0 || month > 12 || day <= 0 || day > 31)
|
||||
/* Tickmate stores Android Calendar.MONTH values: January is 0. */
|
||||
if(year <= 0 || month < 0 || month > 11 || day <= 0 || day > 31)
|
||||
continue;
|
||||
local_date = year * 10000 + month * 100 + day;
|
||||
local_date = year * 10000 + (month + 1) * 100 + day;
|
||||
snprintf(import_habit_id, sizeof(import_habit_id), "tickmate-%d", track_id);
|
||||
if(!resolve_import_habit_id(import_habit_id, name, local_habit_id,
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,1,?3)",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
sqlite3_reset(write_stmt);
|
||||
sqlite3_clear_bindings(write_stmt);
|
||||
bind_text(write_stmt, 1, local_habit_id);
|
||||
sqlite3_bind_int(write_stmt, 2, local_date);
|
||||
sqlite3_bind_int64(write_stmt, 3, imported_at);
|
||||
sqlite3_bind_int(write_stmt, 3, count > 0 ? count : 1);
|
||||
sqlite3_bind_int64(write_stmt, 4, imported_at);
|
||||
if(sqlite3_step(write_stmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(write_stmt);
|
||||
write_stmt = NULL;
|
||||
}
|
||||
}
|
||||
finish:
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_finalize(write_stmt);
|
||||
exec_sql("COMMIT");
|
||||
@@ -1563,7 +1978,9 @@ import_settings_from_source(sqlite3 *src)
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO settings(user_id,key,value,updated_at) VALUES(?1,?2,?3,?4) "
|
||||
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value,updated_at=excluded.updated_at",
|
||||
"ON CONFLICT(user_id,key) DO UPDATE SET "
|
||||
"value=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.value ELSE settings.value END,"
|
||||
"updated_at=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.updated_at ELSE settings.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, g_storage.user_id);
|
||||
@@ -1672,10 +2089,16 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
|
||||
if(source_table_exists(src, "habits")) {
|
||||
int has_sync_activity = source_table_has_column(src, "habits", "sync_activity");
|
||||
int has_counter_enabled = source_table_has_column(src, "habits", "counter_enabled");
|
||||
int has_day_count = source_table_has_column(src, "habit_days", "count");
|
||||
const char *habit_sql =
|
||||
has_sync_activity
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: "SELECT id,name,color_r,color_g,color_b,sync_mode,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
|
||||
has_sync_activity && has_counter_enabled
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: has_sync_activity
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,0,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: has_counter_enabled
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,0,counter_enabled,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: "SELECT id,name,color_r,color_g,color_b,sync_mode,0,0,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
|
||||
if(sqlite3_prepare_v2(src, habit_sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
goto after_habits;
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
@@ -1683,8 +2106,11 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
const char *import_habit_id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
char local_habit_id[INBE_STORAGE_ID_SIZE];
|
||||
int sync_activity = has_sync_activity ? sqlite3_column_int(stmt, 6) : 0;
|
||||
int sort_order = has_sync_activity ? sqlite3_column_int(stmt, 7) : sqlite3_column_int(stmt, 6);
|
||||
int sync_activity = sqlite3_column_int(stmt, 6);
|
||||
int counter_enabled = sqlite3_column_int(stmt, 7) != 0;
|
||||
int sort_order = sqlite3_column_int(stmt, 8);
|
||||
if(sync_activity != 0)
|
||||
counter_enabled = 1;
|
||||
|
||||
if(import_habit_id == NULL || import_habit_id[0] == '\0' ||
|
||||
name == NULL || name[0] == '\0')
|
||||
@@ -1693,8 +2119,9 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,"
|
||||
"CASE WHEN ?9!=0 THEN 1 ELSE COALESCE((SELECT counter_enabled FROM habits WHERE id=?1),0) END,?10,0)",
|
||||
-1, &hstmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(hstmt, 1, local_habit_id);
|
||||
@@ -1705,27 +2132,35 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
sqlite3_bind_int(hstmt, 6, sqlite3_column_int(stmt, 4));
|
||||
sqlite3_bind_int(hstmt, 7, sqlite3_column_int(stmt, 5));
|
||||
sqlite3_bind_int(hstmt, 8, sync_activity);
|
||||
sqlite3_bind_int(hstmt, 9, sort_order);
|
||||
sqlite3_bind_int(hstmt, 9, counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(hstmt, 10, sort_order);
|
||||
if(sqlite3_step(hstmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(hstmt);
|
||||
hstmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT local_date,completed FROM habit_days WHERE habit_id=?1",
|
||||
has_day_count
|
||||
? "SELECT local_date,completed,count FROM habit_days WHERE habit_id=?1"
|
||||
: "SELECT local_date,completed,CASE WHEN completed!=0 THEN 1 ELSE 0 END FROM habit_days WHERE habit_id=?1",
|
||||
-1, &hstmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(hstmt, 1, import_habit_id, -1, SQLITE_TRANSIENT);
|
||||
while(sqlite3_step(hstmt) == SQLITE_ROW) {
|
||||
sqlite3_stmt *day_stmt = NULL;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"count=CASE WHEN habit_days.count>excluded.count THEN habit_days.count ELSE excluded.count END,"
|
||||
"completed=CASE WHEN habit_days.count>0 OR excluded.count>0 OR habit_days.completed!=0 OR excluded.completed!=0 THEN 1 ELSE 0 END,"
|
||||
"updated_at=CASE WHEN excluded.count>habit_days.count THEN excluded.updated_at ELSE habit_days.updated_at END",
|
||||
-1, &day_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(day_stmt, 1, local_habit_id);
|
||||
sqlite3_bind_int(day_stmt, 2, sqlite3_column_int(hstmt, 0));
|
||||
sqlite3_bind_int(day_stmt, 3, sqlite3_column_int(hstmt, 1) != 0);
|
||||
sqlite3_bind_int64(day_stmt, 4, now_seconds());
|
||||
sqlite3_bind_int(day_stmt, 4, sqlite3_column_int(hstmt, 2));
|
||||
sqlite3_bind_int64(day_stmt, 5, now_seconds());
|
||||
sqlite3_step(day_stmt);
|
||||
sqlite3_finalize(day_stmt);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ int inbe_storage_session_count(void);
|
||||
int inbe_storage_habit_count(void);
|
||||
long long inbe_storage_total_size(void);
|
||||
long long inbe_storage_delete_all_sessions(void);
|
||||
char *inbe_storage_build_sync_payload_json(const char *user_id_hash,
|
||||
const char *public_key_hex);
|
||||
void inbe_storage_free_sync_payload_json(char *payload);
|
||||
|
||||
int inbe_storage_habits_empty(void);
|
||||
int inbe_storage_habits_load(void *habits);
|
||||
|
||||
@@ -0,0 +1,381 @@
|
||||
#include "sync_account.h"
|
||||
|
||||
#include "data.h"
|
||||
#include "storage.h"
|
||||
#include "raylib.h"
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_share.h"
|
||||
#endif
|
||||
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
#include <oqs/oqs.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SYNC_PUBLIC_ID_KEY "sync_public_id"
|
||||
#define SYNC_PUBLIC_KEY_KEY "sync_public_key"
|
||||
#define SYNC_PRIVATE_KEY_KEY "sync_private_key"
|
||||
|
||||
typedef struct Sha256Ctx {
|
||||
uint32_t state[8];
|
||||
uint64_t bit_len;
|
||||
uint8_t data[64];
|
||||
size_t data_len;
|
||||
} Sha256Ctx;
|
||||
|
||||
static const uint32_t sha256_k[64] = {
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U,
|
||||
0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U,
|
||||
0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, 0xe49b69c1U, 0xefbe4786U,
|
||||
0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U,
|
||||
0x06ca6351U, 0x14292967U, 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U,
|
||||
0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, 0xa2bfe8a1U, 0xa81a664bU,
|
||||
0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU,
|
||||
0x5b9cca4fU, 0x682e6ff3U, 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U,
|
||||
0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
rotr32(uint32_t value, uint32_t bits)
|
||||
{
|
||||
return (value >> bits) | (value << (32U - bits));
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_transform(Sha256Ctx *ctx, const uint8_t data[64])
|
||||
{
|
||||
uint32_t m[64];
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
|
||||
for(int i = 0; i < 16; i++) {
|
||||
m[i] = ((uint32_t)data[i * 4] << 24) |
|
||||
((uint32_t)data[i * 4 + 1] << 16) |
|
||||
((uint32_t)data[i * 4 + 2] << 8) |
|
||||
(uint32_t)data[i * 4 + 3];
|
||||
}
|
||||
for(int i = 16; i < 64; i++) {
|
||||
uint32_t s0 = rotr32(m[i - 15], 7) ^ rotr32(m[i - 15], 18) ^ (m[i - 15] >> 3);
|
||||
uint32_t s1 = rotr32(m[i - 2], 17) ^ rotr32(m[i - 2], 19) ^ (m[i - 2] >> 10);
|
||||
m[i] = m[i - 16] + s0 + m[i - 7] + s1;
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
e = ctx->state[4];
|
||||
f = ctx->state[5];
|
||||
g = ctx->state[6];
|
||||
h = ctx->state[7];
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
uint32_t s1 = rotr32(e, 6) ^ rotr32(e, 11) ^ rotr32(e, 25);
|
||||
uint32_t ch = (e & f) ^ ((~e) & g);
|
||||
uint32_t temp1 = h + s1 + ch + sha256_k[i] + m[i];
|
||||
uint32_t s0 = rotr32(a, 2) ^ rotr32(a, 13) ^ rotr32(a, 22);
|
||||
uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
uint32_t temp2 = s0 + maj;
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + temp1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = temp1 + temp2;
|
||||
}
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
ctx->state[4] += e;
|
||||
ctx->state[5] += f;
|
||||
ctx->state[6] += g;
|
||||
ctx->state[7] += h;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_init(Sha256Ctx *ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->state[0] = 0x6a09e667U;
|
||||
ctx->state[1] = 0xbb67ae85U;
|
||||
ctx->state[2] = 0x3c6ef372U;
|
||||
ctx->state[3] = 0xa54ff53aU;
|
||||
ctx->state[4] = 0x510e527fU;
|
||||
ctx->state[5] = 0x9b05688cU;
|
||||
ctx->state[6] = 0x1f83d9abU;
|
||||
ctx->state[7] = 0x5be0cd19U;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_update(Sha256Ctx *ctx, const uint8_t *data, size_t len)
|
||||
{
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
ctx->data[ctx->data_len++] = data[i];
|
||||
if(ctx->data_len == 64) {
|
||||
sha256_transform(ctx, ctx->data);
|
||||
ctx->bit_len += 512;
|
||||
ctx->data_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_final(Sha256Ctx *ctx, uint8_t hash[32])
|
||||
{
|
||||
size_t i = ctx->data_len;
|
||||
|
||||
ctx->data[i++] = 0x80;
|
||||
if(i > 56) {
|
||||
while(i < 64)
|
||||
ctx->data[i++] = 0;
|
||||
sha256_transform(ctx, ctx->data);
|
||||
i = 0;
|
||||
}
|
||||
while(i < 56)
|
||||
ctx->data[i++] = 0;
|
||||
|
||||
ctx->bit_len += ctx->data_len * 8;
|
||||
for(int j = 0; j < 8; j++)
|
||||
ctx->data[63 - j] = (uint8_t)(ctx->bit_len >> (j * 8));
|
||||
sha256_transform(ctx, ctx->data);
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
for(int j = 0; j < 8; j++)
|
||||
hash[j * 4 + i] = (uint8_t)(ctx->state[j] >> (24 - i * 8));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bytes_to_hex(const uint8_t *bytes, size_t len, char *out, size_t out_size)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
size_t needed = len * 2 + 1;
|
||||
|
||||
if(out == NULL || out_size < needed)
|
||||
return;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
out[i * 2] = hex[bytes[i] >> 4];
|
||||
out[i * 2 + 1] = hex[bytes[i] & 0x0f];
|
||||
}
|
||||
out[len * 2] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
hex_to_bytes(const char *hex, uint8_t *out, size_t out_len)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(hex == NULL || out == NULL)
|
||||
return 0;
|
||||
len = strlen(hex);
|
||||
if(len != out_len * 2)
|
||||
return 0;
|
||||
for(size_t i = 0; i < out_len; i++) {
|
||||
unsigned int value;
|
||||
if(sscanf(hex + i * 2, "%2x", &value) != 1)
|
||||
return 0;
|
||||
out[i] = (uint8_t)value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_sync_sha256_hex(const uint8_t *data, size_t len, char out_hex[65])
|
||||
{
|
||||
uint8_t digest[32];
|
||||
Sha256Ctx sha;
|
||||
|
||||
if(out_hex == NULL)
|
||||
return;
|
||||
out_hex[0] = '\0';
|
||||
if(data == NULL && len > 0)
|
||||
return;
|
||||
sha256_init(&sha);
|
||||
sha256_update(&sha, data, len);
|
||||
sha256_final(&sha, digest);
|
||||
bytes_to_hex(digest, sizeof(digest), out_hex, 65);
|
||||
}
|
||||
|
||||
static int
|
||||
account_has_values(const InbeSyncAccount *account)
|
||||
{
|
||||
return account != NULL &&
|
||||
account->public_id[0] != '\0' &&
|
||||
account->public_key_hex[0] != '\0' &&
|
||||
account->private_key_hex[0] != '\0';
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_available(void)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_load(InbeSyncAccount *account)
|
||||
{
|
||||
const char *public_id;
|
||||
const char *public_key;
|
||||
const char *private_key;
|
||||
|
||||
data_init();
|
||||
if(account == NULL)
|
||||
return 0;
|
||||
memset(account, 0, sizeof(*account));
|
||||
|
||||
public_id = inbe_storage_get_setting_text(SYNC_PUBLIC_ID_KEY);
|
||||
if(public_id != NULL)
|
||||
snprintf(account->public_id, sizeof(account->public_id), "%s", public_id);
|
||||
public_key = inbe_storage_get_setting_text(SYNC_PUBLIC_KEY_KEY);
|
||||
if(public_key != NULL)
|
||||
snprintf(account->public_key_hex, sizeof(account->public_key_hex), "%s", public_key);
|
||||
private_key = inbe_storage_get_setting_text(SYNC_PRIVATE_KEY_KEY);
|
||||
if(private_key != NULL)
|
||||
snprintf(account->private_key_hex, sizeof(account->private_key_hex), "%s", private_key);
|
||||
return account_has_values(account);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_create(InbeSyncAccount *account)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
OQS_SIG *sig;
|
||||
uint8_t public_key[1312];
|
||||
uint8_t private_key[2560];
|
||||
uint8_t digest[32];
|
||||
Sha256Ctx sha;
|
||||
InbeSyncAccount generated;
|
||||
|
||||
data_init();
|
||||
if(account == NULL)
|
||||
return 0;
|
||||
memset(&generated, 0, sizeof(generated));
|
||||
|
||||
sig = OQS_SIG_new(OQS_SIG_alg_ml_dsa_44);
|
||||
if(sig == NULL ||
|
||||
sig->length_public_key != sizeof(public_key) ||
|
||||
sig->length_secret_key != sizeof(private_key)) {
|
||||
if(sig != NULL)
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
if(OQS_SIG_keypair(sig, public_key, private_key) != OQS_SUCCESS) {
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
OQS_SIG_free(sig);
|
||||
|
||||
sha256_init(&sha);
|
||||
sha256_update(&sha, public_key, sizeof(public_key));
|
||||
sha256_final(&sha, digest);
|
||||
|
||||
bytes_to_hex(digest, sizeof(digest), generated.public_id, sizeof(generated.public_id));
|
||||
bytes_to_hex(public_key, sizeof(public_key), generated.public_key_hex,
|
||||
sizeof(generated.public_key_hex));
|
||||
bytes_to_hex(private_key, sizeof(private_key), generated.private_key_hex,
|
||||
sizeof(generated.private_key_hex));
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
inbe_storage_set_setting_text(SYNC_PUBLIC_ID_KEY, generated.public_id);
|
||||
inbe_storage_set_setting_text(SYNC_PUBLIC_KEY_KEY, generated.public_key_hex);
|
||||
inbe_storage_set_setting_text(SYNC_PRIVATE_KEY_KEY, generated.private_key_hex);
|
||||
inbe_storage_settings_end_write();
|
||||
|
||||
*account = generated;
|
||||
return 1;
|
||||
#else
|
||||
(void)account;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_export_private_key(const InbeSyncAccount *account, const char *filename)
|
||||
{
|
||||
char body[5400];
|
||||
int len;
|
||||
|
||||
if(!account_has_values(account) || filename == NULL || filename[0] == '\0')
|
||||
return 0;
|
||||
|
||||
len = snprintf(body, sizeof(body),
|
||||
"inbe-sync-key-v1\nalgorithm=ML-DSA-44\npublic_id=%s\nprivate_key=%s\n",
|
||||
account->public_id, account->private_key_hex);
|
||||
if(len <= 0 || (size_t)len >= sizeof(body))
|
||||
return 0;
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
return android_share_bytes((const unsigned char *)body, (size_t)len, filename,
|
||||
"application/octet-stream");
|
||||
#else
|
||||
if(strchr(filename, '/') != NULL || strchr(filename, '\\') != NULL)
|
||||
return SaveFileData(filename, body, len);
|
||||
{
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/%s", data_root(), filename);
|
||||
return SaveFileData(path, body, len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_sign_hex(const uint8_t *message, size_t message_len,
|
||||
char *out_signature_hex, size_t out_size)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
InbeSyncAccount account;
|
||||
OQS_SIG *sig;
|
||||
uint8_t private_key[2560];
|
||||
uint8_t signature[2420];
|
||||
size_t signature_len = 0;
|
||||
|
||||
if(out_signature_hex == NULL || out_size < sizeof(signature) * 2 + 1 ||
|
||||
(message == NULL && message_len > 0))
|
||||
return 0;
|
||||
out_signature_hex[0] = '\0';
|
||||
if(!inbe_sync_account_load(&account))
|
||||
return 0;
|
||||
if(!hex_to_bytes(account.private_key_hex, private_key, sizeof(private_key)))
|
||||
return 0;
|
||||
|
||||
sig = OQS_SIG_new(OQS_SIG_alg_ml_dsa_44);
|
||||
if(sig == NULL ||
|
||||
sig->length_secret_key != sizeof(private_key) ||
|
||||
sig->length_signature != sizeof(signature)) {
|
||||
if(sig != NULL)
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(OQS_SIG_sign(sig, signature, &signature_len, message, message_len,
|
||||
private_key) != OQS_SUCCESS ||
|
||||
signature_len != sizeof(signature)) {
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
OQS_SIG_free(sig);
|
||||
|
||||
bytes_to_hex(signature, sizeof(signature), out_signature_hex, out_size);
|
||||
return out_signature_hex[0] != '\0';
|
||||
#else
|
||||
(void)message;
|
||||
(void)message_len;
|
||||
(void)out_signature_hex;
|
||||
(void)out_size;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef INBE_SYNC_ACCOUNT_H
|
||||
#define INBE_SYNC_ACCOUNT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
INBE_SYNC_PUBLIC_ID_HEX_SIZE = 65,
|
||||
INBE_SYNC_PUBLIC_KEY_HEX_SIZE = 2625,
|
||||
INBE_SYNC_PRIVATE_KEY_HEX_SIZE = 5121
|
||||
};
|
||||
|
||||
typedef struct InbeSyncAccount {
|
||||
char public_id[INBE_SYNC_PUBLIC_ID_HEX_SIZE];
|
||||
char public_key_hex[INBE_SYNC_PUBLIC_KEY_HEX_SIZE];
|
||||
char private_key_hex[INBE_SYNC_PRIVATE_KEY_HEX_SIZE];
|
||||
} InbeSyncAccount;
|
||||
|
||||
int inbe_sync_account_available(void);
|
||||
int inbe_sync_account_load(InbeSyncAccount *account);
|
||||
int inbe_sync_account_create(InbeSyncAccount *account);
|
||||
int inbe_sync_account_export_private_key(const InbeSyncAccount *account, const char *filename);
|
||||
void inbe_sync_sha256_hex(const uint8_t *data, size_t len, char out_hex[65]);
|
||||
int inbe_sync_account_sign_hex(const uint8_t *message, size_t message_len,
|
||||
char *out_signature_hex, size_t out_size);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,470 @@
|
||||
#include "sync_client.h"
|
||||
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#define INBE_SYNC_CLIENT_HAS_ANDROID 1
|
||||
#include <android_native_app_glue.h>
|
||||
#include <jni.h>
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
#elif defined(FLINT_HAS_LIBCURL) && !defined(__EMSCRIPTEN__)
|
||||
#define INBE_SYNC_CLIENT_HAS_CURL 1
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_CURL) || defined(INBE_SYNC_CLIENT_HAS_ANDROID)
|
||||
#define INBE_SYNC_CLIENT_HAS_HTTP 1
|
||||
#endif
|
||||
|
||||
#define INBE_SYNC_PATH "/api/v1/sync"
|
||||
#define INBE_CHALLENGE_PATH "/api/v1/sync/challenge"
|
||||
|
||||
typedef struct SyncBuffer {
|
||||
char *data;
|
||||
size_t len;
|
||||
size_t cap;
|
||||
} SyncBuffer;
|
||||
|
||||
static int
|
||||
sync_has_prefix(const char *text, const char *prefix)
|
||||
{
|
||||
return text != NULL && prefix != NULL &&
|
||||
strncmp(text, prefix, strlen(prefix)) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_url_host_boundary(char ch)
|
||||
{
|
||||
return ch == '\0' || ch == ':' || ch == '/' || ch == '?' || ch == '#';
|
||||
}
|
||||
|
||||
static int
|
||||
sync_loopback_authority_valid(const char *authority)
|
||||
{
|
||||
static const char *const hosts[] = {
|
||||
"localhost",
|
||||
"127.0.0.1",
|
||||
"10.0.2.2"
|
||||
};
|
||||
|
||||
if(authority == NULL || authority[0] == '\0')
|
||||
return 0;
|
||||
for(size_t i = 0; i < sizeof(hosts) / sizeof(hosts[0]); i++) {
|
||||
size_t len = strlen(hosts[i]);
|
||||
if(strncmp(authority, hosts[i], len) == 0 &&
|
||||
sync_url_host_boundary(authority[len]))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_client_url_valid(const char *url)
|
||||
{
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return 0;
|
||||
if(sync_has_prefix(url, "https://"))
|
||||
return url[8] != '\0';
|
||||
if(sync_has_prefix(url, "http://"))
|
||||
return sync_loopback_authority_valid(url + 7);
|
||||
return sync_loopback_authority_valid(url);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_client_normalize_url(const char *input, char *out, size_t out_size)
|
||||
{
|
||||
int len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
if(!inbe_sync_client_url_valid(input))
|
||||
return 0;
|
||||
if(sync_has_prefix(input, "https://") || sync_has_prefix(input, "http://"))
|
||||
len = snprintf(out, out_size, "%s", input);
|
||||
else
|
||||
len = snprintf(out, out_size, "http://%s", input);
|
||||
return len > 0 && (size_t)len < out_size;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_buffer_append(SyncBuffer *buffer, const void *data, size_t bytes)
|
||||
{
|
||||
char *next;
|
||||
size_t next_cap;
|
||||
|
||||
if(buffer == NULL || data == NULL || bytes == 0)
|
||||
return 1;
|
||||
if(buffer->cap == 0 || bytes >= buffer->cap - buffer->len) {
|
||||
next_cap = buffer->cap > 0 ? buffer->cap : 1024;
|
||||
while(bytes >= next_cap - buffer->len)
|
||||
next_cap *= 2;
|
||||
next = (char *)realloc(buffer->data, next_cap);
|
||||
if(next == NULL)
|
||||
return 0;
|
||||
buffer->data = next;
|
||||
buffer->cap = next_cap;
|
||||
}
|
||||
memcpy(buffer->data + buffer->len, data, bytes);
|
||||
buffer->len += bytes;
|
||||
buffer->data[buffer->len] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_TESTS)
|
||||
int
|
||||
inbe_sync_client_test_response_buffer(const char *first, const char *second,
|
||||
char *out, size_t out_size)
|
||||
{
|
||||
SyncBuffer buffer = {0};
|
||||
int ok;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
ok = sync_buffer_append(&buffer, first, first != NULL ? strlen(first) : 0) &&
|
||||
sync_buffer_append(&buffer, second, second != NULL ? strlen(second) : 0);
|
||||
if(ok && buffer.data != NULL)
|
||||
snprintf(out, out_size, "%s", buffer.data);
|
||||
free(buffer.data);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
sync_join_url(char *out, size_t out_size, const char *base_url, const char *path)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
out[0] = '\0';
|
||||
if(base_url == NULL || path == NULL)
|
||||
return;
|
||||
len = strlen(base_url);
|
||||
while(len > 0 && base_url[len - 1] == '/')
|
||||
len--;
|
||||
snprintf(out, out_size, "%.*s%s", (int)len, base_url, path);
|
||||
}
|
||||
|
||||
static int
|
||||
sync_build_message(const char *method, const char *path, const char *nonce_hex,
|
||||
const char *body, char *out, size_t out_size)
|
||||
{
|
||||
char body_hash[65];
|
||||
int len;
|
||||
|
||||
if(method == NULL || path == NULL || nonce_hex == NULL || body == NULL ||
|
||||
out == NULL || out_size == 0)
|
||||
return 0;
|
||||
inbe_sync_sha256_hex((const uint8_t *)body, strlen(body), body_hash);
|
||||
if(body_hash[0] == '\0')
|
||||
return 0;
|
||||
len = snprintf(out, out_size, "inbe-sync-v1\n%s\n%s\n%s\n%s\n",
|
||||
method, path, body_hash, nonce_hex);
|
||||
return len > 0 && (size_t)len < out_size;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_find_json_string(const char *json, const char *key, char *out, size_t out_size)
|
||||
{
|
||||
char pattern[64];
|
||||
const char *p;
|
||||
char *w;
|
||||
size_t remaining;
|
||||
|
||||
if(json == NULL || key == NULL || out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
snprintf(pattern, sizeof(pattern), "\"%s\"", key);
|
||||
p = strstr(json, pattern);
|
||||
if(p == NULL)
|
||||
return 0;
|
||||
p += strlen(pattern);
|
||||
while(*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||
p++;
|
||||
if(*p++ != ':')
|
||||
return 0;
|
||||
while(*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||
p++;
|
||||
if(*p++ != '"')
|
||||
return 0;
|
||||
w = out;
|
||||
remaining = out_size - 1;
|
||||
while(*p != '\0' && *p != '"' && remaining > 0) {
|
||||
if(*p == '\\')
|
||||
return 0;
|
||||
*w++ = *p++;
|
||||
remaining--;
|
||||
}
|
||||
*w = '\0';
|
||||
return *p == '"' && out[0] != '\0';
|
||||
}
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_CURL)
|
||||
static size_t
|
||||
sync_write_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
SyncBuffer *buffer = (SyncBuffer *)userdata;
|
||||
size_t bytes = size * nmemb;
|
||||
|
||||
if(buffer == NULL || bytes == 0)
|
||||
return bytes;
|
||||
return sync_buffer_append(buffer, ptr, bytes) ? bytes : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_http_request(const char *method, const char *url, const char *body,
|
||||
const char *const *headers, int header_count,
|
||||
SyncBuffer *response, long *status)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
struct curl_slist *curl_headers = NULL;
|
||||
|
||||
if(status != NULL)
|
||||
*status = 0;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if(curl == NULL)
|
||||
return 0;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "inbe-sync/1");
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, sync_write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
|
||||
for(int i = 0; i < header_count; i++) {
|
||||
if(headers[i] != NULL)
|
||||
curl_headers = curl_slist_append(curl_headers, headers[i]);
|
||||
}
|
||||
if(curl_headers != NULL)
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers);
|
||||
if(strcmp(method, "POST") == 0) {
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body != NULL ? body : "");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)(body != NULL ? strlen(body) : 0));
|
||||
} else if(strcmp(method, "DELETE") == 0) {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body != NULL ? body : "");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)(body != NULL ? strlen(body) : 0));
|
||||
}
|
||||
res = curl_easy_perform(curl);
|
||||
if(status != NULL)
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status);
|
||||
curl_slist_free_all(curl_headers);
|
||||
curl_easy_cleanup(curl);
|
||||
return res == CURLE_OK;
|
||||
}
|
||||
#elif defined(INBE_SYNC_CLIENT_HAS_ANDROID)
|
||||
static int
|
||||
sync_buffer_set(SyncBuffer *response, const char *text)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(response == NULL)
|
||||
return 0;
|
||||
len = text != NULL ? strlen(text) : 0;
|
||||
response->data = (char *)malloc(len + 1);
|
||||
if(response->data == NULL)
|
||||
return 0;
|
||||
if(len > 0)
|
||||
memcpy(response->data, text, len);
|
||||
response->data[len] = '\0';
|
||||
response->len = len;
|
||||
response->cap = len + 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_http_request(const char *method, const char *url, const char *body,
|
||||
const char *const *headers, int header_count,
|
||||
SyncBuffer *response, long *status)
|
||||
{
|
||||
struct android_app *app = GetAndroidApp();
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method_id;
|
||||
jstring jmethod = NULL;
|
||||
jstring jurl = NULL;
|
||||
jstring jbody = NULL;
|
||||
jobjectArray jheaders = NULL;
|
||||
jstring result = NULL;
|
||||
const char *result_text = NULL;
|
||||
const char *newline;
|
||||
int attached = 0;
|
||||
int ok = 0;
|
||||
|
||||
if(status != NULL)
|
||||
*status = 0;
|
||||
if(app == NULL || app->activity == NULL || app->activity->vm == NULL ||
|
||||
app->activity->clazz == NULL || method == NULL || url == NULL)
|
||||
return 0;
|
||||
|
||||
jvm = app->activity->vm;
|
||||
activity = app->activity->clazz;
|
||||
if((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK || env == NULL)
|
||||
return 0;
|
||||
attached = 1;
|
||||
}
|
||||
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method_id = (*env)->GetMethodID(env, activity_class, "syncHttpRequest",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/String;");
|
||||
if(method_id == NULL)
|
||||
goto done;
|
||||
|
||||
jmethod = (*env)->NewStringUTF(env, method);
|
||||
jurl = (*env)->NewStringUTF(env, url);
|
||||
jbody = (*env)->NewStringUTF(env, body != NULL ? body : "");
|
||||
jclass string_class = (*env)->FindClass(env, "java/lang/String");
|
||||
if(jmethod == NULL || jurl == NULL || jbody == NULL || string_class == NULL)
|
||||
goto done;
|
||||
jheaders = (*env)->NewObjectArray(env, header_count, string_class, NULL);
|
||||
if(jheaders == NULL)
|
||||
goto done;
|
||||
for(int i = 0; i < header_count; i++) {
|
||||
jstring value = (*env)->NewStringUTF(env, headers[i] != NULL ? headers[i] : "");
|
||||
if(value == NULL)
|
||||
goto done;
|
||||
(*env)->SetObjectArrayElement(env, jheaders, i, value);
|
||||
(*env)->DeleteLocalRef(env, value);
|
||||
}
|
||||
|
||||
result = (jstring)(*env)->CallObjectMethod(env, activity, method_id,
|
||||
jmethod, jurl, jbody, jheaders);
|
||||
if((*env)->ExceptionCheck(env) || result == NULL)
|
||||
goto done;
|
||||
result_text = (*env)->GetStringUTFChars(env, result, NULL);
|
||||
if(result_text == NULL)
|
||||
goto done;
|
||||
newline = strchr(result_text, '\n');
|
||||
if(newline == NULL)
|
||||
goto done;
|
||||
if(status != NULL)
|
||||
*status = strtol(result_text, NULL, 10);
|
||||
ok = sync_buffer_set(response, newline + 1);
|
||||
|
||||
done:
|
||||
if(result_text != NULL && result != NULL)
|
||||
(*env)->ReleaseStringUTFChars(env, result, result_text);
|
||||
if(result != NULL)
|
||||
(*env)->DeleteLocalRef(env, result);
|
||||
if(jheaders != NULL)
|
||||
(*env)->DeleteLocalRef(env, jheaders);
|
||||
if(jbody != NULL)
|
||||
(*env)->DeleteLocalRef(env, jbody);
|
||||
if(jurl != NULL)
|
||||
(*env)->DeleteLocalRef(env, jurl);
|
||||
if(jmethod != NULL)
|
||||
(*env)->DeleteLocalRef(env, jmethod);
|
||||
if((*env)->ExceptionCheck(env)) {
|
||||
(*env)->ExceptionDescribe(env);
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
if(attached)
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_HTTP)
|
||||
static InbeSyncClientResult
|
||||
sync_fetch_challenge(const char *base_url, const char *user_id, char nonce_hex[65])
|
||||
{
|
||||
char url[768];
|
||||
SyncBuffer response = {0};
|
||||
long status = 0;
|
||||
int ok;
|
||||
|
||||
nonce_hex[0] = '\0';
|
||||
sync_join_url(url, sizeof(url), base_url, INBE_CHALLENGE_PATH);
|
||||
if(strlen(url) + strlen(user_id) + 10 >= sizeof(url))
|
||||
return INBE_SYNC_CLIENT_INVALID_URL;
|
||||
strncat(url, "?user_id=", sizeof(url) - strlen(url) - 1);
|
||||
strncat(url, user_id, sizeof(url) - strlen(url) - 1);
|
||||
ok = sync_http_request("GET", url, NULL, NULL, 0, &response, &status);
|
||||
if(!ok || status != 200 ||
|
||||
!sync_find_json_string(response.data, "nonce", nonce_hex, 65) ||
|
||||
strlen(nonce_hex) != 64) {
|
||||
free(response.data);
|
||||
return status == 401 ? INBE_SYNC_CLIENT_AUTH_FAILED : INBE_SYNC_CLIENT_CHALLENGE_FAILED;
|
||||
}
|
||||
free(response.data);
|
||||
return INBE_SYNC_CLIENT_OK;
|
||||
}
|
||||
|
||||
static InbeSyncClientResult
|
||||
sync_send_signed(const char *base_url, const char *path, const char *method,
|
||||
const char *user_id, const char *body)
|
||||
{
|
||||
char nonce_hex[65];
|
||||
char message[256];
|
||||
char signature_hex[5000];
|
||||
char url[768];
|
||||
char user_header[96];
|
||||
char signature_header[5050];
|
||||
const char *headers[3];
|
||||
SyncBuffer response = {0};
|
||||
long status = 0;
|
||||
InbeSyncClientResult challenge_result;
|
||||
int ok;
|
||||
|
||||
challenge_result = sync_fetch_challenge(base_url, user_id, nonce_hex);
|
||||
if(challenge_result != INBE_SYNC_CLIENT_OK)
|
||||
return challenge_result;
|
||||
if(!sync_build_message(method, path, nonce_hex, body, message, sizeof(message)))
|
||||
return INBE_SYNC_CLIENT_SIGN_FAILED;
|
||||
if(!inbe_sync_account_sign_hex((const uint8_t *)message, strlen(message),
|
||||
signature_hex, sizeof(signature_hex)))
|
||||
return INBE_SYNC_CLIENT_SIGN_FAILED;
|
||||
sync_join_url(url, sizeof(url), base_url, path);
|
||||
snprintf(user_header, sizeof(user_header), "X-Inbe-User: %s", user_id);
|
||||
snprintf(signature_header, sizeof(signature_header), "X-Inbe-Signature: %s", signature_hex);
|
||||
headers[0] = "Content-Type: application/json";
|
||||
headers[1] = user_header;
|
||||
headers[2] = signature_header;
|
||||
ok = sync_http_request(method, url, body, headers, 3, &response, &status);
|
||||
free(response.data);
|
||||
if(!ok)
|
||||
return INBE_SYNC_CLIENT_REQUEST_FAILED;
|
||||
if(status == 401)
|
||||
return INBE_SYNC_CLIENT_AUTH_FAILED;
|
||||
return status >= 200 && status < 300 ? INBE_SYNC_CLIENT_OK : INBE_SYNC_CLIENT_REQUEST_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
InbeSyncClientResult
|
||||
inbe_sync_client_sync(const char *base_url)
|
||||
{
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_HTTP)
|
||||
InbeSyncAccount account;
|
||||
char *payload;
|
||||
InbeSyncClientResult result;
|
||||
|
||||
if(!inbe_sync_client_url_valid(base_url))
|
||||
return INBE_SYNC_CLIENT_INVALID_URL;
|
||||
if(!inbe_sync_account_load(&account))
|
||||
return INBE_SYNC_CLIENT_NO_ACCOUNT;
|
||||
payload = inbe_storage_build_sync_payload_json(account.public_id, account.public_key_hex);
|
||||
if(payload == NULL)
|
||||
return INBE_SYNC_CLIENT_PAYLOAD_FAILED;
|
||||
result = sync_send_signed(base_url, INBE_SYNC_PATH, "POST", account.public_id, payload);
|
||||
inbe_storage_free_sync_payload_json(payload);
|
||||
return result;
|
||||
#else
|
||||
(void)base_url;
|
||||
return INBE_SYNC_CLIENT_UNAVAILABLE;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef INBE_SYNC_CLIENT_H
|
||||
#define INBE_SYNC_CLIENT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum InbeSyncClientResult {
|
||||
INBE_SYNC_CLIENT_OK = 0,
|
||||
INBE_SYNC_CLIENT_UNAVAILABLE,
|
||||
INBE_SYNC_CLIENT_INVALID_URL,
|
||||
INBE_SYNC_CLIENT_NO_ACCOUNT,
|
||||
INBE_SYNC_CLIENT_PAYLOAD_FAILED,
|
||||
INBE_SYNC_CLIENT_CHALLENGE_FAILED,
|
||||
INBE_SYNC_CLIENT_SIGN_FAILED,
|
||||
INBE_SYNC_CLIENT_REQUEST_FAILED,
|
||||
INBE_SYNC_CLIENT_AUTH_FAILED
|
||||
} InbeSyncClientResult;
|
||||
|
||||
int inbe_sync_client_url_valid(const char *url);
|
||||
int inbe_sync_client_normalize_url(const char *input, char *out, size_t out_size);
|
||||
InbeSyncClientResult inbe_sync_client_sync(const char *base_url);
|
||||
|
||||
#endif
|
||||
@@ -8,12 +8,12 @@
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://inbe.waozi.xyz/">
|
||||
<meta property="og:title" content="Inner Breeze">
|
||||
<meta property="og:description" content="guided breathing meditation based on the Wim Hof method">
|
||||
<meta property="og:description" content="guided breathing, meditation, and habit tracking">
|
||||
<meta property="og:image" content="https://inbe.waozi.xyz/og.jpg">
|
||||
<meta name="twitter:card" content="summary_large_image">
|
||||
<meta name="twitter:url" content="https://inbe.waozi.xyz/">
|
||||
<meta name="twitter:title" content="Inner Breeze">
|
||||
<meta name="twitter:description" content="guided breathing meditation based on the Wim Hof method">
|
||||
<meta name="twitter:description" content="guided breathing, meditation, and habit tracking">
|
||||
<meta name="twitter:image" content="https://inbe.waozi.xyz/og.jpg">
|
||||
<meta name="twitter:site" content="@waozixyz">
|
||||
<meta name="twitter:creator" content="@waozixyz">
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int g_failures = 0;
|
||||
@@ -159,6 +160,32 @@ write_source_database(const char *root)
|
||||
inbe_storage_close();
|
||||
}
|
||||
|
||||
static void
|
||||
insert_raw_habit_day(const char *root, const char *habit_id, int local_date, int completed)
|
||||
{
|
||||
char db_path[512];
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
|
||||
make_path(db_path, sizeof(db_path), root, "inbe.db");
|
||||
check_true("open raw habit day db", sqlite3_open(db_path, &db) == SQLITE_OK);
|
||||
if(db == NULL)
|
||||
return;
|
||||
if(sqlite3_prepare_v2(db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, habit_id, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, 2, local_date);
|
||||
sqlite3_bind_int(stmt, 3, completed ? 1 : 0);
|
||||
check_true("insert raw habit day", sqlite3_step(stmt) == SQLITE_DONE);
|
||||
} else {
|
||||
check_true("prepare raw habit day", 0);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
static void
|
||||
metadata_history_callback(const char *id, int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
@@ -338,6 +365,91 @@ test_habit_name_merge_import(void)
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_import_conflict_prefers_data_over_empty(void)
|
||||
{
|
||||
char source[512], dest[512], zip_path[512];
|
||||
InbeHabits habits;
|
||||
InbeHabit *habit;
|
||||
|
||||
make_clean_root(source, sizeof(source), "conflict-source");
|
||||
make_clean_root(dest, sizeof(dest), "conflict-dest");
|
||||
make_path(zip_path, sizeof(zip_path), source, "conflict-export.zip");
|
||||
|
||||
check_true("init conflict source", inbe_storage_init(source));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict source habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){224, 124, 104, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_storage_set_setting_text("language", "");
|
||||
inbe_storage_close();
|
||||
insert_raw_habit_day(source, "habit-1", 20260618, 0);
|
||||
check_true("reopen conflict source", inbe_storage_init(source));
|
||||
check_true("conflict source export", inbe_storage_export_zip(zip_path));
|
||||
inbe_storage_close();
|
||||
|
||||
check_true("init conflict dest", inbe_storage_init(dest));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict dest habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){126, 183, 230, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20260618, 1);
|
||||
inbe_storage_set_setting_text("language", "en");
|
||||
check_true("conflict import",
|
||||
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("conflict habits load", inbe_storage_habits_load(&habits));
|
||||
habit = find_habit_ci(&habits, "Meditation");
|
||||
check_true("conflict keeps completed day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260618));
|
||||
check_str("conflict keeps non-empty setting",
|
||||
inbe_storage_get_setting_text("language"), "en");
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_all_resets_habits_to_empty_storage(void)
|
||||
{
|
||||
char root[512];
|
||||
InbeHabits habits;
|
||||
long long deleted;
|
||||
|
||||
make_clean_root(root, sizeof(root), "delete-all");
|
||||
check_true("init delete all db", inbe_storage_init(root));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add delete all habit",
|
||||
inbe_habits_add_custom(&habits, "Work out",
|
||||
(Color){99, 196, 165, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20260618, 1);
|
||||
check_int("delete all habit count before", inbe_storage_habit_count(), 1);
|
||||
check_true("delete all sees habit-only data", inbe_storage_has_any());
|
||||
|
||||
deleted = inbe_storage_delete_all_sessions();
|
||||
check_true("delete all removed habit data", deleted >= 2);
|
||||
check_int("delete all habit count after", inbe_storage_habit_count(), 0);
|
||||
|
||||
inbe_habits_add_default_set(&habits);
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("load default habit after delete all", inbe_storage_habits_load(&habits));
|
||||
check_int("default habit count after delete all", habits.count, 1);
|
||||
check_true("default meditation after delete all",
|
||||
strcmp(habits.items[0].name, "Meditation") == 0);
|
||||
check_true("old workout day removed",
|
||||
!inbe_habit_completed_day(&habits.items[0], 20260618));
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
write_multi_habit_source_database(const char *root, const char *zip_path)
|
||||
{
|
||||
@@ -533,6 +645,7 @@ static void
|
||||
write_tickmate_database(const char *path)
|
||||
{
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char *error = NULL;
|
||||
|
||||
check_true("open tickmate db", sqlite3_open(path, &db) == SQLITE_OK);
|
||||
@@ -547,15 +660,56 @@ write_tickmate_database(const char *path)
|
||||
"CREATE TABLE ticks(_id integer primary key autoincrement,"
|
||||
"_track_id integer,year integer,month integer,day integer,"
|
||||
"hour integer,minute integer,second integer,has_time_info integer DEFAULT 0);"
|
||||
"INSERT INTO tracks(_id,name,description,icon,enabled,color,\"order\") "
|
||||
"VALUES(1,'Meditation','Silenced my mind','',1,8925,0);"
|
||||
"INSERT INTO tracks(_id,name,description,icon,enabled,multiple_entries_per_day,color,\"order\") "
|
||||
"VALUES(1,'Meditation','Silenced my mind','',1,1,8925,0);"
|
||||
"INSERT INTO ticks(_track_id,year,month,day,hour,minute,second,has_time_info) "
|
||||
"VALUES(1,2026,6,13,0,0,0,0);",
|
||||
"VALUES(1,2026,0,1,0,0,0,0),"
|
||||
"(1,2026,1,2,0,0,0,0),"
|
||||
"(1,2026,2,3,0,0,0,0),"
|
||||
"(1,2026,3,4,0,0,0,0),"
|
||||
"(1,2026,4,5,0,0,0,0),"
|
||||
"(1,2026,5,6,0,0,0,0),"
|
||||
"(1,2026,6,7,0,0,0,0),"
|
||||
"(1,2026,7,8,0,0,0,0),"
|
||||
"(1,2026,8,9,0,0,0,0),"
|
||||
"(1,2026,9,10,0,0,0,0),"
|
||||
"(1,2026,10,11,0,0,0,0),"
|
||||
"(1,2026,11,12,0,0,0,0),"
|
||||
"(1,2025,0,1,0,0,0,0),"
|
||||
"(1,2025,0,1,0,0,0,0);",
|
||||
NULL, NULL, &error) == SQLITE_OK);
|
||||
if(error != NULL) {
|
||||
fprintf(stderr, "tickmate setup SQL error: %s\n", error);
|
||||
sqlite3_free(error);
|
||||
}
|
||||
check_true("prepare large tickmate insert",
|
||||
sqlite3_prepare_v2(db,
|
||||
"INSERT INTO ticks(_track_id,year,month,day,hour,minute,second,has_time_info) "
|
||||
"VALUES(1,?1,?2,?3,0,0,0,0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK);
|
||||
if(stmt != NULL) {
|
||||
struct tm day;
|
||||
|
||||
check_true("begin large tickmate insert", sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) == SQLITE_OK);
|
||||
memset(&day, 0, sizeof(day));
|
||||
day.tm_year = 2025 - 1900;
|
||||
day.tm_mon = 0;
|
||||
day.tm_mday = 1;
|
||||
day.tm_hour = 12;
|
||||
mktime(&day);
|
||||
for(int i = 0; i < 12000; i++) {
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_clear_bindings(stmt);
|
||||
sqlite3_bind_int(stmt, 1, day.tm_year + 1900);
|
||||
sqlite3_bind_int(stmt, 2, day.tm_mon);
|
||||
sqlite3_bind_int(stmt, 3, day.tm_mday);
|
||||
check_true("large tickmate insert row", sqlite3_step(stmt) == SQLITE_DONE);
|
||||
day.tm_mday++;
|
||||
mktime(&day);
|
||||
}
|
||||
check_true("commit large tickmate insert", sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) == SQLITE_OK);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
@@ -575,24 +729,101 @@ test_tickmate_db_import(void)
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("tickmate habits load", inbe_storage_habits_load(&habits));
|
||||
check_int("tickmate habit count", habits.count, 1);
|
||||
check_true("tickmate habit day", inbe_habit_completed_day(&habits.items[0], 20260613));
|
||||
check_true("tickmate january day", inbe_habit_completed_day(&habits.items[0], 20260101));
|
||||
check_true("tickmate february day", inbe_habit_completed_day(&habits.items[0], 20260202));
|
||||
check_true("tickmate march day", inbe_habit_completed_day(&habits.items[0], 20260303));
|
||||
check_true("tickmate april day", inbe_habit_completed_day(&habits.items[0], 20260404));
|
||||
check_true("tickmate may day", inbe_habit_completed_day(&habits.items[0], 20260505));
|
||||
check_true("tickmate june day", inbe_habit_completed_day(&habits.items[0], 20260606));
|
||||
check_true("tickmate july day", inbe_habit_completed_day(&habits.items[0], 20260707));
|
||||
check_true("tickmate august day", inbe_habit_completed_day(&habits.items[0], 20260808));
|
||||
check_true("tickmate september day", inbe_habit_completed_day(&habits.items[0], 20260909));
|
||||
check_true("tickmate october day", inbe_habit_completed_day(&habits.items[0], 20261010));
|
||||
check_true("tickmate november day", inbe_habit_completed_day(&habits.items[0], 20261111));
|
||||
check_true("tickmate december day", inbe_habit_completed_day(&habits.items[0], 20261212));
|
||||
check_true("tickmate loads thousands of days",
|
||||
inbe_habit_completed_day(&habits.items[0], 20571108));
|
||||
check_true("tickmate habit name", strcmp(habits.items[0].name, "Meditation") == 0);
|
||||
check_int("tickmate enables counter habit", habits.items[0].counter_enabled, 1);
|
||||
check_int("tickmate imports count", inbe_habit_day_count(&habits.items[0], 20250101), 3);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tickmate_reimport_recovers_counter_data(void)
|
||||
{
|
||||
char source[512], dest[512], db_path[512];
|
||||
InbeHabits habits;
|
||||
|
||||
make_clean_root(source, sizeof(source), "tickmate-reimport-source");
|
||||
make_clean_root(dest, sizeof(dest), "tickmate-reimport-dest");
|
||||
make_path(db_path, sizeof(db_path), source, "tickmate.db");
|
||||
write_tickmate_database(db_path);
|
||||
|
||||
check_true("init tickmate reimport dest", inbe_storage_init(dest));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add old boolean meditation",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){99, 196, 165, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20250101, 1);
|
||||
check_true("tickmate reimport", inbe_storage_import_zip(db_path));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("tickmate reimport load", inbe_storage_habits_load(&habits));
|
||||
check_int("tickmate reimport habit count", habits.count, 1);
|
||||
check_int("tickmate reimport enables counter", habits.items[0].counter_enabled, 1);
|
||||
check_int("tickmate reimport restores count",
|
||||
inbe_habit_day_count(&habits.items[0], 20250101), 3);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_external_tickmate_db_import(void)
|
||||
{
|
||||
const char *db_path = getenv("INBE_TICKMATE_IMPORT_FIXTURE");
|
||||
char dest[512];
|
||||
InbeStorageImportInfo info;
|
||||
InbeHabits habits;
|
||||
|
||||
if(db_path == NULL || db_path[0] == '\0')
|
||||
return;
|
||||
|
||||
make_clean_root(dest, sizeof(dest), "external-tickmate-dest");
|
||||
check_true("init external tickmate import dest", inbe_storage_init(dest));
|
||||
memset(&info, 0, sizeof(info));
|
||||
check_true("inspect external tickmate db", inbe_storage_inspect_import(db_path, &info));
|
||||
check_true("external tickmate db valid", info.valid);
|
||||
check_true("external tickmate db has habits", info.has_habits);
|
||||
check_true("external tickmate db import", inbe_storage_import_zip(db_path));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("external tickmate habits load", inbe_storage_habits_load(&habits));
|
||||
check_true("external tickmate habit count", habits.count > 0);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
test_raw_db_import();
|
||||
test_zip_db_import();
|
||||
test_habit_name_merge_import();
|
||||
test_import_conflict_prefers_data_over_empty();
|
||||
test_delete_all_resets_habits_to_empty_storage();
|
||||
test_import_modes_preserve_habits_and_settings_choice();
|
||||
test_legacy_zip_import();
|
||||
test_legacy_file_startup_migration();
|
||||
test_tickmate_db_import();
|
||||
test_tickmate_reimport_recovers_counter_data();
|
||||
test_external_tickmate_db_import();
|
||||
test_session_metadata();
|
||||
|
||||
if(g_failures != 0) {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "sync_client.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int inbe_sync_client_test_response_buffer(const char *first, const char *second,
|
||||
char *out, size_t out_size);
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void
|
||||
check_valid(const char *input, const char *normalized)
|
||||
{
|
||||
char out[256];
|
||||
|
||||
if(!inbe_sync_client_url_valid(input)) {
|
||||
fprintf(stderr, "FAIL valid %s\n", input);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if(!inbe_sync_client_normalize_url(input, out, sizeof(out)) ||
|
||||
strcmp(out, normalized) != 0) {
|
||||
fprintf(stderr, "FAIL normalize %s: got %s, want %s\n",
|
||||
input, out, normalized);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_invalid(const char *input)
|
||||
{
|
||||
char out[256];
|
||||
|
||||
if(inbe_sync_client_url_valid(input)) {
|
||||
fprintf(stderr, "FAIL invalid accepted %s\n", input);
|
||||
failures++;
|
||||
}
|
||||
if(inbe_sync_client_normalize_url(input, out, sizeof(out))) {
|
||||
fprintf(stderr, "FAIL invalid normalized %s to %s\n", input, out);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_response_buffer(void)
|
||||
{
|
||||
char out[64];
|
||||
|
||||
if(!inbe_sync_client_test_response_buffer("{\"nonce\":\"", "abc\"}", out, sizeof(out)) ||
|
||||
strcmp(out, "{\"nonce\":\"abc\"}") != 0) {
|
||||
fprintf(stderr, "FAIL response buffer append: got %s\n", out);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
check_valid("https://api.waozi.xyz", "https://api.waozi.xyz");
|
||||
check_valid("http://localhost:8080", "http://localhost:8080");
|
||||
check_valid("localhost:8080", "http://localhost:8080");
|
||||
check_valid("localhost:3000", "http://localhost:3000");
|
||||
check_valid("127.0.0.1:8080", "http://127.0.0.1:8080");
|
||||
check_valid("127.0.0.1:49152", "http://127.0.0.1:49152");
|
||||
check_valid("10.0.2.2:8080", "http://10.0.2.2:8080");
|
||||
|
||||
check_invalid("");
|
||||
check_invalid("localhost.evil.test:8080");
|
||||
check_invalid("http://localhost.evil.test");
|
||||
check_invalid("http://example.com");
|
||||
|
||||
check_response_buffer();
|
||||
|
||||
if(failures != 0) {
|
||||
fprintf(stderr, "%d sync URL test failure(s)\n", failures);
|
||||
return 1;
|
||||
}
|
||||
printf("sync URL tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
IDI_APP_ICON ICON "inbe.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,3,3,0
|
||||
PRODUCTVERSION 1,3,3,0
|
||||
FILEVERSION 1,4,0,0
|
||||
PRODUCTVERSION 1,4,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -21,11 +21,11 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "waozi"
|
||||
VALUE "FileDescription", "Inner Breeze"
|
||||
VALUE "FileVersion", "1.3.3"
|
||||
VALUE "FileVersion", "1.4.0"
|
||||
VALUE "InternalName", "inbe"
|
||||
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
|
||||
VALUE "ProductName", "Inner Breeze"
|
||||
VALUE "ProductVersion", "1.3.3"
|
||||
VALUE "ProductVersion", "1.4.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||