Compare commits

...
33 Commits
Author SHA1 Message Date
waozixyz d1cc630a06 bug fixes on web 2026-06-19 14:43:41 -03:00
waozixyz f06ba7c670 improve account management 2026-06-19 14:20:17 -03:00
waozixyz 615444fa70 improve account maangement 2026-06-19 14:19:52 -03:00
waozixyz e0b5bb3599 fix icon row 2026-06-19 13:18:26 -03:00
waozixyz e62357670f ui improvements 2026-06-19 13:15:21 -03:00
waozixyz 59ebb09921 implement habit conutr 2026-06-19 13:05:40 -03:00
waozixyz d8a6521ce4 simplify tutorial 2026-06-19 11:49:43 -03:00
waozixyz e5c77d0a0e add sync settings 2026-06-19 11:13:30 -03:00
waozixyz 0c13c833e3 refactor and add private id generation 2026-06-19 01:59:20 -03:00
waozixyz f29a1f8cf7 improve file dialog 2026-06-19 00:00:41 -03:00
waozixyz 1b0e06dce2 fix tickmate import 2026-06-18 18:32:52 -03:00
waozixyz db7bb624e4 improved android data import for .db 2026-06-18 17:27:23 -03:00
waozixyz 4a8a554396 allow import db files 2026-06-18 17:09:50 -03:00
waozixyz ffc7577ddc reduce apk mess 2026-06-18 11:56:47 -03:00
waozixyz b577e8411b fix gituhb action 2026-06-18 11:45:56 -03:00
waozixyz 10103c82a0 Build release artifacts without Nix 2026-06-18 11:04:08 -03:00
waozixyz 4e7c737c1c Run CI tests without Nix 2026-06-18 02:33:08 -03:00
waozixyz 6c96e8a119 split up workflows 2026-06-18 01:59:50 -03:00
waozixyz 87829c5dd6 improve github action 2026-06-18 01:54:01 -03:00
waozixyz e736bb7ec7 improve github actino 2026-06-18 01:44:45 -03:00
waozixyz 3236a6176a fix audio linux 2026-06-18 01:30:30 -03:00
waozixyz fae1cb89bb multi platform build on gh 2026-06-18 01:18:48 -03:00
waozixyz 7b01f675a7 refactor practices 2026-06-18 01:11:15 -03:00
waozixyz beefec7df0 cleanup and refactor 2026-06-17 23:12:37 -03:00
waozixyz f8ee130b45 fix improt web 2026-06-17 19:32:00 -03:00
waozixyz f12ef05421 update version 2026-06-17 18:50:36 -03:00
waozixyz 1732b31031 improve and fix improt 2026-06-17 18:50:24 -03:00
waozixyz b14ca1c8c9 fix issues with runtime assets 2026-06-17 16:43:48 -03:00
waozixyz 9466bf02ed fix no of assets 2026-06-17 16:33:01 -03:00
waozixyz acbd43bc65 bug fixes 2026-06-17 16:30:25 -03:00
waozixyz 06d79002e1 fix appimage 2026-06-17 15:36:27 -03:00
waozixyz 2db5045efb fix merge import 2026-06-17 13:47:05 -03:00
waozixyz 0f6f40cb0a fix orientation change 2026-06-17 13:37:38 -03:00
101 changed files with 10891 additions and 2850 deletions

No files matched your search

+12
View File
@@ -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
-106
View File
@@ -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 }}
+37
View File
@@ -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
+320
View File
@@ -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 }}
+3
View File
@@ -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
+37
View File
@@ -1,4 +1,41 @@
# Changelog
## [1.4.1] - 2026-06-19
### Changed
- Improve account management
## [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.
## [1.3.2] - 2026-06-17
### Fixed
- Unified scroll containers so content stays out of scrollbar tracks and scroll positions clamp cleanly at the bottom.
- Android meditation audio downloads now show a localized network-permission/connectivity modal when the host cannot be resolved.
- Windows builds now support runtime meditation audio downloads.
## [1.3.1] - 2026-06-17
### Fixed
- Fixed Android orientation resizing and habit import merging by name.
## [1.3.0] - 2026-06-14
### Added
- Implemented 1-bit habit tracker synced with practice data
+104 -20
View File
@@ -6,6 +6,7 @@ ANDROID_APP_ID := xyz.waozi.inbe
ANDROID_ACTIVITY := xyz.waozi.inbe.MainActivity
CC ?= gcc
CMAKE ?= $(shell if [ -x /usr/bin/cmake ]; then echo /usr/bin/cmake; else command -v cmake; fi)
GRADLE ?= gradle
ARCH := $(shell uname -m)
ANDROID_KEYSTORE ?= $(HOME)/.android/flint-release.keystore
@@ -61,46 +62,66 @@ FLINT_SRCS := $(filter-out $(FLINT_ICON_ASSETS_C),$(wildcard $(FLINT_DIR)/src/*.
FLINT_WEB_SRCS := $(filter-out $(FLINT_DIR)/src/flint_file_dialog.c,$(FLINT_SRCS))
FLINT_WINDOWS_SRCS := $(filter-out $(FLINT_DIR)/src/flint_file_dialog.c,$(FLINT_SRCS))
FLINT_INCLUDE := -I$(FLINT_DIR)/include
FLINT_CURL_CFLAGS ?= $(shell pkg-config --cflags libcurl 2>/dev/null)
FLINT_CURL_LDLIBS ?= $(shell pkg-config --libs libcurl 2>/dev/null)
FLINT_CURL_CFLAGS ?= $(shell pkg-config --cflags libcurl 2>/dev/null || curl-config --cflags 2>/dev/null)
FLINT_CURL_LDLIBS ?= $(shell pkg-config --libs libcurl 2>/dev/null || curl-config --libs 2>/dev/null)
SQLITE_DIR := vendor/sqlite
SQLITE_BUILD_DIR := $(BUILD_OBJ_DIR)/sqlite
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
WEB_LIBOQS_BUILD_DIR := $(BUILD_OBJ_DIR)/liboqs/web
WEB_LIBOQS_A := $(WEB_LIBOQS_BUILD_DIR)/lib/liboqs.a
WEB_LIBOQS_INCLUDE := -I$(WEB_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
ifneq ($(strip $(FLINT_CURL_LDLIBS)),)
LOCALE_KEYS_TEST := $(TEST_BIN_DIR)/locale_keys_test
SYNC_URL_TEST := $(TEST_BIN_DIR)/sync_url_test
SYNC_ACCOUNT_TEST := $(TEST_BIN_DIR)/sync_account_test
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
else
FLINT_RUNTIME_ASSET_CFLAGS :=
FLINT_RUNTIME_ASSET_LDLIBS :=
endif
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
@@ -110,14 +131,14 @@ 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
WEB_CFLAGS := $(filter-out -std=c99,$(CFLAGS)) -std=gnu99
LDFLAGS := -Wl,--gc-sections -s
WINDOWS_LDFLAGS := -Wl,--gc-sections -static -static-libgcc -mwindows
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lm
WINDOWS_LDLIBS := -lgdi32 -lwinmm -lopengl32 -luser32 -lshell32 -lole32 -lcomdlg32 -lcomctl32 -luuid -lwininet -lm
ifneq ($(strip $(MCFGTHREADS)),)
WIN64_THREAD_LDFLAGS := -L$(MCFGTHREADS)/lib
else
@@ -143,11 +164,13 @@ 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 windows64 windows32 web
.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
.NOTPARALLEL: dist windows windows64 windows32 android-release android-bundle
all: native
@@ -180,13 +203,16 @@ appimage: $(APPIMAGE_TARGET)
run: $(TARGET)
./$(TARGET)
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST)
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST) $(SYNC_URL_TEST) $(SYNC_ACCOUNT_TEST)
$(STORAGE_IMPORT_TEST)
$(FLINT_TEXT_SCALING_TEST)
$(LOCALE_KEYS_TEST)
$(SYNC_URL_TEST)
$(SYNC_ACCOUNT_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
@@ -198,6 +224,24 @@ $(FLINT_TEXT_SCALING_TEST): tests/flint_text_scaling_test.c flint/src/flint_text
tests/flint_text_scaling_test.c flint/src/flint_text.c flint/src/flint_clip.c flint/src/flint_scaling.c \
-Wl,--gc-sections -lm
$(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE \
-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
$(SYNC_ACCOUNT_TEST): tests/sync_account_test.c src/storage/sync_account.c src/storage/sync_account.h src/storage/storage.c src/storage/storage.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/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party -Ivendor/raylib/src $(SQLITE_INCLUDE) \
-o $@ \
tests/sync_account_test.c src/storage/sync_account.c src/storage/storage.c src/third_party/miniz.c $(SQLITE_SRC) \
-Wl,--gc-sections -lm -lpthread -ldl
$(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 $@
@@ -290,13 +334,35 @@ $(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
$(WEB_LIBOQS_A): $(LIBOQS_DIR)/CMakeLists.txt | $(BUILD_OBJ_DIR)
emcmake $(CMAKE) -S $(LIBOQS_DIR) -B $(WEB_LIBOQS_BUILD_DIR) \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DBUILD_SHARED_LIBS=OFF \
-DOQS_BUILD_ONLY_LIB=ON \
-DOQS_USE_OPENSSL=OFF \
-DOQS_DIST_BUILD=OFF \
-DOQS_OPT_TARGET=generic \
-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44
$(CMAKE) --build $(WEB_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 \
@@ -305,6 +371,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 \
@@ -353,11 +420,16 @@ $(APPIMAGE_TARGET): $(TARGET) $(LINUX_APPIMAGE_APPRUN) $(LINUX_APPIMAGE_DESKTOP)
echo "appimagetool is missing. Re-enter the flake shell with: nix develop"; \
exit 1; \
}
@command -v patchelf >/dev/null || { \
echo "patchelf is missing. Re-enter the flake shell with: nix develop"; \
exit 1; \
}
rm -rf $(LINUX_APPDIR)
rm -rf $(LINUX_DIST_DIR)/*.AppDir
rm -f $(LINUX_DIST_DIR)/*.AppImage
mkdir -p $(LINUX_APPDIR)/usr/bin $(LINUX_APPDIR)/usr/share/applications $(LINUX_APPDIR)/usr/share/icons/hicolor/512x512/apps
cp $(TARGET) $(LINUX_APPDIR)/usr/bin/$(APP_NAME)
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $(LINUX_APPDIR)/usr/bin/$(APP_NAME)
cp $(LINUX_APPIMAGE_APPRUN) $(LINUX_APPDIR)/AppRun
chmod +x $(LINUX_APPDIR)/AppRun
cp $(LINUX_APPIMAGE_DESKTOP) $(LINUX_APPDIR)/$(APP_NAME).desktop
@@ -372,12 +444,14 @@ $(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) $(WEB_LIBOQS_A) src/web_shell.html manifest.json $(WEB_ASSET_FILES) $(WEB_AUDIO_FILES) | $(WEB_DIST_DIR)
$(WEB_CC) $(WEB_CFLAGS) \
$(APP_INCLUDE) \
$(FLINT_INCLUDE) \
$(SQLITE_INCLUDE) \
$(WEB_LIBOQS_INCLUDE) \
-I$(RAYLIB_DIR) \
-DINBE_HAS_LIBOQS=1 \
-DPLATFORM_WEB \
-DSUPPORT_MODULE_RAUDIO=1 \
-DSUPPORT_FILEFORMAT_OGG=1 \
@@ -387,11 +461,13 @@ $(WEB_TARGET): Makefile $(SRC) $(FLINT_WEB_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMA
$(FLINT_WEB_SRCS) \
$(SQLITE_SRC) \
$(WEB_RAYLIB_A) \
$(WEB_LIBOQS_A) \
-sUSE_GLFW=3 \
-sASYNCIFY \
-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
@@ -525,9 +601,12 @@ package-unpackaged-assets:
rm -f $(MEDITATION_AUDIO_ZIP)
cd $(UNPACKAGED_AUDIO_DIR) && find . -mindepth 2 -type f -name '*.ogg' -exec zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) {} + && zip -9 -r $(abspath $(MEDITATION_AUDIO_ZIP)) LICENSE.md MANIFEST.txt
windows64: $(WIN64_TARGET)
windows-runtime-assets-check:
@:
windows32: $(WIN32_TARGET)
windows64: windows-runtime-assets-check $(WIN64_TARGET)
windows32: windows-runtime-assets-check $(WIN32_TARGET)
windows:
$(MAKE) windows64
@@ -541,6 +620,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
@@ -568,4 +649,7 @@ endif
ifeq ($(strip $(RAY_RAYLIB_CONFIG)),)
$(error RAY_RAYLIB_CONFIG is not set. Enter the ray flake shell with 'nix develop')
endif
ifeq ($(strip $(FLINT_CURL_LDLIBS)),)
$(error libcurl pkg-config metadata is missing. Runtime asset downloads are required; enter the flake shell with 'nix develop' or set FLINT_CURL_CFLAGS/FLINT_CURL_LDLIBS explicitly)
endif
endif
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

+2 -2
View File
@@ -35,8 +35,8 @@ android {
defaultConfig {
minSdk 19
targetSdk 35
versionCode 28
versionName "1.3.0"
versionCode 36
versionName "1.4.1"
}
+29 -5
View File
@@ -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,8 +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";
@@ -48,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);
@@ -146,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);
@@ -177,10 +197,10 @@ public class MainActivity extends NativeActivity {
int requested = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
switch (mode) {
case 1:
requested = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
requested = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
break;
case 2:
requested = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
requested = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
break;
case 3:
requested = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR;
@@ -249,6 +269,9 @@ public class MainActivity extends NativeActivity {
}
nativeRuntimeAssetDownloadSucceeded(handle, written, status);
} catch (UnknownHostException | SocketException | SocketTimeoutException e) {
outputFile.delete();
nativeRuntimeAssetDownloadFailed(handle, status, "NETWORK_UNAVAILABLE");
} catch (Exception e) {
outputFile.delete();
nativeRuntimeAssetDownloadFailed(handle, status, e.getMessage());
@@ -262,7 +285,69 @@ public class MainActivity extends NativeActivity {
}, "inbe-runtime-asset-download").start();
}
public void openImportPicker() {
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(final String mimeTypesCsv) {
runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -270,13 +355,10 @@ public class MainActivity extends NativeActivity {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {
"application/zip",
"application/x-zip-compressed",
"application/vnd.sqlite3",
"application/x-sqlite",
"application/x-sqlite3"
});
String[] mimeTypes = parseMimeTypes(mimeTypesCsv);
if (mimeTypes.length > 0) {
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
}
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
} catch (Exception e) {
Log.e(TAG, "Failed to open import picker", e);
@@ -286,6 +368,22 @@ public class MainActivity extends NativeActivity {
});
}
private static String[] parseMimeTypes(String mimeTypesCsv) {
if (mimeTypesCsv == null || mimeTypesCsv.trim().isEmpty()) {
return new String[0];
}
String[] raw = mimeTypesCsv.split(",");
java.util.ArrayList<String> result = new java.util.ArrayList<>();
for (String mimeType : raw) {
String trimmed = mimeType.trim();
if (!trimmed.isEmpty()) {
result.add(trimmed);
}
}
return result.toArray(new String[0]);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -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,2 @@
### Fixed
- Fixed Android orientation changes so forced landscape and portrait resize the app viewport correctly.
@@ -0,0 +1,3 @@
### Fixed
- Unified scroll containers so content stays out of scrollbar tracks and scroll positions clamp cleanly at the bottom.
- Android meditation audio downloads now show a localized network-permission/connectivity modal when the host cannot be resolved.
@@ -0,0 +1,2 @@
### Fixed
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
@@ -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
@@ -0,0 +1,2 @@
### Changed
- Improve account management
+4
View File
@@ -191,6 +191,7 @@ EOF
butler
cmake
curl
curl.dev
emscripten
gcc
git-lfs
@@ -203,13 +204,16 @@ EOF
libgbm
libglvnd
libglvnd.dev
alsa-lib
appimagetool
libpulseaudio
linuxdeploy
linuxdeployPluginAppImage
mesa
ncurses
ninja
pkg-config
pipewire
rsync
zlib
zip
+2
View File
@@ -37,12 +37,14 @@ int flint_file_dialog_save(FlintFileDialog *dlg, const char *title, const char *
/* Load file dialog - returns 1 if file selected, 0 if cancelled */
int flint_file_dialog_load(FlintFileDialog *dlg, const char *title);
int flint_file_dialog_load_filtered(FlintFileDialog *dlg, const char *title, const char *filter);
/* Select folder dialog - returns 1 if folder selected, 0 if cancelled */
int flint_file_dialog_select_folder(FlintFileDialog *dlg, const char *title);
/* Begin non-blocking dialogs. Call flint_file_dialog_update() each frame while active. */
void flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title);
void flint_file_dialog_begin_load_filtered(FlintFileDialog *dlg, const char *title, const char *filter);
void flint_file_dialog_begin_save(FlintFileDialog *dlg, const char *title, const char *default_filename);
/* Draw/update active dialog: 1 confirmed, 0 cancelled, -1 still active. */
+5
View File
@@ -126,6 +126,8 @@ typedef struct {
typedef struct {
Rectangle bounds;
int content_height;
int content_x;
int content_width;
int *scroll_offset;
int wheel_step;
int scrollbar_x;
@@ -214,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);
@@ -257,6 +261,7 @@ int ui_scrollbar_reserved_width(int max_scroll);
int ui_scrollbar_content_width(int content_width, int max_scroll);
int ui_scrollbar_safe_content_width(int content_x, int content_width,
int scrollbar_x, int max_scroll);
FlintUIScrollView ui_scroll_container_measure(FlintUIScrollArea area);
FlintUIScrollView ui_scroll_container_begin(FlintUIScrollArea area);
void ui_scroll_container_end(FlintUIScrollArea area, FlintUIScrollView view);
int ui_draw_scrollbar(int x, int y, int viewport_h, int content_h, int *scroll_offset, int max_scroll);
+31 -9
View File
@@ -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;
}
}
@@ -754,7 +762,7 @@ run_dialog(FlintFileDialog *dlg)
}
void
flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title)
flint_file_dialog_begin_load_filtered(FlintFileDialog *dlg, const char *title, const char *filter)
{
FlintFileDialogInternal *internal;
@@ -762,7 +770,7 @@ flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title)
flint_file_dialog_init(dlg);
dlg->mode = FLINT_FILE_DIALOG_LOAD;
copy_text(dlg->title, sizeof(dlg->title), title);
copy_text(dlg->filter, sizeof(dlg->filter), ".db,.zip");
copy_text(dlg->filter, sizeof(dlg->filter), filter != NULL ? filter : "");
dlg->active = 1;
dlg->confirmed = 0;
@@ -771,10 +779,23 @@ 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;
}
void
flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title)
{
flint_file_dialog_begin_load_filtered(dlg, title, NULL);
}
int flint_file_dialog_load_filtered(FlintFileDialog *dlg, const char *title, const char *filter) {
if(!dlg || !title) return 0;
flint_file_dialog_begin_load_filtered(dlg, title, filter);
return run_dialog(dlg);
}
int flint_file_dialog_load(FlintFileDialog *dlg, const char *title) {
if(!dlg || !title) return 0;
flint_file_dialog_begin_load(dlg, title);
@@ -839,7 +860,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)) {
+1
View File
@@ -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;
+145 -1
View File
@@ -7,6 +7,8 @@
#if defined(_WIN32)
#include <direct.h>
#include <windows.h>
#include <wininet.h>
#define FLINT_MKDIR(path) _mkdir(path)
#else
#include <errno.h>
@@ -208,6 +210,128 @@ fetch_failed(emscripten_fetch_t *fetch)
}
#endif
#if defined(_WIN32) && !defined(__EMSCRIPTEN__)
typedef struct WindowsDownloadContext {
FlintRuntimeAssetDownload *download;
} WindowsDownloadContext;
static void
windows_set_last_error(FlintRuntimeAssetDownload *download, const char *prefix)
{
DWORD err = GetLastError();
if(download == NULL)
return;
snprintf(download->error, sizeof(download->error), "%s (%lu)",
prefix != NULL ? prefix : "Windows download failed",
(unsigned long)err);
}
static DWORD WINAPI
windows_download_thread_main(void *user_data)
{
WindowsDownloadContext *ctx = (WindowsDownloadContext *)user_data;
FlintRuntimeAssetDownload *download = ctx != NULL ? ctx->download : NULL;
HINTERNET internet = NULL;
HINTERNET request = NULL;
FILE *file = NULL;
char status_buf[32];
DWORD status_len = sizeof(status_buf);
DWORD status_index = 0;
char length_buf[64];
DWORD length_len = sizeof(length_buf);
DWORD length_index = 0;
BYTE buffer[32768];
DWORD bytes_read = 0;
BOOL read_ok;
free(ctx);
if(download == NULL)
return 0;
file = fopen(download->path, "wb");
if(file == NULL) {
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
internet = InternetOpenA("flint-runtime-assets/1",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if(internet == NULL) {
fclose(file);
windows_set_last_error(download, "failed to initialize Windows networking");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
request = InternetOpenUrlA(internet, download->url, NULL, 0,
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_PRAGMA_NOCACHE,
0);
if(request == NULL) {
fclose(file);
InternetCloseHandle(internet);
remove(download->path);
windows_set_last_error(download, "Windows download failed");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
if(HttpQueryInfoA(request, HTTP_QUERY_STATUS_CODE, status_buf, &status_len, &status_index)) {
status_buf[sizeof(status_buf) - 1] = '\0';
download->http_status = strtol(status_buf, NULL, 10);
}
if(download->http_status < 200 || download->http_status >= 300) {
snprintf(download->error, sizeof(download->error), "HTTP %ld", download->http_status);
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
if(HttpQueryInfoA(request, HTTP_QUERY_CONTENT_LENGTH, length_buf, &length_len, &length_index)) {
length_buf[sizeof(length_buf) - 1] = '\0';
download->total_bytes = (size_t)strtoull(length_buf, NULL, 10);
}
while((read_ok = InternetReadFile(request, buffer, sizeof(buffer), &bytes_read)) && bytes_read > 0) {
if(fwrite(buffer, 1, bytes_read, file) != bytes_read) {
snprintf(download->error, sizeof(download->error), "failed to write %.200s", download->path);
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
download->bytes += (size_t)bytes_read;
}
if(!read_ok) {
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
remove(download->path);
windows_set_last_error(download, "Windows download failed");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
fclose(file);
InternetCloseHandle(request);
InternetCloseHandle(internet);
if(download->total_bytes == 0)
download->total_bytes = download->bytes;
download->status = FLINT_RUNTIME_ASSET_READY;
return 0;
}
#endif
#if defined(FLINT_HAS_LIBCURL) && !defined(__EMSCRIPTEN__)
typedef struct NativeDownloadContext {
FlintRuntimeAssetDownload *download;
@@ -251,7 +375,7 @@ curl_thread_main(void *user_data)
file = fopen(download->path, "wb");
if(file == NULL) {
snprintf(download->error, sizeof(download->error), "failed to open %s", download->path);
snprintf(download->error, sizeof(download->error), "failed to open %.200s", download->path);
download->status = FLINT_RUNTIME_ASSET_ERROR;
return NULL;
}
@@ -348,6 +472,26 @@ flint_runtime_asset_download(FlintRuntimeAssetDownload *download,
emscripten_fetch(&attr, download->url);
return 1;
}
#elif defined(_WIN32)
{
HANDLE thread;
WindowsDownloadContext *ctx = (WindowsDownloadContext *)calloc(1, sizeof(*ctx));
if(ctx == NULL) {
snprintf(download->error, sizeof(download->error), "out of memory");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
ctx->download = download;
thread = CreateThread(NULL, 0, windows_download_thread_main, ctx, 0, NULL);
if(thread == NULL) {
free(ctx);
windows_set_last_error(download, "failed to create download thread");
download->status = FLINT_RUNTIME_ASSET_ERROR;
return 0;
}
CloseHandle(thread);
return 1;
}
#elif defined(FLINT_HAS_LIBCURL)
{
pthread_t thread;
+94 -34
View File
@@ -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;
@@ -2779,25 +2827,22 @@ ui_scrollbar_safe_content_width(int content_x, int content_width,
}
FlintUIScrollView
ui_scroll_container_begin(FlintUIScrollArea area)
ui_scroll_container_measure(FlintUIScrollArea area)
{
static int content_drag_active = 0;
static int content_dragging = 0;
static int content_drag_start_y = 0;
static int content_drag_start_scroll = 0;
FlintUIScrollView view;
Vector2 mouse_world = ui_mouse_world();
int wheel_step = area.wheel_step > 0 ? area.wheel_step : flint_px(42);
int x = (int)area.bounds.x;
int y = (int)area.bounds.y;
int w = (int)area.bounds.width;
int h = (int)area.bounds.height;
int inside = CheckCollisionPointRec(mouse_world, area.bounds);
int captured = ui_input_captures_click(mouse_world);
int drag_threshold = flint_px(5);
int scrollbar_w = flint_px(8);
int scrollbar_x = area.scrollbar_x > 0
? area.scrollbar_x
: x + w - scrollbar_w;
int content_x = area.content_x > 0 ? area.content_x : x;
int content_w = area.content_width > 0 ? area.content_width : w;
memset(&view, 0, sizeof(view));
view.content_x = x;
view.content_x = content_x;
view.viewport_h = h;
view.content_h = area.content_height > 0 ? area.content_height : 0;
view.max_scroll = view.content_h - h;
@@ -2805,19 +2850,39 @@ ui_scroll_container_begin(FlintUIScrollArea area)
view.max_scroll = 0;
if(area.scroll_offset != NULL) {
if(*area.scroll_offset < 0)
*area.scroll_offset = 0;
if(*area.scroll_offset > view.max_scroll)
*area.scroll_offset = view.max_scroll;
int scroll_offset = ui_clampi(*area.scroll_offset, 0, view.max_scroll);
view.content_y = y - scroll_offset;
} else {
view.content_y = y;
}
view.content_w = ui_scrollbar_safe_content_width(content_x, content_w,
scrollbar_x, view.max_scroll);
return view;
}
FlintUIScrollView
ui_scroll_container_begin(FlintUIScrollArea area)
{
static int content_drag_active = 0;
static int content_dragging = 0;
static int content_drag_start_y = 0;
static int content_drag_start_scroll = 0;
FlintUIScrollView view = ui_scroll_container_measure(area);
Vector2 mouse_world = ui_mouse_world();
int y = (int)area.bounds.y;
int wheel_step = area.wheel_step > 0 ? area.wheel_step : flint_px(42);
int inside = CheckCollisionPointRec(mouse_world, area.bounds);
int captured = ui_input_captures_click(mouse_world);
int drag_threshold = flint_px(5);
if(area.scroll_offset != NULL) {
*area.scroll_offset = ui_clampi(*area.scroll_offset, 0, view.max_scroll);
if(view.max_scroll > 0 && inside && !captured) {
float wheel = GetMouseWheelMove();
if(wheel != 0.0f) {
*area.scroll_offset -= (int)(wheel * (float)wheel_step);
if(*area.scroll_offset < 0)
*area.scroll_offset = 0;
if(*area.scroll_offset > view.max_scroll)
*area.scroll_offset = view.max_scroll;
*area.scroll_offset = ui_clampi(*area.scroll_offset, 0, view.max_scroll);
}
}
@@ -2849,10 +2914,7 @@ ui_scroll_container_begin(FlintUIScrollArea area)
g_ui_pointer_owner = UI_POINTER_OWNER_SCROLL;
content_dragging = 1;
*area.scroll_offset = content_drag_start_scroll - dy;
if(*area.scroll_offset < 0)
*area.scroll_offset = 0;
if(*area.scroll_offset > view.max_scroll)
*area.scroll_offset = view.max_scroll;
*area.scroll_offset = ui_clampi(*area.scroll_offset, 0, view.max_scroll);
ui_set_input_blocked(1);
}
} else if(content_drag_active) {
@@ -2865,8 +2927,6 @@ ui_scroll_container_begin(FlintUIScrollArea area)
} else {
view.content_y = y;
}
view.content_w = ui_scrollbar_content_width(w, view.max_scroll);
{
Rectangle screen_bounds = {
g_ui_camera.offset.x + area.bounds.x * g_ui_camera.zoom,
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Vyzkoušet přehrání
[meditation_music_stop_test_button]
Zastavit test
---
[meditation_music_network_error_title]
Síť není dostupná
---
[meditation_music_network_error_message]
Nelze se připojit k serveru s meditačním audiem. Zkontrolujte síťová oprávnění Androidu a připojení k internetu a zkuste to znovu.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ Uložit dokončená kola před ukončením?
[cancel_button]
Zrušit
---
[ok_button]
OK
---
[save_button]
Uložit
---
@@ -294,6 +306,9 @@ Importovat data
[import_failed]
Import selhal
---
[imported_data]
Data importována
---
[imported_sessions]
Importováno %d sezení
---
@@ -303,6 +318,18 @@ Neplatný exportní soubor
[import_cancelled]
Import zrušen
---
[import_choice_title]
Importovat nastavení?
---
[import_choice_message]
Nalezeny data a nastavení.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Nastavení
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Smazat toto kolo? Tuto akci nelze vrátit.
[delete_button]
Smazat
---
[meditation_music_attribution]
Hudba od Elijah_K.
---
[theme_system]
Systém
---
[orientation_label]
Orientace
---
[orientation_system]
Systém
---
[orientation_portrait]
Na výšku
---
[orientation_landscape]
Na šířku
---
[orientation_sensor]
Senzor
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Testwiedergabe
[meditation_music_stop_test_button]
Test stoppen
---
[meditation_music_network_error_title]
Netzwerk nicht verfügbar
---
[meditation_music_network_error_message]
Der Meditations-Audioserver konnte nicht erreicht werden. Prüfe die Android-Netzwerkberechtigungen und deine Internetverbindung und versuche es erneut.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ Abgeschlossene Runden vor dem Beenden speichern?
[cancel_button]
Abbrechen
---
[ok_button]
OK
---
[save_button]
Speichern
---
@@ -294,6 +306,9 @@ Daten importieren
[import_failed]
Import fehlgeschlagen
---
[imported_data]
Daten importiert
---
[imported_sessions]
%d Sitzungen importiert
---
@@ -303,6 +318,18 @@ Ungültige Exportdatei
[import_cancelled]
Import cancelled
---
[import_choice_title]
Einstellungen importieren?
---
[import_choice_message]
Daten und Einstellungen gefunden.
---
[import_data_only_button]
Daten
---
[import_data_settings_button]
Daten+Einstellungen
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Diese Runde löschen? Das kann nicht rückgängig gemacht werden.
[delete_button]
Löschen
---
[meditation_music_attribution]
Musik von Elijah_K.
---
[theme_system]
System
---
[orientation_label]
Ausrichtung
---
[orientation_system]
System
---
[orientation_portrait]
Hochformat
---
[orientation_landscape]
Querformat
---
[orientation_sensor]
Sensor
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+157 -16
View File
@@ -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
@@ -70,6 +73,12 @@ Test audio
[meditation_music_stop_test_button]
Stop test
---
[meditation_music_network_error_title]
Network unavailable
---
[meditation_music_network_error_message]
Could not reach the meditation audio server. Check Android network permissions and your internet connection, then try again.
---
[meditation_music_attribution]
Music by Elijah_K.
---
@@ -106,6 +115,9 @@ Save completed rounds before exit?
[cancel_button]
Cancel
---
[ok_button]
OK
---
[save_button]
Save
---
@@ -315,6 +327,9 @@ Import Data
[import_failed]
Import failed
---
[imported_data]
Imported data
---
[imported_sessions]
Imported %d sessions
---
@@ -324,6 +339,18 @@ Invalid export file
[import_cancelled]
Import cancelled
---
[import_choice_title]
Import settings?
---
[import_choice_message]
Data and settings found.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Settings
---
[export_cancelled]
Export cancelled
---
@@ -391,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.
@@ -413,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
@@ -467,3 +490,121 @@ Delete this round? This cannot be undone.
[delete_button]
Delete
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Probar reproducción
[meditation_music_stop_test_button]
Detener prueba
---
[meditation_music_network_error_title]
Red no disponible
---
[meditation_music_network_error_message]
No se pudo acceder al servidor de audio de meditación. Revisa los permisos de red de Android y tu conexión a internet, e inténtalo de nuevo.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ INICIO
[cancel_button]
Cancelar
---
[ok_button]
Aceptar
---
[save_button]
Guardar
---
@@ -294,6 +306,9 @@ Importar datos
[import_failed]
Error al importar
---
[imported_data]
Datos importados
---
[imported_sessions]
%d sesiones importadas
---
@@ -303,6 +318,18 @@ Archivo de exportación no válido
[import_cancelled]
Import cancelled
---
[import_choice_title]
¿Importar ajustes?
---
[import_choice_message]
Datos y ajustes encontrados.
---
[import_data_only_button]
Datos
---
[import_data_settings_button]
Datos+Ajustes
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Recuento de sesiones: %d
[delete_button]
Eliminar
---
[meditation_music_attribution]
Música de Elijah_K.
---
[theme_system]
Sistema
---
[orientation_label]
Orientación
---
[orientation_system]
Sistema
---
[orientation_portrait]
Vertical
---
[orientation_landscape]
Horizontal
---
[orientation_sensor]
Sensor
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Tester la lecture
[meditation_music_stop_test_button]
Arrêter le test
---
[meditation_music_network_error_title]
Réseau indisponible
---
[meditation_music_network_error_message]
Impossible de joindre le serveur audio de méditation. Vérifiez les autorisations réseau d'Android et votre connexion internet, puis réessayez.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ Enregistrer les cycles terminés avant de quitter ?
[cancel_button]
Annuler
---
[ok_button]
OK
---
[save_button]
Enregistrer
---
@@ -294,6 +306,9 @@ Importer les données
[import_failed]
Échec de l'import
---
[imported_data]
Données importées
---
[imported_sessions]
%d sessions importées
---
@@ -303,6 +318,18 @@ Fichier d'export invalide
[import_cancelled]
Import annulé
---
[import_choice_title]
Importer les réglages ?
---
[import_choice_message]
Données et réglages trouvés.
---
[import_data_only_button]
Données
---
[import_data_settings_button]
Données+Réglages
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Supprimer ce cycle ? Cette action est irréversible.
[delete_button]
Supprimer
---
[meditation_music_attribution]
Musique par Elijah_K.
---
[theme_system]
Système
---
[orientation_label]
Orientation
---
[orientation_system]
Système
---
[orientation_portrait]
Portrait
---
[orientation_landscape]
Paysage
---
[orientation_sensor]
Capteur
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Coba putar
[meditation_music_stop_test_button]
Hentikan tes
---
[meditation_music_network_error_title]
Jaringan tidak tersedia
---
[meditation_music_network_error_message]
Tidak dapat menjangkau server audio meditasi. Periksa izin jaringan Android dan koneksi internetmu, lalu coba lagi.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ Simpan ronde yang selesai sebelum keluar?
[cancel_button]
Batal
---
[ok_button]
OK
---
[save_button]
Simpan
---
@@ -294,6 +306,9 @@ Impor Data
[import_failed]
Impor gagal
---
[imported_data]
Data diimpor
---
[imported_sessions]
Mengimpor %d sesi
---
@@ -303,6 +318,18 @@ File ekspor tidak valid
[import_cancelled]
Impor dibatalkan
---
[import_choice_title]
Impor pengaturan?
---
[import_choice_message]
Data dan pengaturan ditemukan.
---
[import_data_only_button]
Data
---
[import_data_settings_button]
Data+Pengaturan
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Hapus ronde ini? Tidak dapat dibatalkan.
[delete_button]
Hapus
---
[meditation_music_attribution]
Musik oleh Elijah_K.
---
[theme_system]
Sistem
---
[orientation_label]
Orientasi
---
[orientation_system]
Sistem
---
[orientation_portrait]
Potret
---
[orientation_landscape]
Lanskap
---
[orientation_sensor]
Sensor
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+162 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Test audio
[meditation_music_stop_test_button]
Ferma test
---
[meditation_music_network_error_title]
Rete non disponibile
---
[meditation_music_network_error_message]
Impossibile raggiungere il server audio per la meditazione. Controlla le autorizzazioni di rete di Android e la connessione a internet, poi riprova.
---
[duration_5m]
5 min
---
@@ -103,6 +112,9 @@ Salvare i round completati prima di uscire?
[cancel_button]
Annulla
---
[ok_button]
OK
---
[save_button]
Salva
---
@@ -310,6 +322,9 @@ Importa Dati
[import_failed]
Importazione fallita
---
[imported_data]
Dati importati
---
[imported_sessions]
Importate %d sessioni
---
@@ -319,6 +334,18 @@ File di esportazione non valido
[import_cancelled]
Importazione annullata
---
[import_choice_title]
Importare impostazioni?
---
[import_choice_message]
Dati e impostazioni trovati.
---
[import_data_only_button]
Dati
---
[import_data_settings_button]
Dati+Impostazioni
---
[export_cancelled]
Esportazione annullata
---
@@ -386,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.
@@ -408,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
@@ -462,3 +485,124 @@ Eliminare questo round? Questa azione non può essere annullata.
[delete_button]
Elimina
---
[meditation_music_attribution]
Musica di Elijah_K.
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+182 -13
View File
@@ -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]
瞑想音楽
@@ -70,6 +73,12 @@
[meditation_music_stop_test_button]
テスト停止
---
[meditation_music_network_error_title]
ネットワークを利用できません
---
[meditation_music_network_error_message]
瞑想音声サーバーに接続できませんでした。Android のネットワーク権限とインターネット接続を確認してから、もう一度お試しください。
---
[duration_5m]
5分
---
@@ -103,6 +112,9 @@
[cancel_button]
キャンセル
---
[ok_button]
OK
---
[save_button]
保存
---
@@ -294,6 +306,9 @@ In / Out
[import_failed]
インポートに失敗しました
---
[imported_data]
データをインポートしました
---
[imported_sessions]
%dセッションをインポートしました
---
@@ -303,6 +318,18 @@ In / Out
[import_cancelled]
Import cancelled
---
[import_choice_title]
設定もインポートしますか?
---
[import_choice_message]
データと設定があります。
---
[import_data_only_button]
データ
---
[import_data_settings_button]
データ+設定
---
[export_cancelled]
Export cancelled
---
@@ -372,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]
スキップ
@@ -439,3 +468,143 @@ Inner Breeze データ書き出し
---
[delete_button]
削除
---
[meditation_music_attribution]
音楽: Elijah_K.
---
[theme_system]
システム
---
[orientation_label]
向き
---
[orientation_system]
システム
---
[orientation_portrait]
縦向き
---
[orientation_landscape]
横向き
---
[orientation_sensor]
センサー
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+162 -18
View File
@@ -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]
명상 음악
@@ -70,6 +73,12 @@ Inner Breeze
[meditation_music_stop_test_button]
테스트 중지
---
[meditation_music_network_error_title]
네트워크를 사용할 수 없음
---
[meditation_music_network_error_message]
명상 오디오 서버에 연결할 수 없습니다. Android 네트워크 권한과 인터넷 연결을 확인한 뒤 다시 시도하세요.
---
[duration_5m]
5분
---
@@ -103,6 +112,9 @@ Inner Breeze
[cancel_button]
취소
---
[ok_button]
확인
---
[save_button]
저장
---
@@ -310,6 +322,9 @@ In / Out
[import_failed]
가져오기 실패
---
[imported_data]
데이터를 가져왔습니다
---
[imported_sessions]
%d개 세션을 가져왔습니다
---
@@ -319,6 +334,18 @@ In / Out
[import_cancelled]
가져오기 취소됨
---
[import_choice_title]
설정을 가져올까요?
---
[import_choice_message]
데이터와 설정을 찾았습니다.
---
[import_data_only_button]
데이터
---
[import_data_settings_button]
데이터+설정
---
[export_cancelled]
내보내기 취소됨
---
@@ -385,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]
점진적 속도는 첫 라운드를 쉽게 시작할 수 있게 해줍니다.
@@ -407,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]
건너뛰기
@@ -461,3 +484,124 @@ Inner Breeze 데이터 내보내기
[delete_button]
삭제
---
[meditation_music_attribution]
음악: Elijah_K.
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+180 -18
View File
@@ -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
@@ -70,6 +73,12 @@ Testar reprodução
[meditation_music_stop_test_button]
Parar teste
---
[meditation_music_network_error_title]
Rede indisponível
---
[meditation_music_network_error_message]
Não foi possível acessar o servidor de áudio de meditação. Verifique as permissões de rede do Android e sua conexão com a internet, depois tente novamente.
---
[duration_5m]
5m
---
@@ -103,6 +112,9 @@ Salvar rodadas concluídas antes de sair?
[cancel_button]
Cancelar
---
[ok_button]
OK
---
[save_button]
Salvar
---
@@ -294,6 +306,9 @@ Importar dados
[import_failed]
Falha ao importar
---
[imported_data]
Dados importados
---
[imported_sessions]
%d sessões importadas
---
@@ -303,6 +318,18 @@ Arquivo de exportação inválido
[import_cancelled]
Importação cancelada
---
[import_choice_title]
Importar configurações?
---
[import_choice_message]
Dados e configurações encontrados.
---
[import_data_only_button]
Dados
---
[import_data_settings_button]
Dados+Config.
---
[export_cancelled]
Export cancelled
---
@@ -370,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.
@@ -392,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
@@ -446,3 +469,142 @@ Excluir esta rodada? Isso não pode ser desfeito.
[delete_button]
Excluir
---
[meditation_music_attribution]
Música por Elijah_K.
---
[theme_system]
Sistema
---
[orientation_label]
Orientação
---
[orientation_system]
Sistema
---
[orientation_portrait]
Retrato
---
[orientation_landscape]
Paisagem
---
[orientation_sensor]
Sensor
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+182 -13
View File
@@ -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]
冥想音乐
@@ -70,6 +73,12 @@ Wim Hof 呼吸
[meditation_music_stop_test_button]
停止测试
---
[meditation_music_network_error_title]
网络不可用
---
[meditation_music_network_error_message]
无法连接到冥想音频服务器。请检查 Android 网络权限和互联网连接,然后重试。
---
[duration_5m]
5分钟
---
@@ -103,6 +112,9 @@ Wim Hof 呼吸
[cancel_button]
取消
---
[ok_button]
确定
---
[save_button]
保存
---
@@ -294,6 +306,9 @@ In / Out
[import_failed]
导入失败
---
[imported_data]
数据已导入
---
[imported_sessions]
已导入 %d 个会话
---
@@ -303,6 +318,18 @@ In / Out
[import_cancelled]
Import cancelled
---
[import_choice_title]
导入设置?
---
[import_choice_message]
找到数据和设置。
---
[import_data_only_button]
数据
---
[import_data_settings_button]
数据+设置
---
[export_cancelled]
Export cancelled
---
@@ -370,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]
跳过
@@ -437,3 +466,143 @@ Inner Breeze 数据导出
---
[delete_button]
删除
---
[meditation_music_attribution]
音乐来自 Elijah_K。
---
[theme_system]
系统
---
[orientation_label]
方向
---
[orientation_system]
系统
---
[orientation_portrait]
竖屏
---
[orientation_landscape]
横屏
---
[orientation_sensor]
传感器
---
[back_button]
Back
---
[close_button]
Close
---
[sync_account_title]
Account
---
[sync_configure_account_button]
Configure Account
---
[sync_create_account_button]
Create Account
---
[sync_account_created]
Account created
---
[sync_account_create_failed]
Could not create account
---
[sync_import_key_button]
Import .key File
---
[sync_import_key_dialog_title]
Import Account Key
---
[sync_private_key_imported]
Account key imported
---
[sync_private_key_import_failed]
Could not import account key
---
[sync_private_key_import_cancelled]
Account key import cancelled
---
[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 connecting
---
[sync_auth_failed]
Remote rejected this account
---
[sync_backup_warning]
Save this private key somewhere you control. Anyone with it can claim this account.
---
[sync_backup_title]
Backup Account Key
---
[sync_save_key_file_button]
Save .key File
---
[sync_save_key_dialog_title]
Save Account Key
---
[sync_private_key_backup_saved]
Account key backup saved
---
[sync_private_key_backup_failed]
Could not save account key backup
---
[sync_private_key_backup_cancelled]
Account key backup cancelled
---
[sync_delete_account_button]
Delete Account
---
[sync_delete_account_title]
Delete Account?
---
[sync_delete_account_message]
Delete this account from the remote server and this device? This cannot be undone.
---
[sync_account_deleted]
Account deleted
---
[sync_account_delete_cancelled]
Account deletion cancelled
---
+3 -2
View File
@@ -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 \
+156 -611
View File
File diff suppressed because it is too large. Load diff
+48 -35
View File
@@ -59,6 +59,10 @@ typedef enum {
UIModalConfirmDeleteData,
UIModalConfirmDeleteHabit,
UIModalEditProgressiveStartSpeed,
UIModalMeditationNetworkError,
UIModalConfirmImportDataSettings,
UIModalSyncAccountBackup,
UIModalConfirmDeleteSyncAccount,
} UIModalType;
typedef struct {
@@ -77,15 +81,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,
@@ -94,7 +89,7 @@ typedef enum HoldDisplayMode {
typedef enum ExerciseType {
EXERCISE_WIM_HOF = 0,
EXERCISE_MEDITATION = 1,
EXERCISE_COUNT
EXERCISE_COUNT = 2
} ExerciseType;
typedef enum AppThemeMode {
@@ -121,6 +116,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;
@@ -131,8 +150,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;
@@ -153,6 +172,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;
@@ -176,9 +199,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;
@@ -199,6 +219,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;
@@ -212,20 +239,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;
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;
@@ -234,16 +247,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 reset_settings_preview(InbeApp *app);
void app_reload_after_import(InbeApp *app, int reload_settings);
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);
@@ -251,7 +264,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
+298
View File
@@ -0,0 +1,298 @@
#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 Module.__inbeScheduleStorageSync === 'function')
Module.__inbeScheduleStorageSync(250, true);
});
}
#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;
}
+12
View File
@@ -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
-12
View File
@@ -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
+3 -3
View File
@@ -2,8 +2,8 @@
#define INBE_VERSION_H
#define INBE_VERSION_MAJOR 1
#define INBE_VERSION_MINOR 3
#define INBE_VERSION_PATCH 0
#define INBE_VERSION_STRING "1.3.0"
#define INBE_VERSION_MINOR 4
#define INBE_VERSION_PATCH 1
#define INBE_VERSION_STRING "1.4.1"
#endif
+14 -4
View File
@@ -31,7 +31,7 @@ android_import_set_result(int result, const char *path)
}
int
android_import_open_picker(void)
android_import_open_picker(const char *mime_types)
{
struct android_app *app = GetAndroidApp();
if(app == NULL || app->activity == NULL) {
@@ -55,14 +55,23 @@ android_import_open_picker(void)
return 0;
}
jmethodID method = (*env)->GetMethodID(env, activity_class, "openImportPicker", "()V");
jmethodID method = (*env)->GetMethodID(env, activity_class, "openImportPicker",
"(Ljava/lang/String;)V");
if(method == NULL) {
TraceLog(LOG_ERROR, "ANDROID_IMPORT: openImportPicker method not found");
(*jvm)->DetachCurrentThread(jvm);
return 0;
}
(*env)->CallVoidMethod(env, activity->clazz, method);
jstring mime_string = (*env)->NewStringUTF(env, mime_types != NULL ? mime_types : "");
if(mime_string == NULL) {
TraceLog(LOG_ERROR, "ANDROID_IMPORT: failed to allocate MIME string");
(*jvm)->DetachCurrentThread(jvm);
return 0;
}
(*env)->CallVoidMethod(env, activity->clazz, method, mime_string);
(*env)->DeleteLocalRef(env, mime_string);
if((*env)->ExceptionCheck(env)) {
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
@@ -124,8 +133,9 @@ android_import_poll_result(char *path, size_t path_size)
#else
int
android_import_open_picker(void)
android_import_open_picker(const char *mime_types)
{
(void)mime_types;
return 0;
}
+1 -1
View File
@@ -3,7 +3,7 @@
#include <stddef.h>
int android_import_open_picker(void);
int android_import_open_picker(const char *mime_types);
int android_import_poll_result(char *path, size_t path_size);
enum {
+95
View File
@@ -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
+4
View File
@@ -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
+4 -3
View File
@@ -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);
}
@@ -63,6 +63,20 @@ safe_archive_member(const char *path)
return 1;
}
static int
known_track_archive_member(const char *path)
{
if(path == NULL)
return 0;
for(int i = 0; i < MEDITATION_MUSIC_TRACK_COUNT; i++) {
if(strcmp(path, g_tracks[i].file) == 0)
return 1;
}
return 0;
}
static int
copy_text_checked(char *out, size_t out_size, const char *text)
{
@@ -129,11 +143,55 @@ 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)
{
const char *error;
if(download == NULL)
return 0;
error = download->error;
if(error == NULL || error[0] == '\0')
return 0;
if(strcmp(error, "NETWORK_UNAVAILABLE") == 0)
return 1;
if(strstr(error, "Unable to resolve host") != NULL ||
strstr(error, "No address associated with hostname") != NULL ||
strstr(error, "Could not resolve host") != NULL ||
strstr(error, "Couldn't resolve host") != NULL ||
strstr(error, "Name or service not known") != NULL ||
strstr(error, "Temporary failure in name resolution") != NULL)
return 1;
return 0;
}
static void
format_download_status(char *out, size_t out_size,
const FlintRuntimeAssetDownload *download)
@@ -169,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;
@@ -226,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");
}
@@ -243,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;
@@ -264,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");
@@ -284,8 +342,10 @@ extract_audio_archive(InbeApp *app, const char *archive_path)
continue;
if(!safe_archive_member(stat.m_filename))
continue;
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;
@@ -306,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;
}
@@ -334,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;
@@ -347,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");
}
}
@@ -368,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
@@ -382,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
@@ -395,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");
}
@@ -422,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;
@@ -435,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;
}
@@ -453,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
@@ -477,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))) {
@@ -485,20 +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(app->meditation_music_download.error[0] != '\0')
set_status(app, app->meditation_music_download.error);
} 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) {
app->modal.active = 1;
app->modal.type = UIModalMeditationNetworkError;
app->modal.selected_button = 0;
app->meditation.music_network_error_notified = 1;
}
} 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);
}
}
@@ -511,16 +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_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);
@@ -534,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);
}
@@ -565,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);
@@ -578,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);
@@ -592,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);
}
}
@@ -620,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);
@@ -641,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);
}
}
+110
View File
@@ -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);
}
+40
View File
@@ -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
+418
View File
@@ -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);
}
+355
View File
@@ -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);
}
}
+39
View File
@@ -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;
}
+14
View File
@@ -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"
+484 -40
View File
@@ -16,14 +16,20 @@
#include <string.h>
#include <time.h>
#if defined(PLATFORM_WEB)
#include <emscripten.h>
#endif
/* External declarations from app.c */
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 +49,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 +58,146 @@ 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_web_context_click_in_bounds(InbeApp *app, Rectangle bounds)
{
#if defined(PLATFORM_WEB)
Vector2 top_left;
Vector2 bottom_right;
if(app == NULL)
return 0;
top_left = GetWorldToScreen2D((Vector2){bounds.x, bounds.y}, app->camera);
bottom_right = GetWorldToScreen2D((Vector2){bounds.x + bounds.width,
bounds.y + bounds.height}, app->camera);
return EM_ASM_INT({
const click = Module.__inbeContextClick;
if(!click)
return 0;
if(Date.now() - click.time > 750) {
Module.__inbeContextClick = null;
return 0;
}
if(click.x >= $0 && click.x <= $2 && click.y >= $1 && click.y <= $3) {
Module.__inbeContextClick = null;
return 1;
}
return 0;
}, (int)top_left.x, (int)top_left.y, (int)bottom_right.x, (int)bottom_right.y);
#else
(void)app;
(void)bounds;
return 0;
#endif
}
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)) ||
habit_web_context_click_in_bounds(app, bounds))
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 +213,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 +251,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 +281,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 +297,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 +333,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 +356,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 +394,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 +443,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 +572,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 +592,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 +608,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 +652,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 +669,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 +826,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 +855,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 +1028,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 +1098,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 +1119,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 +1164,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 +1189,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 +1228,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 +1241,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 +1278,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);
@@ -1216,10 +1543,13 @@ draw_habits_screen(InbeApp *app)
scroll_h = 0;
scroll_area = (FlintUIScrollArea){
.bounds = {(float)content_x, (float)scroll_y, (float)content_w, (float)scroll_h},
.bounds = {0.0f, (float)scroll_y, (float)view_width, (float)scroll_h},
.content_height = scroll_content_h,
.content_x = content_x,
.content_width = content_w,
.scroll_offset = &app->habits.scroll,
.wheel_step = flint_px(42)
.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;
@@ -1274,6 +1604,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));
@@ -1284,10 +1618,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) {
@@ -1295,11 +1647,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);
}
@@ -1413,8 +1785,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;
@@ -1465,10 +1839,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);
@@ -1540,10 +1934,13 @@ draw_habit_session_edit_screen(InbeApp *app)
flint_centered_column(max_w, side_padding, &content_x, &content_w);
content_h = draw_habit_session_edit_content(app, &ctx, content_x, content_w, y, 0) - y;
scroll_area = (FlintUIScrollArea){
.bounds = {(float)content_x, (float)y, (float)content_w, (float)viewport_h},
.bounds = {0.0f, (float)y, (float)view_width, (float)viewport_h},
.content_height = content_h,
.content_x = content_x,
.content_width = content_w,
.scroll_offset = &app->habit_session_edit_scroll,
.wheel_step = flint_px(42)
.wheel_step = flint_px(42),
.scrollbar_x = view_width - flint_px(8)
};
scroll_view = ui_scroll_container_begin(scroll_area);
draw_habit_session_edit_content(app, &ctx, scroll_view.content_x, scroll_view.content_w,
@@ -1698,6 +2095,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;
}
+9 -5
View File
@@ -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);
+12 -465
View File
@@ -1,489 +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);
}
#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 = flint_px(520);
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(),
};
scroll_area = (FlintUIScrollArea){
.bounds = {(float)content_x, (float)content_y,
(float)content_w, (float)content_h},
.content_height = content_total_h,
.scroll_offset = &app->manual_scroll,
.wheel_step = flint_px(42)
};
scroll_view = ui_scroll_container_begin(scroll_area);
y = scroll_view.content_y;
meditation_music_draw_guide_settings(app, content_x, content_w, &y);
y += flint_px(34);
flint_ui_paragraph_draw(paragraph, 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;
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);
/* Calculate actual content height based on current step and text layouts */
/* Don't include padding in this calculation - it's handled separately */
int actual_content_h = 0; /* Content only, no padding */
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) {
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font) + flint_px(20);
/* Circle preview height - calculate actual rmax based on content_w */
/* update_preview_bounds uses min(content_w, 132)/2 clamped to 60-120 for rmax */
int preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
int 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);
/* Circle is drawn at y+flint_px(40) with radius 0.72*preview_rmax */
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
int slider_h = flint_px(40);
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);
}
/* Calculate scroll range for virtual content space */
int top_padding = flint_px(16);
int total_content_h = actual_content_h + top_padding;
int viewport_content_h = content_area_h;
int max_scroll = total_content_h - viewport_content_h;
if(max_scroll < 0)
max_scroll = 0;
/* Reset scroll position if content now fits in viewport */
if(max_scroll == 0) {
app->manual_scroll = 0;
}
/* Clamp scroll position to new max */
app->manual_scroll = clampi(app->manual_scroll, 0, max_scroll);
app->manual_scroll -= (int)(GetMouseWheelMove() * 24.0f);
app->manual_scroll = clampi(app->manual_scroll, 0, max_scroll);
/* Handle content area drag scrolling */
static int content_drag_active = 0;
static int content_drag_start_y = 0;
static int content_drag_start_scroll = 0;
Vector2 mouse_pos = GetMousePosition();
int content_area_y = title_h;
Rectangle content_bounds = {content_x, content_area_y, content_w, content_area_h};
if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
if(!content_drag_active) {
/* Start drag if clicking in content area */
if(CheckCollisionPointRec(mouse_pos, content_bounds)) {
content_drag_active = 1;
content_drag_start_y = (int)mouse_pos.y;
content_drag_start_scroll = app->manual_scroll;
}
} else {
/* Continue drag */
int dy = (int)mouse_pos.y - content_drag_start_y;
app->manual_scroll = content_drag_start_scroll - dy;
app->manual_scroll = clampi(app->manual_scroll, 0, max_scroll);
}
} else {
content_drag_active = 0;
}
flint_clip_begin((int)app->camera.offset.x,
(int)(app->camera.offset.y + title_h * app->camera.zoom),
(int)(view_width * app->camera.zoom),
(int)(content_area_h * app->camera.zoom));
int y = title_h + flint_px(16) - app->manual_scroll;
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);
}
flint_clip_end();
/* Draw scrollbar if content overflows */
if(max_scroll > 0) {
/* Transform world coordinates to screen coordinates for scrollbar function */
int scrollbar_x = (int)(app->camera.offset.x + (content_x + content_w + flint_px(4)) * app->camera.zoom);
int scrollbar_y = (int)(app->camera.offset.y + title_h * app->camera.zoom);
int scrollbar_viewport = (int)(content_area_h * app->camera.zoom); /* Scaled by camera zoom */
int total_content_screen_h = (int)(total_content_h * app->camera.zoom); /* Also scaled for ratio calculations */
ui_draw_scrollbar(scrollbar_x, scrollbar_y, scrollbar_viewport, total_content_screen_h,
&app->manual_scroll, max_scroll);
}
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);
}
+7 -16
View File
@@ -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);
}
+817
View File
@@ -0,0 +1,817 @@
#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,
SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT
};
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"
#define SETTINGS_DATA_IMPORT_FILTER ".db,.zip"
#define SETTINGS_SYNC_KEY_IMPORT_FILTER ".key"
#define SETTINGS_ANDROID_DATA_IMPORT_MIME_TYPES "application/zip,application/x-zip-compressed,application/vnd.sqlite3,application/x-sqlite,application/x-sqlite3,application/octet-stream"
#define SETTINGS_ANDROID_SYNC_KEY_IMPORT_MIME_TYPES "text/plain,application/octet-stream"
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
static FlintFileDialog export_dlg;
static FlintFileDialog import_dlg;
#endif
#if defined(INBE_HAS_FLINT_FILE_DIALOG) || defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
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 int settings_import_sync_key_path(InbeApp *app, const char *path);
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 int
settings_start_sync_key_import_dialog(InbeApp *app)
{
#if defined(PLATFORM_WEB)
(void)app;
EM_ASM({
const importPath = UTF8ToString($0);
Module.__inbeSyncKeyImportResult = 0;
const input = document.createElement("input");
input.type = "file";
input.accept = SETTINGS_SYNC_KEY_IMPORT_FILTER;
input.style.display = "none";
input.onchange = async function() {
try {
if(!input.files || input.files.length === 0) {
Module.__inbeSyncKeyImportResult = 2;
return;
}
const file = input.files[0];
const bytes = new Uint8Array(await file.arrayBuffer());
try {
FS.mkdirTree("/tmp");
} catch(e) {}
try {
FS.unlink(importPath);
} catch(e) {}
FS.writeFile(importPath, bytes);
Module.__inbeSyncKeyImportResult = 1;
} catch(e) {
console.error("Inbe sync key import failed:", e);
Module.__inbeSyncKeyImportResult = 3;
} finally {
input.remove();
}
};
document.body.appendChild(input);
input.click();
}, "/tmp/inbe-sync-key-import.key");
settings_screen_set_status_success(locale_get("sync_import_key_dialog_title"), NULL);
return 1;
#elif defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
(void)app;
data_file_dialog_action = SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT;
if(android_import_open_picker(SETTINGS_ANDROID_SYNC_KEY_IMPORT_MIME_TYPES)) {
settings_screen_set_status_success(locale_get("sync_import_key_dialog_title"), NULL);
return 1;
}
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
return 0;
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
settings_apply_file_dialog_theme(app);
flint_file_dialog_begin_load_filtered(&import_dlg, locale_get("sync_import_key_dialog_title"),
SETTINGS_SYNC_KEY_IMPORT_FILTER);
data_file_dialog_action = SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT;
return 1;
#else
(void)app;
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);
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);
settings_sync_account_set_import_dialog(settings_start_sync_key_import_dialog);
if(app != NULL && app->settings_data_view == SETTINGS_DATA_VIEW_SYNC_ACCOUNT) {
settings_sync_account_draw_config(app, x, w, y);
return;
}
if(ui_draw_generic_button(x, *y, w, data_button_h,
locale_get("sync_configure_account_button"),
UI_BUTTON_STYLE_PRIMARY, 0, &hover_account))
settings_open_sync_account_config(app);
*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) {
if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT)
settings_screen_set_status_error(locale_get("sync_private_key_import_cancelled"));
else
settings_screen_set_status_error(locale_get("import_cancelled"));
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
return;
}
if(import_path[0] == '\0') {
if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT)
settings_screen_set_status_error(locale_get("sync_private_key_import_failed"));
else
settings_screen_set_status_error(locale_get("import_invalid_file"));
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
return;
}
if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT)
settings_import_sync_key_path(app, import_path);
else
settings_begin_import_for_path(app, import_path);
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
}
#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"
#define SETTINGS_WEB_SYNC_KEY_IMPORT_PATH "/tmp/inbe-sync-key-import.key"
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.mkdirTree("/tmp");
} catch(e) {}
try {
FS.unlink(importPath);
} 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 == 2) {
settings_screen_set_status_error(locale_get("import_cancelled"));
} else if(import_result != 0 && import_result != 1) {
settings_screen_set_status_error(locale_get("import_failed"));
} else if(import_result == 1) {
settings_begin_import_for_path(app, SETTINGS_WEB_IMPORT_PATH);
}
import_result = EM_ASM_INT({
const result = Module.__inbeSyncKeyImportResult || 0;
if(result !== 0)
Module.__inbeSyncKeyImportResult = 0;
return result;
});
if(import_result == 0)
return;
if(import_result == 2) {
settings_screen_set_status_error(locale_get("sync_private_key_import_cancelled"));
return;
}
if(import_result != 1) {
settings_screen_set_status_error(locale_get("sync_private_key_import_failed"));
return;
}
settings_import_sync_key_path(app, SETTINGS_WEB_SYNC_KEY_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)
data_file_dialog_action = SETTINGS_DATA_ACTION_IMPORT;
if(android_import_open_picker(SETTINGS_ANDROID_DATA_IMPORT_MIME_TYPES))
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
else {
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
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_filtered(&import_dlg, locale_get("import_data_dialog_title"),
SETTINGS_DATA_IMPORT_FILTER);
data_file_dialog_action = SETTINGS_DATA_ACTION_IMPORT;
#else
(void)app;
settings_screen_set_status_error(locale_get("import_failed"));
#endif
}
static int
settings_import_sync_key_path(InbeApp *app, const char *path)
{
InbeSyncAccount account;
if(path != NULL && path[0] != '\0' &&
inbe_sync_account_import_private_key(&account, path)) {
settings_screen_set_status_success(locale_get("sync_private_key_imported"), NULL);
TraceLog(LOG_INFO, "SYNC: Private key imported from %s", path);
(void)app;
return 1;
}
settings_screen_set_status_error(locale_get("sync_private_key_import_failed"));
TraceLog(LOG_ERROR, "SYNC: Private key import failed");
(void)app;
return 0;
}
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"));
}
} else if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_IMPORT) {
if(result == 1) {
const char *path = flint_file_dialog_get_path(&import_dlg);
settings_import_sync_key_path(app, path);
} else {
settings_screen_set_status_error(locale_get("sync_private_key_import_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 == UIModalConfirmDeleteSyncAccount) {
int modal_result = ui_draw_modal(locale_get("sync_delete_account_title"),
locale_get("sync_delete_account_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("sync_account_delete_cancelled"));
} else if(modal_result == 2) {
app->modal.active = 0;
app->modal.type = UIModalNone;
settings_sync_account_delete_confirmed(app);
}
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;
}
+14
View File
@@ -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
+142
View File
@@ -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);
}
}
+17
View File
@@ -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
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -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,446 @@
#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;
static SettingsSyncKeyImportDialog import_dialog_callback = NULL;
void
settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback)
{
save_dialog_callback = callback;
}
void
settings_sync_account_set_import_dialog(SettingsSyncKeyImportDialog callback)
{
import_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_start_sync_key_import(InbeApp *app)
{
if(import_dialog_callback != NULL)
return import_dialog_callback(app);
return 0;
}
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)));
}
}
void
settings_sync_account_delete_confirmed(InbeApp *app)
{
InbeSyncAccount account;
InbeSyncClientResult result;
char url[sizeof(app->sync_server_url)];
if(app == NULL)
return;
if(!inbe_sync_account_load(&account)) {
settings_screen_set_status_error(locale_get("sync_no_account"));
return;
}
if(settings_sync_server_normalize(app, url, sizeof(url))) {
result = inbe_sync_client_delete_account(url);
if(result != INBE_SYNC_CLIENT_OK)
TraceLog(LOG_WARNING, "SYNC: remote account delete failed: %d", result);
} else {
TraceLog(LOG_WARNING, "SYNC: remote account delete skipped due to invalid URL");
}
inbe_sync_account_clear();
inbe_storage_set_setting_int(INBE_SYNC_ENABLED_KEY, 0);
inbe_storage_set_setting_text(INBE_SYNC_CONNECTED_URL_KEY, "");
settings_screen_set_status_success(locale_get("sync_account_deleted"), NULL);
}
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) {
*y += flint_px(12);
if(ui_draw_generic_button(x, *y, half_w, btn_h, locale_get("sync_create_account_button"),
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
if(inbe_sync_account_create(&account)) {
has_account = 1;
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"));
}
}
if(ui_draw_generic_button(x + half_w + gap, *y, half_w, btn_h,
locale_get("sync_import_key_button"),
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
if(!settings_start_sync_key_import(app))
settings_screen_set_status_error(locale_get("sync_private_key_import_failed"));
}
*y += btn_h + flint_px(18);
}
if(!has_account) {
settings_screen_draw_status_reserved(x, y, flint_px(42));
(void)font;
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);
if(ui_draw_generic_button(x, *y, w, btn_h, locale_get("sync_delete_account_button"),
UI_BUTTON_STYLE_DANGER, 0, &hover)) {
app->modal.active = 1;
app->modal.type = UIModalConfirmDeleteSyncAccount;
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,16 @@
#ifndef INBE_SETTINGS_SYNC_ACCOUNT_H
#define INBE_SETTINGS_SYNC_ACCOUNT_H
#include "app_fwd.h"
typedef int (*SettingsSyncKeySaveDialog)(InbeApp *app, const char *filename);
typedef int (*SettingsSyncKeyImportDialog)(InbeApp *app);
void settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback);
void settings_sync_account_set_import_dialog(SettingsSyncKeyImportDialog 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);
void settings_sync_account_delete_confirmed(InbeApp *app);
int settings_sync_account_draw_backup_modal(InbeApp *app);
#endif
+61
View File
@@ -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);
}
}
+14
View File
@@ -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
+33 -1
View File
@@ -235,9 +235,41 @@ data_validate_import_file(const char *path)
int
data_import(const char *path)
{
return data_import_with_mode(path, DATA_IMPORT_DATA_ONLY);
}
int
data_import_with_mode(const char *path, DataImportMode mode)
{
data_init();
return inbe_storage_import_zip(path);
return inbe_storage_import_zip_ex(
path,
mode == DATA_IMPORT_DATA_AND_SETTINGS
? INBE_STORAGE_IMPORT_DATA_AND_SETTINGS
: INBE_STORAGE_IMPORT_DATA_ONLY);
}
int
data_inspect_import(const char *path, DataImportInfo *info)
{
InbeStorageImportInfo storage_info;
data_init();
if(info != NULL)
memset(info, 0, sizeof(*info));
if(!inbe_storage_inspect_import(path, &storage_info))
return 0;
if(info != NULL) {
info->valid = storage_info.valid;
info->has_sessions = storage_info.has_sessions;
info->has_habits = storage_info.has_habits;
info->has_settings = storage_info.has_settings;
info->session_count = storage_info.session_count;
info->habit_count = storage_info.habit_count;
info->setting_count = storage_info.setting_count;
}
return 1;
}
typedef struct DbListSessionContext {
+17
View File
@@ -4,6 +4,21 @@
#include <stddef.h>
#include "breath_engine.h"
typedef enum DataImportMode {
DATA_IMPORT_DATA_ONLY = 0,
DATA_IMPORT_DATA_AND_SETTINGS = 1
} DataImportMode;
typedef struct DataImportInfo {
int valid;
int has_sessions;
int has_habits;
int has_settings;
int session_count;
int habit_count;
int setting_count;
} DataImportInfo;
void data_init(void);
const char *data_root(void);
const char *data_today_dir(void);
@@ -22,6 +37,8 @@ long long data_delete_all(void);
void data_default_export_filename(char *out, size_t out_size);
int data_export(const char *path);
int data_import(const char *path);
int data_import_with_mode(const char *path, DataImportMode mode);
int data_inspect_import(const char *path, DataImportInfo *info);
int data_validate_import_file(const char *path);
typedef void (*data_session_callback)(const char *date, const char *time,
int rounds, int best, void *user);
+868 -121
View File
File diff suppressed because it is too large. Load diff
+20
View File
@@ -16,6 +16,21 @@ typedef void (*InbeStorageSessionRecordCallback)(const char *id,
const int *rounds, int round_count,
void *user);
typedef enum InbeStorageImportMode {
INBE_STORAGE_IMPORT_DATA_ONLY = 0,
INBE_STORAGE_IMPORT_DATA_AND_SETTINGS = 1
} InbeStorageImportMode;
typedef struct InbeStorageImportInfo {
int valid;
int has_sessions;
int has_habits;
int has_settings;
int session_count;
int habit_count;
int setting_count;
} InbeStorageImportInfo;
int inbe_storage_init(const char *root);
void inbe_storage_close(void);
const char *inbe_storage_db_path(void);
@@ -45,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);
@@ -53,5 +71,7 @@ void inbe_storage_mark_habits_initialized(void);
int inbe_storage_export_zip(const char *path);
int inbe_storage_import_zip(const char *path);
int inbe_storage_import_zip_ex(const char *path, InbeStorageImportMode mode);
int inbe_storage_inspect_import(const char *path, InbeStorageImportInfo *info);
#endif
+519
View File
@@ -0,0 +1,519 @@
#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 int account_has_values(const InbeSyncAccount *account);
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;
}
static int
hex_string_valid(const char *hex, size_t expected_len)
{
if(hex == NULL || strlen(hex) != expected_len)
return 0;
for(size_t i = 0; i < expected_len; i++) {
char c = hex[i];
if(!((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F')))
return 0;
}
return 1;
}
static void
copy_key_value(char *out, size_t out_size, const char *value, size_t value_len)
{
if(out == NULL || out_size == 0)
return;
if(value_len >= out_size)
value_len = out_size - 1;
memcpy(out, value, value_len);
out[value_len] = '\0';
}
static void
parse_sync_key_line(InbeSyncAccount *account, const char *line, size_t line_len)
{
const char *value;
size_t value_len;
if(account == NULL || line == NULL)
return;
if(line_len > 0 && line[line_len - 1] == '\r')
line_len--;
if(line_len > 10 && strncmp(line, "public_id=", 10) == 0) {
value = line + 10;
value_len = line_len - 10;
copy_key_value(account->public_id, sizeof(account->public_id), value, value_len);
} else if(line_len > 11 && strncmp(line, "public_key=", 11) == 0) {
value = line + 11;
value_len = line_len - 11;
copy_key_value(account->public_key_hex, sizeof(account->public_key_hex), value, value_len);
} else if(line_len > 12 && strncmp(line, "private_key=", 12) == 0) {
value = line + 12;
value_len = line_len - 12;
copy_key_value(account->private_key_hex, sizeof(account->private_key_hex), value, value_len);
}
}
static int
parse_sync_key_text(const char *text, InbeSyncAccount *account)
{
const char *line;
const char *next;
if(text == NULL || account == NULL)
return 0;
memset(account, 0, sizeof(*account));
line = text;
while(*line != '\0') {
next = strchr(line, '\n');
if(next == NULL) {
parse_sync_key_line(account, line, strlen(line));
break;
}
parse_sync_key_line(account, line, (size_t)(next - line));
line = next + 1;
}
return account_has_values(account);
}
static int
sync_account_validate_import(InbeSyncAccount *account)
{
uint8_t public_key[1312];
char expected_public_id[65];
if(!account_has_values(account))
return 0;
if(!hex_string_valid(account->public_id, 64) ||
!hex_string_valid(account->public_key_hex, 2624) ||
!hex_string_valid(account->private_key_hex, 5120))
return 0;
if(!hex_to_bytes(account->public_key_hex, public_key, sizeof(public_key)))
return 0;
inbe_sync_sha256_hex(public_key, sizeof(public_key), expected_public_id);
return strcmp(account->public_id, expected_public_id) == 0;
}
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_import_private_key(InbeSyncAccount *account, const char *filename)
{
char *body;
InbeSyncAccount imported;
data_init();
if(account == NULL || filename == NULL || filename[0] == '\0')
return 0;
body = LoadFileText(filename);
if(body == NULL)
return 0;
if(!parse_sync_key_text(body, &imported) ||
!sync_account_validate_import(&imported)) {
UnloadFileText(body);
return 0;
}
UnloadFileText(body);
inbe_storage_settings_begin_write();
inbe_storage_set_setting_text(SYNC_PUBLIC_ID_KEY, imported.public_id);
inbe_storage_set_setting_text(SYNC_PUBLIC_KEY_KEY, imported.public_key_hex);
inbe_storage_set_setting_text(SYNC_PRIVATE_KEY_KEY, imported.private_key_hex);
inbe_storage_settings_end_write();
*account = imported;
return 1;
}
int
inbe_sync_account_clear(void)
{
data_init();
inbe_storage_settings_begin_write();
inbe_storage_set_setting_text(SYNC_PUBLIC_ID_KEY, "");
inbe_storage_set_setting_text(SYNC_PUBLIC_KEY_KEY, "");
inbe_storage_set_setting_text(SYNC_PRIVATE_KEY_KEY, "");
inbe_storage_settings_end_write();
return 1;
}
int
inbe_sync_account_export_private_key(const InbeSyncAccount *account, const char *filename)
{
char body[8200];
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\npublic_key=%s\nprivate_key=%s\n",
account->public_id, account->public_key_hex, 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
}
+29
View File
@@ -0,0 +1,29 @@
#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_import_private_key(InbeSyncAccount *account, const char *filename);
int inbe_sync_account_clear(void);
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
+644
View File
@@ -0,0 +1,644 @@
#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(__EMSCRIPTEN__)
#define INBE_SYNC_CLIENT_HAS_WEB 1
#include <emscripten.h>
#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) || defined(INBE_SYNC_CLIENT_HAS_WEB)
#define INBE_SYNC_CLIENT_HAS_HTTP 1
#endif
#define INBE_SYNC_PATH "/api/v1/sync"
#define INBE_CHALLENGE_PATH "/api/v1/sync/challenge"
#define INBE_ACCOUNT_DELETE_WITH_KEY_PATH "/api/v1/account/delete-with-key"
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;
}
static int
sync_buffer_append_json_string(SyncBuffer *buffer, const char *text)
{
const char *p;
if(!sync_buffer_append(buffer, "\"", 1))
return 0;
if(text == NULL)
text = "";
for(p = text; *p != '\0'; p++) {
char escaped[2];
switch(*p) {
case '\\':
if(!sync_buffer_append(buffer, "\\\\", 2))
return 0;
break;
case '"':
if(!sync_buffer_append(buffer, "\\\"", 2))
return 0;
break;
case '\n':
if(!sync_buffer_append(buffer, "\\n", 2))
return 0;
break;
case '\r':
if(!sync_buffer_append(buffer, "\\r", 2))
return 0;
break;
case '\t':
if(!sync_buffer_append(buffer, "\\t", 2))
return 0;
break;
default:
escaped[0] = *p;
escaped[1] = '\0';
if(!sync_buffer_append(buffer, escaped, 1))
return 0;
break;
}
}
return sync_buffer_append(buffer, "\"", 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;
}
#elif defined(INBE_SYNC_CLIENT_HAS_WEB)
EM_ASYNC_JS(int, sync_web_http_request,
(const char *method_ptr, const char *url_ptr, const char *body_ptr,
const char *headers_ptr, char *response_ptr, int response_size,
long *status_ptr), {
const method = UTF8ToString(method_ptr);
const url = UTF8ToString(url_ptr);
const body = body_ptr ? UTF8ToString(body_ptr) : "";
const headerLines = headers_ptr ? UTF8ToString(headers_ptr) : "";
const headers = {};
for(const line of headerLines.split("\n")) {
if(!line) continue;
const colon = line.indexOf(":");
if(colon <= 0) continue;
headers[line.slice(0, colon).trim()] = line.slice(colon + 1).trim();
}
try {
const response = await fetch(url, {
method,
headers,
body: method === "GET" ? undefined : body,
credentials: "omit",
redirect: "manual"
});
const text = await response.text();
setValue(status_ptr, response.status, "i32");
stringToUTF8(text, response_ptr, response_size);
return 1;
} catch(e) {
console.error("Inbe sync HTTP failed:", e);
setValue(status_ptr, 0, "i32");
stringToUTF8("", response_ptr, response_size);
return 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)
{
SyncBuffer header_blob = {0};
char *response_text;
int ok;
if(status != NULL)
*status = 0;
if(response == NULL || method == NULL || url == NULL)
return 0;
for(int i = 0; i < header_count; i++) {
if(headers[i] != NULL &&
(!sync_buffer_append(&header_blob, headers[i], strlen(headers[i])) ||
!sync_buffer_append(&header_blob, "\n", 1))) {
free(header_blob.data);
return 0;
}
}
response_text = (char *)calloc(1, 65536);
if(response_text == NULL) {
free(header_blob.data);
return 0;
}
ok = sync_web_http_request(method, url, body != NULL ? body : "",
header_blob.data != NULL ? header_blob.data : "",
response_text, 65536, status);
free(header_blob.data);
if(!ok) {
free(response_text);
return 0;
}
response->data = response_text;
response->len = strlen(response_text);
response->cap = 65536;
return 1;
}
#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
}
InbeSyncClientResult
inbe_sync_client_delete_account(const char *base_url)
{
#if defined(INBE_SYNC_CLIENT_HAS_HTTP)
InbeSyncAccount account;
char url[768];
char exported_key[8200];
SyncBuffer body = {0};
SyncBuffer response = {0};
const char *headers[1] = {"Content-Type: application/json"};
long status = 0;
int len;
int ok;
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;
len = snprintf(exported_key, sizeof(exported_key),
"inbe-sync-key-v1\nalgorithm=ML-DSA-44\npublic_id=%s\npublic_key=%s\nprivate_key=%s\n",
account.public_id, account.public_key_hex, account.private_key_hex);
if(len <= 0 || (size_t)len >= sizeof(exported_key))
return INBE_SYNC_CLIENT_PAYLOAD_FAILED;
if(!sync_buffer_append(&body, "{\"user_id_hash\":", strlen("{\"user_id_hash\":")) ||
!sync_buffer_append_json_string(&body, account.public_id) ||
!sync_buffer_append(&body, ",\"exported_key\":", strlen(",\"exported_key\":")) ||
!sync_buffer_append_json_string(&body, exported_key) ||
!sync_buffer_append(&body, "}", 1)) {
free(body.data);
return INBE_SYNC_CLIENT_PAYLOAD_FAILED;
}
sync_join_url(url, sizeof(url), base_url, INBE_ACCOUNT_DELETE_WITH_KEY_PATH);
ok = sync_http_request("POST", url, body.data, headers, 1, &response, &status);
free(body.data);
free(response.data);
if(!ok)
return INBE_SYNC_CLIENT_REQUEST_FAILED;
if(status == 401 || status == 403)
return INBE_SYNC_CLIENT_AUTH_FAILED;
return status >= 200 && status < 300 ? INBE_SYNC_CLIENT_OK : INBE_SYNC_CLIENT_REQUEST_FAILED;
#else
(void)base_url;
return INBE_SYNC_CLIENT_UNAVAILABLE;
#endif
}
+23
View File
@@ -0,0 +1,23 @@
#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);
InbeSyncClientResult inbe_sync_client_delete_account(const char *base_url);
#endif
+148 -12
View File
@@ -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">
@@ -28,11 +28,6 @@
overflow: hidden;
}
#status,
#progress {
display: none;
}
.canvas-stage {
width: 100%;
height: 100vh;
@@ -44,6 +39,8 @@
body {
background: #1a1a2e;
color: #f7fbf9;
font-family: ui-monospace, "SFMono-Regular", "Roboto Mono", "Cascadia Mono", "Liberation Mono", monospace;
}
.canvas-frame {
@@ -69,22 +66,149 @@
width: 100vw;
height: 100vh;
}
.loading-screen {
position: fixed;
inset: 0;
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
box-sizing: border-box;
background:
radial-gradient(circle at 50% 38%, rgba(132, 184, 172, 0.24), transparent 36%),
linear-gradient(180deg, #222640 0%, #17172a 58%, #10131f 100%);
opacity: 1;
transition: opacity 360ms ease, visibility 360ms ease;
}
.loading-screen.is-hidden {
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.loading-panel {
width: min(360px, 100%);
display: grid;
justify-items: center;
gap: 18px;
text-align: center;
}
.loading-mark {
width: 76px;
height: 76px;
border-radius: 18px;
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}
.loading-title {
margin: 0;
font-size: 20px;
line-height: 1.25;
font-weight: 700;
}
#status {
min-height: 1.35em;
color: #c9deda;
font-size: 13px;
line-height: 1.35;
}
#progress {
width: min(280px, 100%);
height: 8px;
overflow: hidden;
border: 0;
border-radius: 999px;
background: rgba(255, 255, 255, 0.18);
}
#progress::-webkit-progress-bar {
border-radius: 999px;
background: rgba(255, 255, 255, 0.18);
}
#progress::-webkit-progress-value {
border-radius: 999px;
background: #8fcfc2;
}
#progress::-moz-progress-bar {
border-radius: 999px;
background: #8fcfc2;
}
</style>
</head>
<body>
<div id="status">Downloading...</div>
<progress value="0" max="100" id="progress" hidden></progress>
<div class="loading-screen" id="loading-screen" role="status" aria-live="polite">
<div class="loading-panel">
<img class="loading-mark" src="/web-assets/icons/icon-192x192.png" alt="" width="76" height="76">
<h1 class="loading-title">Inner Breeze</h1>
<div id="status">Downloading...</div>
<progress value="0" max="100" id="progress" hidden></progress>
</div>
</div>
<div class="canvas-stage">
<div class="canvas-frame" id="canvas-frame">
<canvas class="emscripten" id="canvas" width="320" height="560" oncontextmenu="event.preventDefault()" tabindex="-1"></canvas>
<canvas class="emscripten" id="canvas" width="320" height="560" tabindex="-1"></canvas>
</div>
</div>
<script>
var statusElement = document.querySelector('#status');
var progressElement = document.querySelector('#progress');
var loadingScreen = document.querySelector('#loading-screen');
function hideLoadingScreen() {
if (!loadingScreen) return;
window.requestAnimationFrame(function() {
loadingScreen.classList.add('is-hidden');
});
}
function scheduleStorageSync(delay, logSuccess) {
if (typeof FS === 'undefined' || typeof FS.syncfs !== 'function') return;
Module.__inbeStorageSyncPending = true;
Module.__inbeStorageSyncLogSuccess = Module.__inbeStorageSyncLogSuccess || !!logSuccess;
if (Module.__inbeStorageSyncTimer) clearTimeout(Module.__inbeStorageSyncTimer);
Module.__inbeStorageSyncTimer = setTimeout(function runStorageSync() {
Module.__inbeStorageSyncTimer = 0;
if (Module.__inbeStorageSyncing) return;
Module.__inbeStorageSyncing = true;
Module.__inbeStorageSyncPending = false;
var shouldLog = !!Module.__inbeStorageSyncLogSuccess;
Module.__inbeStorageSyncLogSuccess = false;
try {
FS.syncfs(false, function(err) {
Module.__inbeStorageSyncing = false;
if (err) console.error('IDBFS save failed:', err);
else if (shouldLog) console.log('IDBFS synced');
if (Module.__inbeStorageSyncPending) {
if (Module.__inbeStorageSyncTimer) clearTimeout(Module.__inbeStorageSyncTimer);
Module.__inbeStorageSyncTimer = setTimeout(runStorageSync, delay);
}
});
} catch (e) {
Module.__inbeStorageSyncing = false;
console.error('IDBFS sync error:', e);
if (Module.__inbeStorageSyncPending) {
if (Module.__inbeStorageSyncTimer) clearTimeout(Module.__inbeStorageSyncTimer);
Module.__inbeStorageSyncTimer = setTimeout(runStorageSync, delay);
}
}
}, delay);
}
var Module = {
__inbeScheduleStorageSync: scheduleStorageSync,
preRun: [function() {
if (typeof FS === 'undefined' || typeof IDBFS === 'undefined') {
console.error('IDBFS unavailable');
@@ -111,7 +235,7 @@
removeRunDependency('inbe-idbfs');
});
}],
postRun: [],
postRun: [hideLoadingScreen],
locateFile: function(path, prefix) {
if (path === 'index.wasm' || path === 'index.data') {
return prefix + path + '?v=WEB_CACHE_BUSTER';
@@ -132,6 +256,18 @@
alert('WebGL context lost. Reload the page to continue.');
e.preventDefault();
}, false);
canvas.addEventListener('contextmenu', function(e) {
var rect = canvas.getBoundingClientRect();
var width = canvas.width || rect.width || 1;
var height = canvas.height || rect.height || 1;
e.preventDefault();
Module.__inbeContextClick = {
x: Math.round((e.clientX - rect.left) * width / Math.max(1, rect.width)),
y: Math.round((e.clientY - rect.top) * height / Math.max(1, rect.height)),
time: Date.now()
};
}, false);
return canvas;
})(),
setStatus: function(text) {
@@ -153,7 +289,7 @@
} else {
statusElement.textContent = text;
progressElement.hidden = true;
if (!text) statusElement.style.display = 'none';
if (!text) hideLoadingScreen();
}
},
totalDependencies: 0,
+181
View File
@@ -0,0 +1,181 @@
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum {
MAX_KEYS = 1024,
MAX_KEY_LEN = 128,
MAX_PATH_LEN = 512
};
typedef struct LocaleKeys {
char keys[MAX_KEYS][MAX_KEY_LEN];
int count;
} LocaleKeys;
static int failures = 0;
static void
trim_newline(char *text)
{
size_t len;
if(text == NULL)
return;
len = strlen(text);
while(len > 0 && (text[len - 1] == '\n' || text[len - 1] == '\r')) {
text[len - 1] = '\0';
len--;
}
}
static int
parse_key_line(const char *line, char *out, size_t out_size)
{
const char *end;
size_t len;
if(line == NULL || out == NULL || out_size == 0 || line[0] != '[')
return 0;
end = strchr(line, ']');
if(end == NULL || end == line + 1)
return 0;
len = (size_t)(end - line - 1);
if(len >= out_size)
len = out_size - 1;
memcpy(out, line + 1, len);
out[len] = '\0';
return 1;
}
static int
keys_contains(const LocaleKeys *keys, const char *key)
{
if(keys == NULL || key == NULL)
return 0;
for(int i = 0; i < keys->count; i++) {
if(strcmp(keys->keys[i], key) == 0)
return 1;
}
return 0;
}
static void
keys_add(LocaleKeys *keys, const char *key)
{
if(keys == NULL || key == NULL || key[0] == '\0')
return;
if(keys_contains(keys, key))
return;
if(keys->count >= MAX_KEYS) {
fprintf(stderr, "FAIL too many locale keys\n");
failures++;
return;
}
snprintf(keys->keys[keys->count], sizeof(keys->keys[keys->count]), "%s", key);
keys->count++;
}
static int
line_has_value(const char *line)
{
if(line == NULL)
return 0;
while(*line == ' ' || *line == '\t')
line++;
return line[0] != '\0' && strcmp(line, "---") != 0;
}
static int
load_locale_keys(const char *path, LocaleKeys *keys)
{
FILE *fp;
char line[512];
char pending_key[MAX_KEY_LEN] = "";
int ok = 1;
if(keys == NULL)
return 0;
memset(keys, 0, sizeof(*keys));
fp = fopen(path, "rb");
if(fp == NULL) {
fprintf(stderr, "FAIL open %s\n", path);
failures++;
return 0;
}
while(fgets(line, sizeof(line), fp) != NULL) {
char key[MAX_KEY_LEN];
trim_newline(line);
if(parse_key_line(line, key, sizeof(key))) {
if(pending_key[0] != '\0') {
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
failures++;
ok = 0;
}
keys_add(keys, key);
snprintf(pending_key, sizeof(pending_key), "%s", key);
} else if(pending_key[0] != '\0' && line_has_value(line)) {
pending_key[0] = '\0';
}
}
if(pending_key[0] != '\0') {
fprintf(stderr, "FAIL %s key [%s] has no value\n", path, pending_key);
failures++;
ok = 0;
}
fclose(fp);
return ok;
}
static void
check_locale_file(const LocaleKeys *english, const char *path)
{
LocaleKeys translated;
load_locale_keys(path, &translated);
for(int i = 0; i < english->count; i++) {
if(!keys_contains(&translated, english->keys[i])) {
fprintf(stderr, "FAIL %s missing [%s]\n", path, english->keys[i]);
failures++;
}
}
}
int
main(void)
{
LocaleKeys english;
DIR *dir;
struct dirent *entry;
if(!load_locale_keys("locales/en.txt", &english))
return 1;
dir = opendir("locales");
if(dir == NULL) {
fprintf(stderr, "FAIL open locales directory\n");
return 1;
}
while((entry = readdir(dir)) != NULL) {
char path[MAX_PATH_LEN];
const char *name = entry->d_name;
size_t len = strlen(name);
if(len <= 4 || strcmp(name + len - 4, ".txt") != 0)
continue;
if(strcmp(name, "en.txt") == 0 || strcmp(name, "index.txt") == 0)
continue;
snprintf(path, sizeof(path), "locales/%s", name);
check_locale_file(&english, path);
}
closedir(dir);
if(failures != 0) {
fprintf(stderr, "%d locale key test failure(s)\n", failures);
return 1;
}
printf("locale key tests passed\n");
return 0;
}
+454 -4
View File
@@ -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;
@@ -42,6 +43,51 @@ check_true(const char *label, int ok)
g_failures++;
}
static void
check_str(const char *label, const char *got, const char *want)
{
if(got == NULL && want == NULL)
return;
if(got != NULL && want != NULL && strcmp(got, want) == 0)
return;
fprintf(stderr, "FAIL %s: got %s, want %s\n",
label, got != NULL ? got : "(null)", want != NULL ? want : "(null)");
g_failures++;
}
static int
ascii_equal_ci(const char *a, const char *b)
{
unsigned char ca;
unsigned char cb;
if(a == NULL || b == NULL)
return 0;
while(*a != '\0' && *b != '\0') {
ca = (unsigned char)*a++;
cb = (unsigned char)*b++;
if(ca >= 'A' && ca <= 'Z')
ca = (unsigned char)(ca - 'A' + 'a');
if(cb >= 'A' && cb <= 'Z')
cb = (unsigned char)(cb - 'A' + 'a');
if(ca != cb)
return 0;
}
return *a == '\0' && *b == '\0';
}
static InbeHabit *
find_habit_ci(InbeHabits *habits, const char *name)
{
if(habits == NULL || name == NULL)
return NULL;
for(int i = 0; i < habits->count; i++) {
if(ascii_equal_ci(habits->items[i].name, name))
return &habits->items[i];
}
return NULL;
}
static int
ensure_dir(const char *path)
{
@@ -114,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,
@@ -229,6 +301,263 @@ test_zip_db_import(void)
remove_tree(dest);
}
static void
test_habit_name_merge_import(void)
{
char source[512], dest[512], zip_path[512];
InbeHabits habits;
InbeHabit *habit;
make_clean_root(source, sizeof(source), "habit-name-source");
make_clean_root(dest, sizeof(dest), "habit-name-dest");
make_path(zip_path, sizeof(zip_path), source, "export.zip");
check_true("init habit merge source", inbe_storage_init(source));
memset(&habits, 0, sizeof(habits));
check_int("add imported meditation",
inbe_habits_add_custom(&habits, "meditation",
(Color){224, 124, 104, 255},
INBE_HABIT_SYNC_NONE, 0),
0);
inbe_habit_set_day(&habits, 0, 20260613, 1);
check_int("add imported push ups",
inbe_habits_add_custom(&habits, "Push ups",
(Color){180, 132, 220, 255},
INBE_HABIT_SYNC_NONE, 0),
1);
inbe_habit_set_day(&habits, 1, 20260614, 1);
check_int("add imported cold shower",
inbe_habits_add_custom(&habits, "Cold Shower",
(Color){99, 196, 165, 255},
INBE_HABIT_SYNC_NONE, 0),
2);
inbe_habit_set_day(&habits, 2, 20260615, 1);
check_true("habit merge export", inbe_storage_export_zip(zip_path));
inbe_storage_close();
check_true("init habit merge dest", inbe_storage_init(dest));
memset(&habits, 0, sizeof(habits));
inbe_habits_add_default_set(&habits);
inbe_habit_set_day(&habits, 0, 20260612, 1);
check_true("habit merge import", inbe_storage_import_zip(zip_path));
memset(&habits, 0, sizeof(habits));
check_true("habit merge load", inbe_storage_habits_load(&habits));
check_int("habit merge count", habits.count, 3);
habit = find_habit_ci(&habits, "Meditation");
check_true("habit merge meditation exists", habit != NULL);
check_true("habit merge preserves local case",
habit != NULL && strcmp(habit->name, "Meditation") == 0);
check_true("habit merge keeps local day",
habit != NULL && inbe_habit_completed_day(habit, 20260612));
check_true("habit merge imports day",
habit != NULL && inbe_habit_completed_day(habit, 20260613));
habit = find_habit_ci(&habits, "Push ups");
check_true("habit merge push ups exists", habit != NULL);
check_true("habit merge push ups day",
habit != NULL && inbe_habit_completed_day(habit, 20260614));
habit = find_habit_ci(&habits, "Cold Shower");
check_true("habit merge cold shower exists", habit != NULL);
check_true("habit merge cold shower day",
habit != NULL && inbe_habit_completed_day(habit, 20260615));
inbe_storage_close();
remove_tree(source);
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)
{
int rounds[] = {77};
InbeHabits habits;
check_true("init multi habit source", inbe_storage_init(root));
check_true("save multi habit source session",
inbe_storage_save_session_for_activity(rounds, 1, 0, 1, NULL, 0));
memset(&habits, 0, sizeof(habits));
check_int("add meditation habit",
inbe_habits_add_custom(&habits, "Meditation",
(Color){224, 124, 104, 255},
INBE_HABIT_SYNC_ACTIVITIES,
(1 << 0) | (1 << 1)),
0);
check_int("add push ups habit",
inbe_habits_add_custom(&habits, "Push ups",
(Color){180, 132, 220, 255},
INBE_HABIT_SYNC_NONE, 0),
1);
check_int("add cold shower habit",
inbe_habits_add_custom(&habits, "Cold Shower",
(Color){99, 196, 165, 255},
INBE_HABIT_SYNC_NONE, 0),
2);
inbe_habit_set_day(&habits, 0, 20260617, 1);
inbe_habit_set_day(&habits, 1, 20260617, 1);
inbe_habit_set_day(&habits, 2, 20260617, 1);
inbe_storage_set_setting_int("speed", 7);
inbe_storage_set_setting_text("language", "en");
inbe_storage_set_setting_text("future_unknown_key", "ignore-me");
check_true("export multi habit source", inbe_storage_export_zip(zip_path));
inbe_storage_close();
}
static void
assert_multi_habits_imported(const char *root, int want_speed)
{
InbeHabits habits;
InbeHabit *habit;
check_true("init multi habit import db", inbe_storage_init(root));
check_int("multi habit imported sessions", inbe_storage_session_count(), 1);
memset(&habits, 0, sizeof(habits));
check_true("multi habit load", inbe_storage_habits_load(&habits));
check_int("multi habit count", habits.count, 3);
habit = find_habit_ci(&habits, "Meditation");
check_true("multi meditation exists", habit != NULL);
check_int("multi meditation sync mode",
habit != NULL ? habit->sync_mode : -1,
INBE_HABIT_SYNC_ACTIVITIES);
check_int("multi meditation sync activity",
habit != NULL ? habit->sync_activity : -1,
(1 << 0) | (1 << 1));
check_true("multi meditation day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
habit = find_habit_ci(&habits, "Push ups");
check_true("multi push ups day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
habit = find_habit_ci(&habits, "Cold Shower");
check_true("multi cold shower day",
habit != NULL && inbe_habit_completed_day(habit, 20260617));
check_int("multi import speed setting",
inbe_storage_get_setting_int("speed", -1), want_speed);
check_str("multi import unknown setting",
inbe_storage_get_setting_text("future_unknown_key"), NULL);
inbe_storage_close();
}
static void
test_import_modes_preserve_habits_and_settings_choice(void)
{
char source[512], dest_data[512], dest_settings[512], zip_path[512];
InbeStorageImportInfo info;
make_clean_root(source, sizeof(source), "multi-source");
make_clean_root(dest_data, sizeof(dest_data), "multi-dest-data");
make_clean_root(dest_settings, sizeof(dest_settings), "multi-dest-settings");
make_path(zip_path, sizeof(zip_path), source, "multi-export.zip");
write_multi_habit_source_database(source, zip_path);
check_true("init inspect dest", inbe_storage_init(dest_data));
memset(&info, 0, sizeof(info));
check_true("inspect multi export", inbe_storage_inspect_import(zip_path, &info));
check_true("inspect valid", info.valid);
check_true("inspect sessions", info.has_sessions);
check_true("inspect habits", info.has_habits);
check_true("inspect settings", info.has_settings);
check_int("inspect habit count", info.habit_count, 3);
inbe_storage_set_setting_int("speed", 1);
check_true("multi data only import",
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_ONLY));
inbe_storage_close();
assert_multi_habits_imported(dest_data, 1);
check_true("init settings import dest", inbe_storage_init(dest_settings));
inbe_storage_set_setting_int("speed", 1);
check_true("multi data settings import",
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
inbe_storage_close();
assert_multi_habits_imported(dest_settings, 7);
remove_tree(source);
remove_tree(dest_data);
remove_tree(dest_settings);
}
static void
write_legacy_zip(const char *path, const char *prefix)
{
@@ -316,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);
@@ -330,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);
}
@@ -358,22 +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) {
+293
View File
@@ -0,0 +1,293 @@
#include "sync_account.h"
#include "storage.h"
#include <dirent.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
static int g_failures = 0;
static char g_data_root[1024] = "";
void
data_init(void)
{
}
const char *
data_root(void)
{
return g_data_root;
}
void
TraceLog(int log_level, const char *text, ...)
{
(void)log_level;
(void)text;
}
char *
LoadFileText(const char *file_name)
{
FILE *file;
long size;
char *text;
file = fopen(file_name, "rb");
if(file == NULL)
return NULL;
if(fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return NULL;
}
size = ftell(file);
if(size < 0) {
fclose(file);
return NULL;
}
rewind(file);
text = (char *)malloc((size_t)size + 1);
if(text == NULL) {
fclose(file);
return NULL;
}
if(fread(text, 1, (size_t)size, file) != (size_t)size) {
free(text);
fclose(file);
return NULL;
}
text[size] = '\0';
fclose(file);
return text;
}
void
UnloadFileText(char *text)
{
free(text);
}
bool
SaveFileData(const char *file_name, const void *data, int data_size)
{
FILE *file;
int ok;
file = fopen(file_name, "wb");
if(file == NULL)
return 0;
ok = fwrite(data, 1, (size_t)data_size, file) == (size_t)data_size;
fclose(file);
return ok;
}
static void
check_true(const char *label, int ok)
{
if(ok)
return;
fprintf(stderr, "FAIL %s\n", label);
g_failures++;
}
static void
check_false(const char *label, int ok)
{
if(!ok)
return;
fprintf(stderr, "FAIL %s\n", label);
g_failures++;
}
static void
check_str(const char *label, const char *got, const char *want)
{
if(got != NULL && want != NULL && strcmp(got, want) == 0)
return;
fprintf(stderr, "FAIL %s: got %s, want %s\n",
label, got != NULL ? got : "(null)", want != NULL ? want : "(null)");
g_failures++;
}
static int
ensure_dir(const char *path)
{
struct stat st;
if(stat(path, &st) == 0 && S_ISDIR(st.st_mode))
return 1;
return mkdir(path, 0700) == 0;
}
static void
remove_tree(const char *path)
{
DIR *dir = opendir(path);
struct dirent *entry;
if(dir == NULL) {
remove(path);
return;
}
while((entry = readdir(dir)) != NULL) {
char child[1024];
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
continue;
snprintf(child, sizeof(child), "%s/%s", path, entry->d_name);
remove_tree(child);
}
closedir(dir);
rmdir(path);
}
static void
make_clean_root(char *out, size_t out_size, const char *name)
{
snprintf(out, out_size, "/tmp/inbe-sync-account-test-%ld-%s", (long)getpid(), name);
remove_tree(out);
check_true("create test root", ensure_dir(out));
snprintf(g_data_root, sizeof(g_data_root), "%s", out);
}
static void
bytes_to_hex_local(const unsigned char *bytes, size_t len, char *out, size_t out_size)
{
static const char hex[] = "0123456789abcdef";
check_true("hex output size", out_size >= len * 2 + 1);
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 void
write_key_file(const char *path, const char *public_id,
const char *public_key, const char *private_key)
{
FILE *file = fopen(path, "wb");
check_true("open key file", file != NULL);
if(file == NULL)
return;
fprintf(file,
"inbe-sync-key-v1\nalgorithm=ML-DSA-44\npublic_id=%s\npublic_key=%s\nprivate_key=%s\n",
public_id, public_key, private_key);
fclose(file);
}
static void
make_account_values(char public_id[65], char public_key_hex[2625],
char private_key_hex[5121])
{
unsigned char public_key[1312];
unsigned char private_key[2560];
for(size_t i = 0; i < sizeof(public_key); i++)
public_key[i] = (unsigned char)(i * 31U + 7U);
for(size_t i = 0; i < sizeof(private_key); i++)
private_key[i] = (unsigned char)(i * 17U + 3U);
inbe_sync_sha256_hex(public_key, sizeof(public_key), public_id);
bytes_to_hex_local(public_key, sizeof(public_key), public_key_hex, 2625);
bytes_to_hex_local(private_key, sizeof(private_key), private_key_hex, 5121);
}
static void
test_import_export_clear(void)
{
char root[512];
char key_path[1024];
char export_path[1024];
char public_id[65];
char public_key[2625];
char private_key[5121];
InbeSyncAccount account;
char *exported;
make_clean_root(root, sizeof(root), "roundtrip");
snprintf(key_path, sizeof(key_path), "%s/inbe-sync.key", root);
snprintf(export_path, sizeof(export_path), "%s/exported.key", root);
make_account_values(public_id, public_key, private_key);
write_key_file(key_path, public_id, public_key, private_key);
check_true("init storage", inbe_storage_init(root));
check_true("import key", inbe_sync_account_import_private_key(&account, key_path));
check_str("import public id", account.public_id, public_id);
check_true("load imported key", inbe_sync_account_load(&account));
check_str("load public key", account.public_key_hex, public_key);
check_str("load private key", account.private_key_hex, private_key);
check_true("export key", inbe_sync_account_export_private_key(&account, export_path));
exported = LoadFileText(export_path);
check_true("read exported key", exported != NULL);
if(exported != NULL) {
check_true("export includes public key", strstr(exported, "\npublic_key=") != NULL);
UnloadFileText(exported);
}
check_true("clear key", inbe_sync_account_clear());
check_false("load after clear", inbe_sync_account_load(&account));
check_true("import exported key", inbe_sync_account_import_private_key(&account, export_path));
check_str("reimport public id", account.public_id, public_id);
inbe_storage_close();
remove_tree(root);
}
static void
test_reject_invalid_keys(void)
{
char root[512];
char key_path[1024];
char public_id[65];
char public_key[2625];
char private_key[5121];
InbeSyncAccount account;
FILE *file;
make_clean_root(root, sizeof(root), "invalid");
snprintf(key_path, sizeof(key_path), "%s/inbe-sync.key", root);
make_account_values(public_id, public_key, private_key);
check_true("init invalid storage", inbe_storage_init(root));
public_id[0] = public_id[0] == '0' ? '1' : '0';
write_key_file(key_path, public_id, public_key, private_key);
check_false("reject mismatched public id",
inbe_sync_account_import_private_key(&account, key_path));
file = fopen(key_path, "wb");
check_true("open missing public key file", file != NULL);
if(file != NULL) {
fprintf(file,
"inbe-sync-key-v1\nalgorithm=ML-DSA-44\npublic_id=%s\nprivate_key=%s\n",
public_id, private_key);
fclose(file);
}
check_false("reject missing public key",
inbe_sync_account_import_private_key(&account, key_path));
check_false("no account after rejected imports", inbe_sync_account_load(&account));
inbe_storage_close();
remove_tree(root);
}
int
main(void)
{
test_import_export_clear();
test_reject_invalid_keys();
if(g_failures != 0) {
fprintf(stderr, "%d sync account test failure(s)\n", g_failures);
return 1;
}
printf("sync account tests passed\n");
return 0;
}
+80
View File
@@ -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;
}
Vendored Submodule
+1
Submodule vendor/liboqs added at d95fc734f5.
Loaded 100 of 101 files, more files were not shown because too many files have changed in this diff. Show more