Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1914a1415 | ||
|
|
e9f95d8c89 | ||
|
|
40a660249c | ||
|
|
14a270c7b6 | ||
|
|
d39ea8fd4d | ||
|
|
88818aea09 | ||
|
|
3aec019348 | ||
|
|
8e01c0fa7d | ||
|
|
5e98458257 | ||
|
|
1209e29078 | ||
|
|
a3743c9b37 | ||
|
|
fe96b6c61e | ||
|
|
eabbff2972 |
No files matched your search
@@ -571,7 +571,7 @@ jobs:
|
||||
butler push "$linux_appimage" waozi/inbe:linux --userversion "$VERSION"
|
||||
|
||||
publish-google-play:
|
||||
name: Publish Google Play Alpha
|
||||
name: Publish Google Play Production
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build-android
|
||||
@@ -595,15 +595,52 @@ jobs:
|
||||
name: release-android
|
||||
path: build/release/android
|
||||
|
||||
- name: Publish AAB to Closed Testing Alpha
|
||||
- name: Publish AAB to Play Games on PC Production
|
||||
uses: r0adkll/upload-google-play@v1
|
||||
with:
|
||||
serviceAccountJsonPlainText: ${{ secrets.PLAY_STORE_JSON_KEY }}
|
||||
packageName: xyz.waozi.inbe
|
||||
releaseFiles: build/release/android/*.aab
|
||||
tracks: alpha
|
||||
tracks: google_play_games_pc:production
|
||||
status: completed
|
||||
|
||||
publish-amazon:
|
||||
name: Publish Amazon Appstore
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- build-android
|
||||
- release
|
||||
if: needs.release.outputs.tag_pushed == 'true'
|
||||
env:
|
||||
AMAZON_CLIENT_ID: ${{ secrets.AMAZON_CLIENT_ID }}
|
||||
AMAZON_CLIENT_SECRET: ${{ secrets.AMAZON_CLIENT_SECRET }}
|
||||
AMAZON_APP_ID: ${{ secrets.AMAZON_APP_ID }}
|
||||
|
||||
steps:
|
||||
- name: Check Amazon Appstore Secrets
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for name in AMAZON_CLIENT_ID AMAZON_CLIENT_SECRET AMAZON_APP_ID; do
|
||||
if [ -z "${!name:-}" ]; then
|
||||
echo "$name secret is required to publish Amazon Appstore"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Download Android Release Artifact
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: release-android
|
||||
path: build/release/android
|
||||
|
||||
- name: Upload APK to Amazon Appstore
|
||||
uses: galonga/[email protected]
|
||||
with:
|
||||
clientId: ${{ env.AMAZON_CLIENT_ID }}
|
||||
clientSecret: ${{ env.AMAZON_CLIENT_SECRET }}
|
||||
appId: ${{ env.AMAZON_APP_ID }}
|
||||
releaseFile: build/release/android/inbe-${{ needs.release.outputs.version }}.apk
|
||||
|
||||
publish-chrome-web-store:
|
||||
name: Publish Chrome Web Store
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
# Changelog
|
||||
## [1.7.6] - 2026-06-30
|
||||
### Added
|
||||
- habit overview
|
||||
|
||||
## [1.7.5] - 2026-06-29
|
||||
### Fixed
|
||||
- Fix Android 15 relaunch freeze.
|
||||
- Code cleanup
|
||||
|
||||
## [1.7.4] - 2026-06-29
|
||||
### Fixed
|
||||
- Clean up practice stats, friend removal, sync review, and Android inset handling.
|
||||
|
||||
## [1.7.3] - 2026-06-29
|
||||
### Fixed
|
||||
- bottom inset in practice
|
||||
|
||||
### Changed
|
||||
- Improve habit management
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
|
||||
|
||||
APP_SRCS := \
|
||||
src/main.c \
|
||||
src/app/app_sync.c \
|
||||
src/core/breath_engine.c \
|
||||
src/app/app.c \
|
||||
src/app/app_nav.c \
|
||||
@@ -193,12 +194,14 @@ APP_SRCS := \
|
||||
src/screens/habits/edit.c \
|
||||
src/screens/habits/session.c \
|
||||
src/screens/profile_screen.c \
|
||||
src/screens/profile_social.c \
|
||||
src/screens/pet_screen.c \
|
||||
src/practices/meditation/meditation_music.c \
|
||||
src/storage/data.c \
|
||||
src/storage/db.c \
|
||||
src/storage/import.c \
|
||||
src/storage/storage.c \
|
||||
src/storage/storage_sessions.c \
|
||||
src/storage/sync_review.c \
|
||||
src/storage/sync_account.c \
|
||||
src/storage/sync_client.c \
|
||||
@@ -208,6 +211,7 @@ APP_SRCS := \
|
||||
src/screens/language_screen.c \
|
||||
src/screens/manual_screen.c \
|
||||
src/screens/settings/settings_screen.c \
|
||||
src/screens/settings/settings_ui.c \
|
||||
src/screens/settings/settings_device.c \
|
||||
src/screens/settings/settings_session.c \
|
||||
src/screens/settings/settings_theme.c \
|
||||
@@ -379,11 +383,11 @@ test: $(TESTS)
|
||||
fi; \
|
||||
exit "$$status"
|
||||
|
||||
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.h src/screens/habits_screen.c src/screens/habits/edit.c src/screens/habits/session.c src/screens/habits_screen.h src/screens/habits/habits.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.h src/screens/habits_screen.c src/screens/habits/edit.c src/screens/habits/session.c src/screens/habits_screen.h src/screens/habits/habits.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 -I$(RAYLIB_DIR) $(FLINT_INCLUDE) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/storage_import_test.c src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/screens/habits_screen.c src/screens/habits/edit.c src/screens/habits/session.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
tests/storage_import_test.c src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/screens/habits_screen.c src/screens/habits/edit.c src/screens/habits/session.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
-Wl,--gc-sections -lm -lpthread -ldl
|
||||
|
||||
$(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
|
||||
@@ -397,18 +401,18 @@ $(SYNC_URL_TEST): tests/sync_url_test.c src/storage/sync_client.c src/storage/sy
|
||||
tests/sync_url_test.c src/storage/sync_client.c $(FLINT_DIR)/src/flint_lyra_sync.c $(FLINT_DIR)/src/flint_lyra_account.c \
|
||||
-Wl,--gc-sections $(FLINT_CURL_LDLIBS)
|
||||
|
||||
$(SYNC_ACCOUNT_TEST): tests/sync_account_test.c src/storage/sync_account.c src/storage/sync_account.h $(FLINT_DIR)/src/flint_lyra_account.c $(FLINT_DIR)/include/flint_lyra_account.h src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(SYNC_ACCOUNT_TEST): tests/sync_account_test.c src/storage/sync_account.c src/storage/sync_account.h $(FLINT_DIR)/src/flint_lyra_account.c $(FLINT_DIR)/include/flint_lyra_account.h src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(LIBOQS_A) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -DFLINT_HAS_LIBOQS=1 -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 $(FLINT_INCLUDE) $(LIBOQS_INCLUDE) -I$(RAYLIB_DIR) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/sync_account_test.c src/storage/sync_account.c $(FLINT_DIR)/src/flint_lyra_account.c src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
tests/sync_account_test.c src/storage/sync_account.c $(FLINT_DIR)/src/flint_lyra_account.c src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
$(LIBOQS_A) -Wl,--gc-sections -lm -lpthread -ldl
|
||||
|
||||
$(SYNC_REVIEW_TEST): tests/sync_review_test.c src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
$(SYNC_REVIEW_TEST): tests/sync_review_test.c src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/storage/storage.h src/storage/db.h src/storage/import.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 $(FLINT_INCLUDE) -I$(RAYLIB_DIR) $(SQLITE_INCLUDE) \
|
||||
-o $@ \
|
||||
tests/sync_review_test.c src/storage/storage.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
tests/sync_review_test.c src/storage/storage.c src/storage/storage_sessions.c src/storage/sync_review.c src/storage/db.c src/storage/import.c src/third_party/miniz.c $(SQLITE_SRC) \
|
||||
-Wl,--gc-sections -lm -lpthread -ldl
|
||||
|
||||
$(FONT_LOCALE_TEST): tests/font_locale_test.c $(FONT_OUTPUTS) | $(TEST_BIN_DIR)
|
||||
@@ -592,6 +596,7 @@ $(WIN64_LIBOQS_A): $(LIBOQS_DIR)/CMakeLists.txt
|
||||
-DCMAKE_C_COMPILER=$(WIN64_CC_PATH) \
|
||||
-DCMAKE_AR=$(WIN64_AR_PATH) \
|
||||
-DCMAKE_RANLIB=$(WIN64_RANLIB_PATH) \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="$(WIN64_THREAD_LDFLAGS)" \
|
||||
-DCMAKE_BUILD_TYPE=$(FLINT_LIBOQS_BUILD_TYPE) \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DOQS_BUILD_ONLY_LIB=ON \
|
||||
@@ -640,6 +645,7 @@ $(WIN32_LIBOQS_A): $(LIBOQS_DIR)/CMakeLists.txt
|
||||
-DCMAKE_C_COMPILER=$(WIN32_CC_PATH) \
|
||||
-DCMAKE_AR=$(WIN32_AR_PATH) \
|
||||
-DCMAKE_RANLIB=$(WIN32_RANLIB_PATH) \
|
||||
-DCMAKE_EXE_LINKER_FLAGS="$(WIN32_THREAD_LDFLAGS)" \
|
||||
-DCMAKE_BUILD_TYPE=$(FLINT_LIBOQS_BUILD_TYPE) \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DOQS_BUILD_ONLY_LIB=ON \
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 103 KiB After Width: | Height: | Size: 104 KiB |
@@ -35,8 +35,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
versionCode 66
|
||||
versionName "1.7.3"
|
||||
versionCode 69
|
||||
versionName "1.7.6"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
android:name="xyz.waozi.inbe.MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|uiMode"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||
android:windowLayoutInDisplayCutoutMode="never">
|
||||
<meta-data
|
||||
|
||||
@@ -110,6 +110,7 @@ target_include_directories(raylib PUBLIC
|
||||
add_library(main SHARED
|
||||
"${SRC_DIR}/main.c"
|
||||
"${SRC_DIR}/core/breath_engine.c"
|
||||
"${SRC_DIR}/app/app_sync.c"
|
||||
"${SRC_DIR}/app/app.c"
|
||||
"${SRC_DIR}/app/app_nav.c"
|
||||
"${SRC_DIR}/app/app_settings.c"
|
||||
@@ -130,12 +131,14 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/screens/habits/edit.c"
|
||||
"${SRC_DIR}/screens/habits/session.c"
|
||||
"${SRC_DIR}/screens/profile_screen.c"
|
||||
"${SRC_DIR}/screens/profile_social.c"
|
||||
"${SRC_DIR}/screens/pet_screen.c"
|
||||
"${SRC_DIR}/practices/meditation/meditation_music.c"
|
||||
"${SRC_DIR}/storage/data.c"
|
||||
"${SRC_DIR}/storage/db.c"
|
||||
"${SRC_DIR}/storage/import.c"
|
||||
"${SRC_DIR}/storage/storage.c"
|
||||
"${SRC_DIR}/storage/storage_sessions.c"
|
||||
"${SRC_DIR}/storage/sync_review.c"
|
||||
"${SRC_DIR}/storage/sync_account.c"
|
||||
"${SRC_DIR}/storage/sync_client.c"
|
||||
@@ -149,6 +152,7 @@ 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_ui.c"
|
||||
"${SRC_DIR}/screens/settings/settings_device.c"
|
||||
"${SRC_DIR}/screens/settings/settings_session.c"
|
||||
"${SRC_DIR}/screens/settings/settings_theme.c"
|
||||
@@ -207,6 +211,7 @@ target_link_options(main PRIVATE
|
||||
-Wl,--gc-sections
|
||||
-Wl,--strip-all
|
||||
-Wl,-z,max-page-size=16384
|
||||
-Wl,-z,common-page-size=16384
|
||||
-Wl,--wrap=fopen
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -24,6 +23,7 @@ import android.view.WindowInsets;
|
||||
import android.view.WindowInsetsController;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -47,7 +47,6 @@ public class MainActivity extends NativeActivity {
|
||||
|
||||
// [status_bar, nav_bar, cutouts] mirrored in native.
|
||||
private final int[] cachedInsets = new int[6];
|
||||
private boolean insetsInitialized = false;
|
||||
private boolean activityPaused = false;
|
||||
private boolean windowFocused = true;
|
||||
private boolean backgroundExecutionActive = false;
|
||||
@@ -447,7 +446,6 @@ public class MainActivity extends NativeActivity {
|
||||
|
||||
// Notify native code that activity is ready for wake lock
|
||||
nativeWakeLockReady();
|
||||
requestNotificationPermissionIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -464,11 +462,20 @@ public class MainActivity extends NativeActivity {
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
getWindow().setDecorFitsSystemWindows(false);
|
||||
|
||||
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
attrs.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
|
||||
} else {
|
||||
attrs.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
}
|
||||
getWindow().setAttributes(attrs);
|
||||
}
|
||||
getWindow().setNavigationBarColor(Color.BLACK);
|
||||
getWindow().setStatusBarColor(Color.BLACK);
|
||||
|
||||
int flags = getWindow().getDecorView().getSystemUiVisibility();
|
||||
flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
||||
flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
||||
@@ -488,7 +495,8 @@ public class MainActivity extends NativeActivity {
|
||||
controller.show(WindowInsets.Type.navigationBars());
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
||||
getWindow().setNavigationBarContrastEnforced(false);
|
||||
}
|
||||
}
|
||||
@@ -600,7 +608,6 @@ public class MainActivity extends NativeActivity {
|
||||
cachedInsets[5] = cBottom;
|
||||
}
|
||||
|
||||
insetsInitialized = true;
|
||||
nativeSetInsets(statusBar, navBar, cLeft, cTop, cRight, cBottom);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -664,6 +671,15 @@ public class MainActivity extends NativeActivity {
|
||||
syncLifecycleState("onResume");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
configureSystemBars();
|
||||
requestInsetRefresh();
|
||||
syncLifecycleState("onNewIntent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
plugins {
|
||||
id 'com.android.application' version '8.4.2' apply false
|
||||
id 'com.android.application' version '8.5.1' apply false
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Fixed
|
||||
---
|
||||
- bottom inset in practice
|
||||
@@ -0,0 +1,3 @@
|
||||
Fixed
|
||||
---
|
||||
- Android lanuch bug
|
||||
@@ -0,0 +1,3 @@
|
||||
Added
|
||||
---
|
||||
- habit overview
|
||||
@@ -75,6 +75,32 @@
|
||||
sdk = androidComposition.androidsdk;
|
||||
ndkPath = "${sdk}/libexec/android-sdk/ndk-bundle";
|
||||
|
||||
emulatorRuntimeLibraryPath = pkgs.lib.makeLibraryPath (with pkgs; [
|
||||
dbus
|
||||
expat
|
||||
fontconfig
|
||||
freetype
|
||||
libbsd
|
||||
libice
|
||||
libmd
|
||||
libpng
|
||||
libsm
|
||||
libuuid
|
||||
libx11
|
||||
libxau
|
||||
libxcb
|
||||
libxdmcp
|
||||
libxkbcommon
|
||||
xcb-util-cursor
|
||||
libXext
|
||||
libXi
|
||||
libxkbfile
|
||||
nspr
|
||||
nss
|
||||
stdenv.cc.cc.lib
|
||||
zlib
|
||||
]);
|
||||
|
||||
pkgConfigPath = pkgs.lib.makeSearchPath "lib/pkgconfig" [
|
||||
sdl2Pkgs.SDL2.dev
|
||||
pkgs.curl.dev
|
||||
@@ -180,9 +206,9 @@ EOF
|
||||
|
||||
export MCFGTHREADS="${mcfgthreads}"
|
||||
export WIN32_MCFGTHREADS="${mcfgthreads32}"
|
||||
export CPATH="$MCFGTHREADS/include:$CPATH"
|
||||
export LIBRARY_PATH="$MCFGTHREADS/lib:$LIBRARY_PATH"
|
||||
export LDFLAGS="-L$MCFGTHREADS/lib $LDFLAGS"
|
||||
export CPATH="$MCFGTHREADS/include:$WIN32_MCFGTHREADS/include:$CPATH"
|
||||
export LIBRARY_PATH="$MCFGTHREADS/lib:$WIN32_MCFGTHREADS/lib:$LIBRARY_PATH"
|
||||
export LDFLAGS="-L$MCFGTHREADS/lib -L$WIN32_MCFGTHREADS/lib $LDFLAGS"
|
||||
'';
|
||||
in
|
||||
(pkgs.buildFHSEnv {
|
||||
@@ -212,6 +238,27 @@ EOF
|
||||
libgbm
|
||||
libglvnd
|
||||
libglvnd.dev
|
||||
dbus
|
||||
expat
|
||||
fontconfig
|
||||
freetype
|
||||
libbsd
|
||||
libmd
|
||||
libice
|
||||
libsm
|
||||
libxcb
|
||||
libxau
|
||||
libxdmcp
|
||||
libxkbcommon
|
||||
xcb-util-cursor
|
||||
libXi
|
||||
libXext
|
||||
libxkbfile
|
||||
nspr
|
||||
nss
|
||||
libpng
|
||||
libuuid
|
||||
libx11
|
||||
alsa-lib
|
||||
appimagetool
|
||||
libpulseaudio
|
||||
@@ -255,6 +302,7 @@ EOF
|
||||
export ANDROID_HOME="${sdk}/libexec/android-sdk"
|
||||
export ANDROID_SDK_ROOT="${sdk}/libexec/android-sdk"
|
||||
export ANDROID_NDK_ROOT="${ndkPath}"
|
||||
export ANDROID_EMULATOR_LD_LIBRARY_PATH="$ANDROID_HOME/emulator/lib64:$ANDROID_HOME/emulator/lib64/qt/lib:${emulatorRuntimeLibraryPath}"
|
||||
export CCACHE_DIR="$PWD/.ccache"
|
||||
export CCACHE_BASEDIR="$PWD"
|
||||
export CCACHE_COMPRESS=1
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Prijmout
|
||||
[profile_friend_decline_button]
|
||||
Odmitnout
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Odebrat pritele?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s bude odebran. Pro obnoveni poslete novou zadost.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Aktualizace
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Socialni
|
||||
[profile_add_friend_button]
|
||||
Pridat pritele
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Obnovit
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Prichozi
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Použijte https:// nebo loopback jako localhost:8080
|
||||
[sync_server_saved]
|
||||
Synchronizační server uložen
|
||||
---
|
||||
[sync_connected]
|
||||
Vzdálená synchronizace dokončena
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Vzdálená synchronizace selhala
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Annehmen
|
||||
[profile_friend_decline_button]
|
||||
Ablehnen
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Freund entfernen?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s wird entfernt. Sende eine neue Anfrage zum Wiederverbinden.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Aktualisieren
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Sozial
|
||||
[profile_add_friend_button]
|
||||
Freund hinzufuegen
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Aktualisieren
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Eingehend
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Nutze https:// oder Loopback wie localhost:8080
|
||||
[sync_server_saved]
|
||||
Sync-Server gespeichert
|
||||
---
|
||||
[sync_connected]
|
||||
Remote-Sync abgeschlossen
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Remote-Sync fehlgeschlagen
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Accept
|
||||
[profile_friend_decline_button]
|
||||
Decline
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Remove friend?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s will be removed. Send a new request to reconnect.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Updating
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Social
|
||||
[profile_add_friend_button]
|
||||
Add friend
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Refresh
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Incoming
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -827,8 +845,20 @@ Use https:// or loopback like localhost:8080
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Aceptar
|
||||
[profile_friend_decline_button]
|
||||
Rechazar
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
¿Eliminar amigo?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
Se eliminara a %s. Envia una nueva solicitud para reconectar.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Actualizando
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Social
|
||||
[profile_add_friend_button]
|
||||
Anadir amigo
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Actualizar
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Entrantes
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Usa https:// o loopback como localhost:8080
|
||||
[sync_server_saved]
|
||||
Servidor de sincronización guardado
|
||||
---
|
||||
[sync_connected]
|
||||
Sincronización remota completa
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Falló la sincronización remota
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Accepter
|
||||
[profile_friend_decline_button]
|
||||
Refuser
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Supprimer l'ami ?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s sera supprime. Envoyez une nouvelle demande pour vous reconnecter.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Mise a jour
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Social
|
||||
[profile_add_friend_button]
|
||||
Ajouter un ami
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Actualiser
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Recues
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -827,8 +845,20 @@ Utilisez https:// ou une boucle locale comme localhost:8080
|
||||
[sync_server_saved]
|
||||
Serveur de synchronisation enregistré
|
||||
---
|
||||
[sync_connected]
|
||||
Synchronisation distante terminée
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Échec de la synchronisation distante
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Terima
|
||||
[profile_friend_decline_button]
|
||||
Tolak
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Hapus teman?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s akan dihapus. Kirim permintaan baru untuk terhubung lagi.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Memperbarui
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Sosial
|
||||
[profile_add_friend_button]
|
||||
Tambah teman
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Segarkan
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Masuk
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Gunakan https:// atau loopback seperti localhost:8080
|
||||
[sync_server_saved]
|
||||
Server sinkronisasi disimpan
|
||||
---
|
||||
[sync_connected]
|
||||
Sinkronisasi remote selesai
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Sinkronisasi remote gagal
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Accetta
|
||||
[profile_friend_decline_button]
|
||||
Rifiuta
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Rimuovere amico?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s sara rimosso. Invia una nuova richiesta per riconnetterti.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Aggiornamento
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Social
|
||||
[profile_add_friend_button]
|
||||
Aggiungi amico
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Aggiorna
|
||||
---
|
||||
[profile_incoming_title]
|
||||
In arrivo
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Usa https:// o loopback come localhost:8080
|
||||
[sync_server_saved]
|
||||
Server di sincronizzazione salvato
|
||||
---
|
||||
[sync_connected]
|
||||
Sincronizzazione remota completata
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Sincronizzazione remota fallita
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Pet
|
||||
[profile_friend_decline_button]
|
||||
拒否
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
フレンドを削除?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s を削除します。再接続には新しいリクエストが必要です。
|
||||
---
|
||||
[profile_updating_status]
|
||||
更新中
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Pet
|
||||
[profile_add_friend_button]
|
||||
フレンドを追加
|
||||
---
|
||||
[profile_refresh_button]
|
||||
更新
|
||||
---
|
||||
[profile_incoming_title]
|
||||
受信
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ https:// または localhost:8080 のようなループバックを使用して
|
||||
[sync_server_saved]
|
||||
同期サーバーを保存しました
|
||||
---
|
||||
[sync_connected]
|
||||
リモート同期が完了しました
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
リモート同期に失敗しました
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Pet
|
||||
[profile_friend_decline_button]
|
||||
거절
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
친구 삭제?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s 님이 삭제됩니다. 다시 연결하려면 새 요청을 보내세요.
|
||||
---
|
||||
[profile_updating_status]
|
||||
업데이트 중
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Pet
|
||||
[profile_add_friend_button]
|
||||
친구 추가
|
||||
---
|
||||
[profile_refresh_button]
|
||||
새로 고침
|
||||
---
|
||||
[profile_incoming_title]
|
||||
받은 요청
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -784,8 +802,20 @@ https:// 또는 localhost:8080 같은 루프백을 사용하세요
|
||||
[sync_server_saved]
|
||||
동기화 서버 저장됨
|
||||
---
|
||||
[sync_connected]
|
||||
원격 동기화 완료
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
원격 동기화 실패
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Aceitar
|
||||
[profile_friend_decline_button]
|
||||
Recusar
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Remover amigo?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s sera removido. Envie uma nova solicitacao para reconectar.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Atualizando
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Social
|
||||
[profile_add_friend_button]
|
||||
Adicionar amigo
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Atualizar
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Recebidos
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ Use https:// ou loopback como localhost:8080
|
||||
[sync_server_saved]
|
||||
Servidor de sincronização salvo
|
||||
---
|
||||
[sync_connected]
|
||||
Sincronização remota concluída
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Falha na sincronização remota
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Pet
|
||||
[profile_friend_decline_button]
|
||||
Отклонить
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
Удалить друга?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
%s будет удален. Для связи отправьте новый запрос.
|
||||
---
|
||||
[profile_updating_status]
|
||||
Обновление
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Pet
|
||||
[profile_add_friend_button]
|
||||
Добавить друга
|
||||
---
|
||||
[profile_refresh_button]
|
||||
Обновить
|
||||
---
|
||||
[profile_incoming_title]
|
||||
Входящие
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -785,8 +803,20 @@ liboqs не собран для этой платформы.
|
||||
[sync_server_saved]
|
||||
Сервер синхронизации сохранен
|
||||
---
|
||||
[sync_connected]
|
||||
Удаленная синхронизация завершена
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
Удаленная синхронизация не удалась
|
||||
|
||||
+35
-5
@@ -67,6 +67,12 @@ Pet
|
||||
[profile_friend_decline_button]
|
||||
拒绝
|
||||
---
|
||||
[profile_friend_remove_title]
|
||||
删除好友?
|
||||
---
|
||||
[profile_friend_remove_message]
|
||||
将删除 %s。重新连接需发送新请求。
|
||||
---
|
||||
[profile_updating_status]
|
||||
正在更新
|
||||
---
|
||||
@@ -97,9 +103,6 @@ Pet
|
||||
[profile_add_friend_button]
|
||||
添加好友
|
||||
---
|
||||
[profile_refresh_button]
|
||||
刷新
|
||||
---
|
||||
[profile_incoming_title]
|
||||
收到
|
||||
---
|
||||
@@ -121,6 +124,21 @@ My practices
|
||||
[profile_my_habits_title]
|
||||
My habits
|
||||
---
|
||||
[profile_habits_section]
|
||||
Habits
|
||||
---
|
||||
[profile_habits_today_format]
|
||||
%d / %d done today
|
||||
---
|
||||
[profile_habit_done_today]
|
||||
Done
|
||||
---
|
||||
[profile_habit_not_done_today]
|
||||
Not done
|
||||
---
|
||||
[profile_manage_habits_button]
|
||||
Manage habits
|
||||
---
|
||||
[profile_my_practices_title]
|
||||
My practices
|
||||
---
|
||||
@@ -783,8 +801,20 @@ liboqs 未为此目标构建。
|
||||
[sync_server_saved]
|
||||
同步服务器已保存
|
||||
---
|
||||
[sync_connected]
|
||||
远程同步完成
|
||||
[sync_review_needed]
|
||||
Sync needs review
|
||||
---
|
||||
[sync_review_message]
|
||||
Review data differences.
|
||||
---
|
||||
[sync_review_using_remote]
|
||||
Using remote data
|
||||
---
|
||||
[sync_review_keeping_local]
|
||||
Keeping local data
|
||||
---
|
||||
[sync_review_failed]
|
||||
Sync review failed
|
||||
---
|
||||
[sync_failed]
|
||||
远程同步失败
|
||||
|
||||
@@ -4,7 +4,7 @@ set -e
|
||||
|
||||
AVD_NAME="${1:-inbe-test}"
|
||||
|
||||
echo "📱 Creating AVD: $AVD_NAME (Pixel 8 Pro - Android 14, punch-hole test profile)"
|
||||
echo "📱 Creating AVD: $AVD_NAME (Pixel 8 Pro - Android 15, punch-hole test profile)"
|
||||
|
||||
# Check for Android SDK location
|
||||
if [ -z "$ANDROID_SDK_ROOT" ] && [ -z "$ANDROID_HOME" ]; then
|
||||
@@ -31,7 +31,7 @@ done
|
||||
mkdir -p "$ANDROID_SDK_ROOT/system-images"
|
||||
mkdir -p "$ANDROID_SDK_ROOT/avd"
|
||||
|
||||
ANDROID_API="${ANDROID_API:-34}"
|
||||
ANDROID_API="${ANDROID_API:-35}"
|
||||
SYSTEM_IMAGE_TYPE=""
|
||||
ABI_TYPE=""
|
||||
SOURCE_DIR=""
|
||||
@@ -175,7 +175,7 @@ EOF
|
||||
|
||||
echo "✅ Done!"
|
||||
echo " Device: Pixel 8 Pro"
|
||||
echo " Android: 14 (API $ANDROID_API)"
|
||||
echo " Android: 15 (API $ANDROID_API)"
|
||||
echo " ABI: $ABI_DISPLAY"
|
||||
echo " Cutout: punch-hole overlay enabled by scripts/emulator.sh after boot"
|
||||
echo ""
|
||||
|
||||
+12
-2
@@ -45,6 +45,9 @@ if [ ! -x "$EMULATOR_CMD" ]; then
|
||||
EMULATOR_CMD="$(command -v emulator)"
|
||||
fi
|
||||
|
||||
EMULATOR_DIR="$(cd "$(dirname "$EMULATOR_CMD")" && pwd)"
|
||||
EMULATOR_LD_LIBRARY_PATH="${ANDROID_EMULATOR_LD_LIBRARY_PATH:-$EMULATOR_DIR/lib64:$EMULATOR_DIR/lib64/qt/lib}"
|
||||
|
||||
# Check if emulator is already running
|
||||
if "$ADB_CMD" devices | grep -q '^emulator-[0-9][0-9]*[[:space:]]*device'; then
|
||||
echo "✅ Emulator already running"
|
||||
@@ -52,14 +55,21 @@ if "$ADB_CMD" devices | grep -q '^emulator-[0-9][0-9]*[[:space:]]*device'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "🚀 Launching Pixel 8 Pro emulator (Android 14 API 34)..."
|
||||
if LD_LIBRARY_PATH="$EMULATOR_LD_LIBRARY_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" ldd "$EMULATOR_CMD" 2>/dev/null | grep -q "not found"; then
|
||||
echo "❌ Emulator runtime libraries are missing."
|
||||
echo " Re-enter the repo flake shell so the updated emulator LD_LIBRARY_PATH is active:"
|
||||
echo " nix develop --impure"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🚀 Launching Pixel 8 Pro emulator (Android 15 API 35)..."
|
||||
|
||||
# Set environment for emulator
|
||||
unset ANDROID_HOME
|
||||
export ANDROID_SDK_ROOT="$ANDROID_SDK_ROOT"
|
||||
|
||||
# Launch emulator in background with KVM acceleration
|
||||
"$EMULATOR_CMD" @"$AVD_NAME" \
|
||||
LD_LIBRARY_PATH="$EMULATOR_LD_LIBRARY_PATH${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" "$EMULATOR_CMD" @"$AVD_NAME" \
|
||||
-gpu host \
|
||||
-skin 1440x2960 \
|
||||
-no-snapshot-load \
|
||||
|
||||
+21
-777
@@ -7,6 +7,7 @@
|
||||
#endif
|
||||
|
||||
#include "app.h"
|
||||
#include "app_sync.h"
|
||||
#include "data.h"
|
||||
#include "flint_locale.h"
|
||||
#include "screens/language_screen.h"
|
||||
@@ -21,8 +22,6 @@
|
||||
#include "practices/practice_registry.h"
|
||||
#include "device_preferences.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "sync_client.h"
|
||||
#include "flint_theme.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
@@ -38,15 +37,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if ANDROID_BUILD
|
||||
#include "android_wakelock.h"
|
||||
#include "android_device.h"
|
||||
@@ -64,8 +54,6 @@ InbeApp *get_global_inbe_app(void);
|
||||
#define INBE_DEFAULT_WIDTH 900
|
||||
#define INBE_DEFAULT_HEIGHT 720
|
||||
#endif
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_INPUT_QUIET_SECONDS 0.45
|
||||
|
||||
enum {
|
||||
APP_SCREEN_TRANSITION_TICKS = 8
|
||||
@@ -79,766 +67,6 @@ InbeConfig config = {
|
||||
.title_custom = 1
|
||||
};
|
||||
|
||||
static double g_dirty_sync_at = 0.0;
|
||||
static double g_last_sync_input_at = 0.0;
|
||||
static int g_sync_running = 0;
|
||||
static int g_sync_refresh_pending = 0;
|
||||
static int g_social_refresh_pending = 0;
|
||||
static int g_social_refresh_running = 0;
|
||||
static int g_remote_sync_due = 0;
|
||||
static char g_social_pending_action[16];
|
||||
static char g_social_pending_value[96];
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
typedef struct InbeSyncWorkerArgs {
|
||||
char url[256];
|
||||
} InbeSyncWorkerArgs;
|
||||
|
||||
typedef struct InbeSocialWorkerArgs {
|
||||
char url[256];
|
||||
char practice[32];
|
||||
char metric[32];
|
||||
char leaderboard_key[96];
|
||||
char action[16];
|
||||
char action_value[96];
|
||||
} InbeSocialWorkerArgs;
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define sync_thread_return DWORD WINAPI
|
||||
#define sync_thread_done 0
|
||||
#define sync_sleep(seconds) Sleep((DWORD)((seconds) * 1000))
|
||||
#define sync_lock() AcquireSRWLockExclusive(&g_sync_mutex)
|
||||
#define sync_unlock() ReleaseSRWLockExclusive(&g_sync_mutex)
|
||||
typedef HANDLE SyncThread;
|
||||
static SRWLOCK g_sync_mutex = SRWLOCK_INIT;
|
||||
static int
|
||||
sync_thread_start(SyncThread *thread, LPTHREAD_START_ROUTINE func, void *arg)
|
||||
{
|
||||
*thread = CreateThread(NULL, 0, func, arg, 0, NULL);
|
||||
return *thread != NULL;
|
||||
}
|
||||
static void
|
||||
sync_thread_detach(SyncThread thread)
|
||||
{
|
||||
CloseHandle(thread);
|
||||
}
|
||||
#else
|
||||
#define sync_thread_return void *
|
||||
#define sync_thread_done NULL
|
||||
#define sync_sleep(seconds) sleep(seconds)
|
||||
#define sync_lock() pthread_mutex_lock(&g_sync_mutex)
|
||||
#define sync_unlock() pthread_mutex_unlock(&g_sync_mutex)
|
||||
typedef pthread_t SyncThread;
|
||||
static pthread_mutex_t g_sync_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int
|
||||
sync_thread_start(SyncThread *thread, void *(*func)(void *), void *arg)
|
||||
{
|
||||
return pthread_create(thread, NULL, func, arg) == 0;
|
||||
}
|
||||
static void
|
||||
sync_thread_detach(SyncThread thread)
|
||||
{
|
||||
pthread_detach(thread);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int g_sync_finished = 0;
|
||||
static int g_sync_finished_result = FLINT_LYRA_SYNC_OK;
|
||||
static int g_sync_finished_changed = 0;
|
||||
static int g_social_finished = 0;
|
||||
static int g_social_finished_result = FLINT_LYRA_SYNC_OK;
|
||||
static char g_social_friend_requests_json[8192];
|
||||
static char g_social_friends_json[8192];
|
||||
static char g_social_leaderboard_json[8192];
|
||||
static char g_social_leaderboard_key[96];
|
||||
static int g_sync_events_running = 0;
|
||||
static char g_sync_events_url[256];
|
||||
|
||||
static int app_sync_url(char *url, size_t url_size);
|
||||
static const char *app_social_practice_id(int practice);
|
||||
static const char *app_social_metric_id(int practice, int metric);
|
||||
static void app_social_leaderboard_key(char *out, size_t out_size,
|
||||
int practice, int metric);
|
||||
|
||||
static sync_thread_return
|
||||
app_sync_worker(void *userdata)
|
||||
{
|
||||
InbeSyncWorkerArgs *args = userdata;
|
||||
FlintLyraSyncResult result = FLINT_LYRA_SYNC_INVALID_URL;
|
||||
int changed = 0;
|
||||
|
||||
if(args != NULL) {
|
||||
result = sync_client_sync(args->url);
|
||||
changed = result == FLINT_LYRA_SYNC_OK && storage_last_sync_changed();
|
||||
free(args);
|
||||
}
|
||||
|
||||
sync_lock();
|
||||
g_sync_finished_result = result;
|
||||
g_sync_finished_changed = changed;
|
||||
g_sync_finished = 1;
|
||||
g_sync_running = 0;
|
||||
sync_unlock();
|
||||
return sync_thread_done;
|
||||
}
|
||||
|
||||
static sync_thread_return
|
||||
app_social_worker(void *userdata)
|
||||
{
|
||||
InbeSocialWorkerArgs *args = userdata;
|
||||
FlintLyraSyncResult result = FLINT_LYRA_SYNC_INVALID_URL;
|
||||
FlintLyraSyncResult friends_result = FLINT_LYRA_SYNC_REQUEST_FAILED;
|
||||
FlintLyraSyncResult leaderboard_result = FLINT_LYRA_SYNC_REQUEST_FAILED;
|
||||
char requests_json[8192] = "{\"incoming\":[],\"outgoing\":[]}";
|
||||
char friends_json[8192] = "{\"friends\":[]}";
|
||||
char leaderboard_json[8192] = "{\"rows\":[]}";
|
||||
|
||||
if(args != NULL) {
|
||||
if(strcmp(args->action, "send") == 0) {
|
||||
result = sync_client_send_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
} else if(strcmp(args->action, "accept") == 0) {
|
||||
result = sync_client_accept_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
} else if(strcmp(args->action, "decline") == 0) {
|
||||
result = sync_client_decline_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
}
|
||||
result = sync_client_get_friend_requests(args->url, requests_json,
|
||||
sizeof(requests_json));
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
friends_result = sync_client_get_friends(args->url, friends_json,
|
||||
sizeof(friends_json));
|
||||
leaderboard_result =
|
||||
sync_client_get_friend_stats(args->url, "inbe", args->practice,
|
||||
args->metric, leaderboard_json,
|
||||
sizeof(leaderboard_json));
|
||||
if(friends_result != FLINT_LYRA_SYNC_OK)
|
||||
result = friends_result;
|
||||
else if(leaderboard_result != FLINT_LYRA_SYNC_OK)
|
||||
result = leaderboard_result;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
sync_lock();
|
||||
g_social_finished_result = result;
|
||||
snprintf(g_social_friend_requests_json, sizeof(g_social_friend_requests_json),
|
||||
"%s", requests_json);
|
||||
snprintf(g_social_friends_json, sizeof(g_social_friends_json), "%s",
|
||||
friends_json);
|
||||
snprintf(g_social_leaderboard_json, sizeof(g_social_leaderboard_json), "%s",
|
||||
leaderboard_json);
|
||||
snprintf(g_social_leaderboard_key, sizeof(g_social_leaderboard_key), "%s",
|
||||
args != NULL ? args->leaderboard_key : "");
|
||||
g_social_finished = 1;
|
||||
g_social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
free(args);
|
||||
return sync_thread_done;
|
||||
}
|
||||
|
||||
static void
|
||||
app_collect_finished_sync(void)
|
||||
{
|
||||
int finished;
|
||||
int result;
|
||||
int changed;
|
||||
|
||||
sync_lock();
|
||||
finished = g_sync_finished;
|
||||
result = g_sync_finished_result;
|
||||
changed = g_sync_finished_changed;
|
||||
g_sync_finished = 0;
|
||||
sync_unlock();
|
||||
|
||||
if(!finished)
|
||||
return;
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
TraceLog(LOG_INFO, "SYNC: background sync complete changed=%d", changed);
|
||||
g_social_refresh_pending = 1;
|
||||
if(changed)
|
||||
g_sync_refresh_pending = 1;
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: background sync failed result=%d name=%s",
|
||||
result, flint_lyra_sync_result_name(result));
|
||||
}
|
||||
}
|
||||
|
||||
static sync_thread_return
|
||||
app_sync_events_worker(void *userdata)
|
||||
{
|
||||
InbeSyncWorkerArgs *args = userdata;
|
||||
|
||||
if(args == NULL)
|
||||
return sync_thread_done;
|
||||
for(;;) {
|
||||
FlintLyraSyncResult result;
|
||||
sync_lock();
|
||||
if(g_sync_running) {
|
||||
sync_unlock();
|
||||
sync_sleep(1);
|
||||
continue;
|
||||
}
|
||||
sync_unlock();
|
||||
|
||||
result = sync_client_wait_for_remote_event(args->url);
|
||||
sync_lock();
|
||||
if(result == FLINT_LYRA_SYNC_OK)
|
||||
g_remote_sync_due = 1;
|
||||
sync_unlock();
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
sync_sleep(2);
|
||||
}
|
||||
return sync_thread_done;
|
||||
}
|
||||
|
||||
static void
|
||||
app_ensure_sync_events(const char *url)
|
||||
{
|
||||
SyncThread thread;
|
||||
InbeSyncWorkerArgs *args;
|
||||
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return;
|
||||
sync_lock();
|
||||
if(g_sync_events_running && strcmp(g_sync_events_url, url) == 0) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
if(g_sync_events_running) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
g_sync_events_running = 1;
|
||||
g_remote_sync_due = 1;
|
||||
snprintf(g_sync_events_url, sizeof(g_sync_events_url), "%s", url);
|
||||
sync_unlock();
|
||||
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_sync_events_running = 0;
|
||||
g_sync_events_url[0] = '\0';
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
if(!sync_thread_start(&thread, app_sync_events_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_sync_events_running = 0;
|
||||
g_sync_events_url[0] = '\0';
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start websocket event thread");
|
||||
return;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
TraceLog(LOG_INFO, "SYNC: websocket event listener started");
|
||||
}
|
||||
#else
|
||||
static char g_sync_events_url[256];
|
||||
static double g_sync_events_retry_at = 0.0;
|
||||
|
||||
static void
|
||||
app_collect_finished_sync(void)
|
||||
{
|
||||
FlintLyraSyncResult result;
|
||||
int changed = 0;
|
||||
|
||||
if(sync_client_web_poll_remote_event())
|
||||
g_remote_sync_due = 1;
|
||||
if(!g_sync_running)
|
||||
return;
|
||||
if(!sync_client_web_sync_poll(&result, &changed))
|
||||
return;
|
||||
g_sync_running = 0;
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
TraceLog(LOG_INFO, "SYNC: background sync complete changed=%d", changed);
|
||||
g_social_refresh_pending = 1;
|
||||
if(changed)
|
||||
g_sync_refresh_pending = 1;
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: background sync failed result=%d name=%s",
|
||||
result, flint_lyra_sync_result_name(result));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
app_ensure_sync_events(const char *url)
|
||||
{
|
||||
double now;
|
||||
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return;
|
||||
if(strcmp(g_sync_events_url, url) == 0) {
|
||||
sync_client_web_start_remote_events(url);
|
||||
return;
|
||||
}
|
||||
now = GetTime();
|
||||
if(now < g_sync_events_retry_at)
|
||||
return;
|
||||
if(!sync_client_web_start_remote_events(url)) {
|
||||
g_sync_events_retry_at = now + 2.0;
|
||||
return;
|
||||
}
|
||||
g_remote_sync_due = 1;
|
||||
snprintf(g_sync_events_url, sizeof(g_sync_events_url), "%s", url);
|
||||
TraceLog(LOG_INFO, "SYNC: websocket event listener started");
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
app_background_sync_safe(const InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(app->modal.active)
|
||||
return 0;
|
||||
if(app->habit_edit.active ||
|
||||
app->sync_server_url_focused ||
|
||||
app->sync_alias_focused ||
|
||||
app->profile_friend_input_focused)
|
||||
return 0;
|
||||
if(app->inbe.screen == InbeScreenPracticeSession ||
|
||||
app->inbe.screen == InbeScreenMeditation ||
|
||||
app->inbe.screen == InbeScreenSunSalutation)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_modal_type_name(UIModalType type)
|
||||
{
|
||||
switch(type) {
|
||||
case UIModalNone: return "none";
|
||||
case UIModalConfirmExitSession: return "confirm_exit_session";
|
||||
case UIModalMeditationSetup: return "meditation_setup";
|
||||
case UIModalConfirmDeleteData: return "confirm_delete_data";
|
||||
case UIModalConfirmDeleteHabit: return "confirm_delete_habit";
|
||||
case UIModalEditProgressiveStartSpeed: return "edit_progressive_start_speed";
|
||||
case UIModalMeditationNetworkError: return "meditation_network_error";
|
||||
case UIModalConfirmImportDataSettings: return "confirm_import_data_settings";
|
||||
case UIModalSyncAccountBackup: return "sync_account_backup";
|
||||
case UIModalConfirmDeleteSyncAccount: return "confirm_delete_sync_account";
|
||||
case UIModalHabitPracticeListInfo: return "habit_practice_list_info";
|
||||
case UIModalHabitCountingInfo: return "habit_counting_info";
|
||||
case UIModalPracticeManual: return "practice_manual";
|
||||
case UIModalPracticeConfig: return "practice_config";
|
||||
case UIModalThemePicker: return "theme_picker";
|
||||
case UIModalSyncReview: return "sync_review";
|
||||
case UIModalSyncAlias: return "sync_alias";
|
||||
case UIModalSyncPublicId: return "sync_public_id";
|
||||
default: break;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static int
|
||||
app_input_active(void)
|
||||
{
|
||||
return IsMouseButtonDown(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonDown(MOUSE_BUTTON_RIGHT) ||
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ||
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
static void
|
||||
app_apply_pending_sync_refresh(InbeApp *app)
|
||||
{
|
||||
if(!g_sync_refresh_pending || !app_background_sync_safe(app))
|
||||
return;
|
||||
g_sync_refresh_pending = 0;
|
||||
TraceLog(LOG_INFO, "SYNC: applying remote refresh");
|
||||
app_reload_after_import(app, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
app_apply_pending_social_refresh(InbeApp *app)
|
||||
{
|
||||
char url[256];
|
||||
char action[16] = "";
|
||||
char action_value[96] = "";
|
||||
|
||||
if(!g_social_refresh_pending || !app_background_sync_safe(app))
|
||||
return;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
{
|
||||
SyncThread thread;
|
||||
InbeSocialWorkerArgs *args;
|
||||
|
||||
sync_lock();
|
||||
if(g_sync_running || g_social_refresh_running) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(action, sizeof(action), "%s", g_social_pending_action);
|
||||
snprintf(action_value, sizeof(action_value), "%s", g_social_pending_value);
|
||||
g_social_pending_action[0] = '\0';
|
||||
g_social_pending_value[0] = '\0';
|
||||
g_social_refresh_running = 1;
|
||||
sync_unlock();
|
||||
|
||||
if(!app_sync_url(url, sizeof(url))) {
|
||||
sync_lock();
|
||||
g_social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
g_social_refresh_pending = 0;
|
||||
return;
|
||||
}
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
snprintf(args->practice, sizeof(args->practice), "%s",
|
||||
app_social_practice_id(app->profile_leaderboard_practice));
|
||||
snprintf(args->metric, sizeof(args->metric), "%s",
|
||||
app_social_metric_id(app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric));
|
||||
app_social_leaderboard_key(args->leaderboard_key,
|
||||
sizeof(args->leaderboard_key),
|
||||
app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric);
|
||||
snprintf(args->action, sizeof(args->action), "%s", action);
|
||||
snprintf(args->action_value, sizeof(args->action_value), "%s", action_value);
|
||||
TraceLog(LOG_INFO, "SYNC: starting background social refresh");
|
||||
if(!sync_thread_start(&thread, app_social_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start social refresh thread");
|
||||
return;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
}
|
||||
#else
|
||||
TraceLog(LOG_INFO, "SYNC: refreshing social cache");
|
||||
profile_screen_refresh_social_cache(app);
|
||||
#endif
|
||||
g_social_refresh_pending = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
app_sync_url(char *url, size_t url_size)
|
||||
{
|
||||
const char *saved_url;
|
||||
InbeSyncAccount account;
|
||||
|
||||
if(url == NULL || url_size == 0)
|
||||
return 0;
|
||||
url[0] = '\0';
|
||||
if(!sync_account_load(&account))
|
||||
return 0;
|
||||
saved_url = storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
if(!sync_client_normalize_url(saved_url != NULL && saved_url[0] != '\0'
|
||||
? saved_url
|
||||
: "https://api.waozi.xyz",
|
||||
url, url_size))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_social_practice_id(int practice)
|
||||
{
|
||||
switch(practice) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return "meditation";
|
||||
case EXERCISE_SUN_SALUTATION:
|
||||
return "sun_salutation";
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return "whm";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_social_metric_id(int practice, int metric)
|
||||
{
|
||||
if(metric != 1)
|
||||
return "streak";
|
||||
return practice == EXERCISE_MEDITATION ? "avg_time" : "avg_hold";
|
||||
}
|
||||
|
||||
static void
|
||||
app_social_leaderboard_key(char *out, size_t out_size, int practice, int metric)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
snprintf(out, out_size, "leaderboard.inbe.%s.%s",
|
||||
app_social_practice_id(practice),
|
||||
app_social_metric_id(practice, metric));
|
||||
}
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
static void
|
||||
app_collect_finished_social_refresh(InbeApp *app)
|
||||
{
|
||||
int finished;
|
||||
int result;
|
||||
char requests_json[8192];
|
||||
char friends_json[8192];
|
||||
char leaderboard_json[8192];
|
||||
char leaderboard_key[96];
|
||||
|
||||
sync_lock();
|
||||
finished = g_social_finished;
|
||||
result = g_social_finished_result;
|
||||
if(finished) {
|
||||
snprintf(requests_json, sizeof(requests_json), "%s",
|
||||
g_social_friend_requests_json);
|
||||
snprintf(friends_json, sizeof(friends_json), "%s", g_social_friends_json);
|
||||
snprintf(leaderboard_json, sizeof(leaderboard_json), "%s",
|
||||
g_social_leaderboard_json);
|
||||
snprintf(leaderboard_key, sizeof(leaderboard_key), "%s",
|
||||
g_social_leaderboard_key);
|
||||
g_social_finished = 0;
|
||||
}
|
||||
sync_unlock();
|
||||
|
||||
if(!finished)
|
||||
return;
|
||||
if(result != FLINT_LYRA_SYNC_OK) {
|
||||
TraceLog(LOG_WARNING, "SYNC: social refresh failed result=%d name=%s",
|
||||
result, flint_lyra_sync_result_name(result));
|
||||
return;
|
||||
}
|
||||
storage_set_social_cache_json("friends.requests", requests_json);
|
||||
storage_set_social_cache_json("friends.list", friends_json);
|
||||
if(leaderboard_key[0] != '\0')
|
||||
storage_set_social_cache_json(leaderboard_key, leaderboard_json);
|
||||
if(app != NULL) {
|
||||
snprintf(app->profile_friend_requests_json,
|
||||
sizeof(app->profile_friend_requests_json), "%s", requests_json);
|
||||
snprintf(app->profile_friends_json, sizeof(app->profile_friends_json),
|
||||
"%s", friends_json);
|
||||
if(leaderboard_key[0] != '\0') {
|
||||
char current_key[96];
|
||||
app_social_leaderboard_key(current_key, sizeof(current_key),
|
||||
app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric);
|
||||
if(strcmp(current_key, leaderboard_key) == 0)
|
||||
snprintf(app->profile_leaderboard_json,
|
||||
sizeof(app->profile_leaderboard_json), "%s",
|
||||
leaderboard_json);
|
||||
}
|
||||
app->profile_friends_loaded = 1;
|
||||
app->profile_leaderboard_loaded = 1;
|
||||
}
|
||||
TraceLog(LOG_INFO, "SYNC: social cache refreshed");
|
||||
}
|
||||
#else
|
||||
static void
|
||||
app_collect_finished_social_refresh(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
app_request_social_refresh(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
g_social_refresh_pending = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
app_request_social_action(const char *action, const char *value)
|
||||
{
|
||||
if(action == NULL || action[0] == '\0' || value == NULL || value[0] == '\0')
|
||||
return;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_lock();
|
||||
snprintf(g_social_pending_action, sizeof(g_social_pending_action), "%s", action);
|
||||
snprintf(g_social_pending_value, sizeof(g_social_pending_value), "%s", value);
|
||||
g_social_refresh_pending = 1;
|
||||
sync_unlock();
|
||||
#else
|
||||
g_social_refresh_pending = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_send(InbeApp *app, const char *target)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("send", target);
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_accept(InbeApp *app, const char *request_id)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("accept", request_id);
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_decline(InbeApp *app, const char *request_id)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("decline", request_id);
|
||||
}
|
||||
|
||||
static int
|
||||
app_sync_now(InbeApp *app)
|
||||
{
|
||||
char url[256];
|
||||
|
||||
if(app == NULL || !app_sync_url(url, sizeof(url)))
|
||||
return 0;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
{
|
||||
SyncThread thread;
|
||||
InbeSyncWorkerArgs *args;
|
||||
|
||||
sync_lock();
|
||||
if(g_sync_running) {
|
||||
sync_unlock();
|
||||
return 0;
|
||||
}
|
||||
g_sync_running = 1;
|
||||
sync_unlock();
|
||||
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_sync_running = 0;
|
||||
sync_unlock();
|
||||
return 0;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
TraceLog(LOG_INFO, "SYNC: starting background sync");
|
||||
if(!sync_thread_start(&thread, app_sync_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_sync_running = 0;
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start background sync thread");
|
||||
return 0;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if(g_sync_running)
|
||||
return 0;
|
||||
g_sync_running = 1;
|
||||
TraceLog(LOG_INFO, "SYNC: starting background sync");
|
||||
if(!sync_client_web_sync_start(url)) {
|
||||
g_sync_running = 0;
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start background sync");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
app_auto_sync(InbeApp *app)
|
||||
{
|
||||
double due;
|
||||
double now;
|
||||
char url[256];
|
||||
|
||||
if(app == NULL || !app_sync_url(url, sizeof(url)))
|
||||
return 0;
|
||||
now = GetTime();
|
||||
g_last_sync_input_at = now;
|
||||
due = now + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
if(g_dirty_sync_at <= 0.0 || due < g_dirty_sync_at)
|
||||
g_dirty_sync_at = due;
|
||||
TraceLog(LOG_INFO, "SYNC: queued local changes");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
app_pump_sync(InbeApp *app)
|
||||
{
|
||||
double now;
|
||||
int should_sync = 0;
|
||||
int dirty_due = 0;
|
||||
int repair_due = 0;
|
||||
char url[256];
|
||||
InbeStorageSyncStatus sync_status;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
app_collect_finished_sync();
|
||||
app_collect_finished_social_refresh(app);
|
||||
if(storage_sync_review_pending() && app_background_sync_safe(app)) {
|
||||
if(storage_sync_review_clear_if_no_visible_diff()) {
|
||||
app_reload_after_import(app, 0);
|
||||
} else {
|
||||
app_open_modal(app, UIModalSyncReview);
|
||||
}
|
||||
}
|
||||
app_apply_pending_sync_refresh(app);
|
||||
app_apply_pending_social_refresh(app);
|
||||
if(!app_sync_url(url, sizeof(url)))
|
||||
return;
|
||||
app_ensure_sync_events(url);
|
||||
now = GetTime();
|
||||
if(app_input_active())
|
||||
g_last_sync_input_at = now;
|
||||
if(g_dirty_sync_at > 0.0 && now >= g_dirty_sync_at) {
|
||||
should_sync = 1;
|
||||
dirty_due = 1;
|
||||
}
|
||||
if(storage_sync_status(&sync_status) && sync_status.has_account && sync_status.repair_pending &&
|
||||
(g_dirty_sync_at <= 0.0 || now >= g_dirty_sync_at)) {
|
||||
should_sync = 1;
|
||||
repair_due = 1;
|
||||
}
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_lock();
|
||||
#endif
|
||||
if(g_remote_sync_due) {
|
||||
should_sync = 1;
|
||||
g_remote_sync_due = 0;
|
||||
}
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_unlock();
|
||||
#endif
|
||||
if(!should_sync)
|
||||
return;
|
||||
if(now < g_last_sync_input_at + INBE_SYNC_INPUT_QUIET_SECONDS) {
|
||||
if(g_dirty_sync_at <= 0.0)
|
||||
g_dirty_sync_at = g_last_sync_input_at + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
return;
|
||||
}
|
||||
if(!app_background_sync_safe(app)) {
|
||||
TraceLog(LOG_INFO,
|
||||
"SYNC: delayed; modal=%d type=%s screen=%d pending_review=%d tutorial_seen=%d habits_guide_seen=%d",
|
||||
app->modal.active,
|
||||
app_modal_type_name(app->modal.type),
|
||||
app->inbe.screen,
|
||||
storage_sync_review_pending(),
|
||||
app->tutorial_seen,
|
||||
app->habits_guide_seen);
|
||||
if(g_dirty_sync_at <= 0.0 || repair_due)
|
||||
g_dirty_sync_at = now + 1.0;
|
||||
return;
|
||||
}
|
||||
if(app_sync_now(app)) {
|
||||
if(dirty_due || repair_due)
|
||||
g_dirty_sync_at = 0.0;
|
||||
TraceLog(LOG_INFO, "SYNC: dispatched");
|
||||
} else if(dirty_due || repair_due) {
|
||||
g_dirty_sync_at = now + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
}
|
||||
app_apply_pending_sync_refresh(app);
|
||||
}
|
||||
|
||||
int view_width = INBE_DEFAULT_WIDTH;
|
||||
int view_height = INBE_DEFAULT_HEIGHT;
|
||||
static int app_full_view_width = INBE_DEFAULT_WIDTH;
|
||||
@@ -1715,6 +943,10 @@ draw_global_modal(InbeApp *app)
|
||||
}
|
||||
if(app->modal.type == UIModalThemePicker)
|
||||
settings_screen_draw_theme_picker_modal(app);
|
||||
if(app->modal.type == UIModalConfirmRemoveFriend) {
|
||||
profile_screen_draw_remove_friend_modal(app);
|
||||
return;
|
||||
}
|
||||
if(app->modal.type == UIModalPracticeManual ||
|
||||
app->modal.type == UIModalPracticeConfig ||
|
||||
app->modal.type == UIModalEditProgressiveStartSpeed) {
|
||||
@@ -1751,7 +983,8 @@ static void
|
||||
updateapp(InbeApp *app)
|
||||
{
|
||||
int center_x = view_width / 2;
|
||||
int center_y = view_height / 2;
|
||||
int frame_view_height = view_height;
|
||||
int center_y;
|
||||
int play_center_y;
|
||||
int hover = 0;
|
||||
int frame_screen = app->inbe.screen;
|
||||
@@ -1759,6 +992,7 @@ updateapp(InbeApp *app)
|
||||
int habits_guide_active = 0;
|
||||
int profile_guide_active = 0;
|
||||
int practice_fullscreen_modal = 0;
|
||||
int global_modal_drawn = 0;
|
||||
|
||||
#if !ANDROID_BUILD && !defined(PLATFORM_WEB)
|
||||
app->backgrounded = (!IsWindowFocused() || IsWindowMinimized()) ? 1 : 0;
|
||||
@@ -1786,6 +1020,9 @@ updateapp(InbeApp *app)
|
||||
ui_push_input_capture((Rectangle){0, 0, (float)view_width, (float)view_height}, 0);
|
||||
}
|
||||
|
||||
view_height = app_page_height(app, view_height);
|
||||
center_y = view_height / 2;
|
||||
|
||||
if(IsKeyPressed(KEY_BACK)) {
|
||||
if(first_run_guide_active || habits_guide_active || profile_guide_active) {
|
||||
app->tutorial_step = 0;
|
||||
@@ -1907,15 +1144,22 @@ updateapp(InbeApp *app)
|
||||
}
|
||||
|
||||
finish_frame:
|
||||
if(practice_fullscreen_modal) {
|
||||
draw_global_modal(app);
|
||||
global_modal_drawn = 1;
|
||||
}
|
||||
view_height = frame_view_height;
|
||||
app_draw_bottom_nav(app);
|
||||
practice_screen_draw_first_run_guide(app);
|
||||
habits_screen_draw_first_run_guide(app);
|
||||
profile_screen_draw_first_run_guide(app);
|
||||
draw_global_modal(app);
|
||||
if(!global_modal_drawn)
|
||||
draw_global_modal(app);
|
||||
app_flush_deferred_settings(app);
|
||||
app_observe_direct_screen_change(app, frame_screen);
|
||||
if(app->transition_mode == APP_TRANSITION_FADE) {
|
||||
flint_transition_draw_fade(&app->screen_transition, view_width, view_height,
|
||||
flint_transition_draw_fade(&app->screen_transition, view_width,
|
||||
app_page_height(app, view_height),
|
||||
flint_theme_get_bg());
|
||||
}
|
||||
app_advance_screen_transition(app);
|
||||
@@ -1978,7 +1222,7 @@ app_update_draw(void *vapp, Rectangle viewport) {
|
||||
EndMode2D();
|
||||
flint_clip_end();
|
||||
habits_flush_save(app);
|
||||
app_pump_sync(app);
|
||||
app_sync_pump(app);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -97,6 +97,7 @@ typedef enum {
|
||||
UIModalSyncReview,
|
||||
UIModalSyncAlias,
|
||||
UIModalSyncPublicId,
|
||||
UIModalConfirmRemoveFriend,
|
||||
} UIModalType;
|
||||
|
||||
typedef struct {
|
||||
@@ -284,6 +285,8 @@ struct InbeApp {
|
||||
int profile_friend_input_focused;
|
||||
int profile_friends_loaded;
|
||||
char profile_friend_input[80];
|
||||
char profile_pending_friend_remove_id[80];
|
||||
char profile_pending_friend_remove_name[96];
|
||||
char profile_friends_json[8192];
|
||||
char profile_friend_requests_json[8192];
|
||||
char profile_leaderboard_json[8192];
|
||||
@@ -373,6 +376,7 @@ void app_request_social_refresh(InbeApp *app);
|
||||
void app_request_friend_send(InbeApp *app, const char *target);
|
||||
void app_request_friend_accept(InbeApp *app, const char *request_id);
|
||||
void app_request_friend_decline(InbeApp *app, const char *request_id);
|
||||
void app_request_friend_remove(InbeApp *app, const char *friend_user_id);
|
||||
int app_should_use_tab_bar(const InbeApp *app);
|
||||
void app_play_sound(InbeApp *app, Sound sound, float scale);
|
||||
Texture2D app_load_asset_texture(const char *name);
|
||||
|
||||
+37
-4
@@ -92,7 +92,30 @@ app_content_bottom_reserved(const InbeApp *app)
|
||||
return 0;
|
||||
if(app_current_nav_route(app) == APP_NAV_ROUTE_NONE)
|
||||
return 0;
|
||||
return ui_bottom_nav_height() + app_android_bottom_nav_height();
|
||||
return ui_bottom_nav_height();
|
||||
}
|
||||
|
||||
int
|
||||
app_page_height(const InbeApp *app, int full_height)
|
||||
{
|
||||
int bottom_reserved;
|
||||
|
||||
if(full_height <= 0)
|
||||
return 0;
|
||||
bottom_reserved = app_fullscreen_bottom_reserved(app);
|
||||
if(bottom_reserved > 0 && bottom_reserved < full_height)
|
||||
return full_height - bottom_reserved;
|
||||
return full_height;
|
||||
}
|
||||
|
||||
static int
|
||||
app_has_fullscreen_overlay(const InbeApp *app)
|
||||
{
|
||||
if(app == NULL || !app->modal.active)
|
||||
return 0;
|
||||
return app->modal.type == UIModalPracticeManual ||
|
||||
app->modal.type == UIModalPracticeConfig ||
|
||||
app->modal.type == UIModalEditProgressiveStartSpeed;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@@ -172,9 +195,19 @@ app_should_draw_bottom_nav(const InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(app_has_fullscreen_overlay(app))
|
||||
return 0;
|
||||
return app_current_nav_route(app) != APP_NAV_ROUTE_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
app_fullscreen_bottom_reserved(const InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
return app_android_bottom_nav_height();
|
||||
}
|
||||
|
||||
void
|
||||
app_draw_bottom_nav(InbeApp *app)
|
||||
{
|
||||
@@ -189,6 +222,9 @@ app_draw_bottom_nav(InbeApp *app)
|
||||
FlintUIBottomNavItem items[BOTTOM_NAV_ROUTE_COUNT];
|
||||
FlintUIBottomNavResult result;
|
||||
|
||||
if(app_android_bottom_nav_height() > 0)
|
||||
DrawRectangle(0, view_height - app_android_bottom_nav_height(),
|
||||
view_width, app_android_bottom_nav_height(), BLACK);
|
||||
if(!app_should_draw_bottom_nav(app))
|
||||
return;
|
||||
for(int i = 0; i < BOTTOM_NAV_ROUTE_COUNT; i++) {
|
||||
@@ -201,9 +237,6 @@ app_draw_bottom_nav(InbeApp *app)
|
||||
app->modal.active
|
||||
};
|
||||
}
|
||||
if(app_android_bottom_nav_height() > 0)
|
||||
DrawRectangle(0, view_height - app_android_bottom_nav_height(),
|
||||
view_width, app_android_bottom_nav_height(), BLACK);
|
||||
result = ui_draw_bottom_nav((FlintUIBottomNav){
|
||||
.view_width = view_width,
|
||||
.view_height = view_height,
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#include "app_fwd.h"
|
||||
|
||||
int app_current_nav_route(const InbeApp *app);
|
||||
int app_page_height(const InbeApp *app, int full_height);
|
||||
int app_content_bottom_reserved(const InbeApp *app);
|
||||
int app_fullscreen_bottom_reserved(const InbeApp *app);
|
||||
void app_set_android_bottom_nav_height(int height);
|
||||
int app_android_bottom_nav_height(void);
|
||||
void app_draw_bottom_nav(InbeApp *app);
|
||||
|
||||
@@ -0,0 +1,810 @@
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOGDI
|
||||
#define NOUSER
|
||||
#define MMNOSOUND
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "app_sync.h"
|
||||
|
||||
#include "profile_social.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "sync_client.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#elif !defined(_WIN32)
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_SERVER_URL_DEFAULT "https://api.waozi.xyz"
|
||||
#define INBE_SYNC_INPUT_QUIET_SECONDS 0.45
|
||||
|
||||
typedef struct InbeSyncCoordinator {
|
||||
double dirty_sync_at;
|
||||
double last_input_at;
|
||||
int sync_running;
|
||||
int data_refresh_pending;
|
||||
int social_refresh_pending;
|
||||
int social_refresh_running;
|
||||
int remote_sync_due;
|
||||
char social_action[16];
|
||||
char social_action_value[96];
|
||||
} InbeSyncCoordinator;
|
||||
|
||||
static InbeSyncCoordinator g_sync = {0};
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
typedef struct InbeSyncWorkerArgs {
|
||||
char url[256];
|
||||
} InbeSyncWorkerArgs;
|
||||
|
||||
typedef struct InbeSocialWorkerArgs {
|
||||
char url[256];
|
||||
char practice[32];
|
||||
char metric[32];
|
||||
char leaderboard_key[96];
|
||||
char action[16];
|
||||
char action_value[96];
|
||||
} InbeSocialWorkerArgs;
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define sync_thread_return DWORD WINAPI
|
||||
#define sync_thread_done 0
|
||||
#define sync_sleep(seconds) Sleep((DWORD)((seconds) * 1000))
|
||||
#define sync_lock() AcquireSRWLockExclusive(&g_sync_mutex)
|
||||
#define sync_unlock() ReleaseSRWLockExclusive(&g_sync_mutex)
|
||||
typedef HANDLE SyncThread;
|
||||
static SRWLOCK g_sync_mutex = SRWLOCK_INIT;
|
||||
static int
|
||||
sync_thread_start(SyncThread *thread, LPTHREAD_START_ROUTINE func, void *arg)
|
||||
{
|
||||
*thread = CreateThread(NULL, 0, func, arg, 0, NULL);
|
||||
return *thread != NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
sync_thread_detach(SyncThread thread)
|
||||
{
|
||||
CloseHandle(thread);
|
||||
}
|
||||
#else
|
||||
#define sync_thread_return void *
|
||||
#define sync_thread_done NULL
|
||||
#define sync_sleep(seconds) sleep(seconds)
|
||||
#define sync_lock() pthread_mutex_lock(&g_sync_mutex)
|
||||
#define sync_unlock() pthread_mutex_unlock(&g_sync_mutex)
|
||||
typedef pthread_t SyncThread;
|
||||
static pthread_mutex_t g_sync_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int
|
||||
sync_thread_start(SyncThread *thread, void *(*func)(void *), void *arg)
|
||||
{
|
||||
return pthread_create(thread, NULL, func, arg) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
sync_thread_detach(SyncThread thread)
|
||||
{
|
||||
pthread_detach(thread);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int g_sync_finished = 0;
|
||||
static int g_sync_finished_result = FLINT_LYRA_SYNC_OK;
|
||||
static int g_sync_finished_changed = 0;
|
||||
static int g_social_finished = 0;
|
||||
static int g_social_finished_result = FLINT_LYRA_SYNC_OK;
|
||||
static char g_social_friend_requests_json[8192];
|
||||
static char g_social_friends_json[8192];
|
||||
static char g_social_leaderboard_json[8192];
|
||||
static char g_social_leaderboard_key[96];
|
||||
static int g_sync_events_running = 0;
|
||||
static char g_sync_events_url[256];
|
||||
#else
|
||||
static char g_sync_events_url[256];
|
||||
static double g_sync_events_retry_at = 0.0;
|
||||
#endif
|
||||
|
||||
static int app_sync_url(char *url, size_t url_size);
|
||||
static int app_background_sync_safe(const InbeApp *app);
|
||||
static int app_input_active(void);
|
||||
static int app_sync_now(InbeApp *app);
|
||||
static const char *app_modal_type_name(UIModalType type);
|
||||
static const char *app_social_practice_id(int practice);
|
||||
static const char *app_social_metric_id(int practice, int metric);
|
||||
static void app_social_leaderboard_key(char *out, size_t out_size,
|
||||
int practice, int metric);
|
||||
|
||||
static void
|
||||
app_queue_social_refresh(void)
|
||||
{
|
||||
g_sync.social_refresh_pending = 1;
|
||||
}
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
static sync_thread_return
|
||||
app_sync_worker(void *userdata)
|
||||
{
|
||||
InbeSyncWorkerArgs *args = userdata;
|
||||
FlintLyraSyncResult result = FLINT_LYRA_SYNC_INVALID_URL;
|
||||
int changed = 0;
|
||||
|
||||
if(args != NULL) {
|
||||
result = sync_client_sync(args->url);
|
||||
changed = result == FLINT_LYRA_SYNC_OK && storage_last_sync_changed();
|
||||
free(args);
|
||||
}
|
||||
|
||||
sync_lock();
|
||||
g_sync_finished_result = result;
|
||||
g_sync_finished_changed = changed;
|
||||
g_sync_finished = 1;
|
||||
g_sync.sync_running = 0;
|
||||
sync_unlock();
|
||||
return sync_thread_done;
|
||||
}
|
||||
|
||||
static sync_thread_return
|
||||
app_social_worker(void *userdata)
|
||||
{
|
||||
InbeSocialWorkerArgs *args = userdata;
|
||||
FlintLyraSyncResult result = FLINT_LYRA_SYNC_INVALID_URL;
|
||||
FlintLyraSyncResult friends_result = FLINT_LYRA_SYNC_REQUEST_FAILED;
|
||||
FlintLyraSyncResult leaderboard_result = FLINT_LYRA_SYNC_REQUEST_FAILED;
|
||||
char requests_json[8192] = "{\"incoming\":[],\"outgoing\":[]}";
|
||||
char friends_json[8192] = "{\"friends\":[]}";
|
||||
char leaderboard_json[8192] = "{\"rows\":[]}";
|
||||
|
||||
if(args != NULL) {
|
||||
if(strcmp(args->action, "send") == 0) {
|
||||
result = sync_client_send_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
} else if(strcmp(args->action, "accept") == 0) {
|
||||
result = sync_client_accept_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
} else if(strcmp(args->action, "decline") == 0) {
|
||||
result = sync_client_decline_friend_request(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
} else if(strcmp(args->action, "remove") == 0) {
|
||||
result = sync_client_remove_friend(args->url, args->action_value);
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = sync_client_get_friend_requests(args->url, requests_json,
|
||||
sizeof(requests_json));
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
friends_result = sync_client_get_friends(args->url, friends_json,
|
||||
sizeof(friends_json));
|
||||
leaderboard_result =
|
||||
sync_client_get_friend_stats(args->url, "inbe", args->practice,
|
||||
args->metric, leaderboard_json,
|
||||
sizeof(leaderboard_json));
|
||||
if(friends_result != FLINT_LYRA_SYNC_OK)
|
||||
result = friends_result;
|
||||
else if(leaderboard_result != FLINT_LYRA_SYNC_OK)
|
||||
result = leaderboard_result;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
sync_lock();
|
||||
g_social_finished_result = result;
|
||||
snprintf(g_social_friend_requests_json, sizeof(g_social_friend_requests_json),
|
||||
"%s", requests_json);
|
||||
snprintf(g_social_friends_json, sizeof(g_social_friends_json), "%s",
|
||||
friends_json);
|
||||
snprintf(g_social_leaderboard_json, sizeof(g_social_leaderboard_json), "%s",
|
||||
leaderboard_json);
|
||||
snprintf(g_social_leaderboard_key, sizeof(g_social_leaderboard_key), "%s",
|
||||
args != NULL ? args->leaderboard_key : "");
|
||||
g_social_finished = 1;
|
||||
g_sync.social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
free(args);
|
||||
return sync_thread_done;
|
||||
}
|
||||
|
||||
static sync_thread_return
|
||||
app_sync_events_worker(void *userdata)
|
||||
{
|
||||
InbeSyncWorkerArgs *args = userdata;
|
||||
|
||||
if(args == NULL)
|
||||
return sync_thread_done;
|
||||
for(;;) {
|
||||
FlintLyraSyncResult result;
|
||||
|
||||
sync_lock();
|
||||
if(g_sync.sync_running) {
|
||||
sync_unlock();
|
||||
sync_sleep(1);
|
||||
continue;
|
||||
}
|
||||
sync_unlock();
|
||||
|
||||
result = sync_client_wait_for_remote_event(args->url);
|
||||
sync_lock();
|
||||
if(result == FLINT_LYRA_SYNC_OK)
|
||||
g_sync.remote_sync_due = 1;
|
||||
sync_unlock();
|
||||
if(result != FLINT_LYRA_SYNC_OK)
|
||||
sync_sleep(2);
|
||||
}
|
||||
return sync_thread_done;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
app_collect_finished_sync(void)
|
||||
{
|
||||
#if !defined(PLATFORM_WEB)
|
||||
int finished;
|
||||
int result;
|
||||
int changed;
|
||||
|
||||
sync_lock();
|
||||
finished = g_sync_finished;
|
||||
result = g_sync_finished_result;
|
||||
changed = g_sync_finished_changed;
|
||||
g_sync_finished = 0;
|
||||
sync_unlock();
|
||||
|
||||
if(!finished)
|
||||
return;
|
||||
#else
|
||||
FlintLyraSyncResult result;
|
||||
int changed = 0;
|
||||
|
||||
if(sync_client_web_poll_remote_event())
|
||||
g_sync.remote_sync_due = 1;
|
||||
if(!g_sync.sync_running)
|
||||
return;
|
||||
if(!sync_client_web_sync_poll(&result, &changed))
|
||||
return;
|
||||
g_sync.sync_running = 0;
|
||||
#endif
|
||||
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
TraceLog(LOG_INFO, "SYNC: background sync complete changed=%d", changed);
|
||||
app_queue_social_refresh();
|
||||
if(changed)
|
||||
g_sync.data_refresh_pending = 1;
|
||||
} else {
|
||||
TraceLog(LOG_WARNING, "SYNC: background sync failed result=%d name=%s",
|
||||
result, flint_lyra_sync_result_name(result));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
app_ensure_sync_events(const char *url)
|
||||
{
|
||||
#if !defined(PLATFORM_WEB)
|
||||
SyncThread thread;
|
||||
InbeSyncWorkerArgs *args;
|
||||
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return;
|
||||
sync_lock();
|
||||
if(g_sync_events_running && strcmp(g_sync_events_url, url) == 0) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
if(g_sync_events_running) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
g_sync_events_running = 1;
|
||||
g_sync.remote_sync_due = 1;
|
||||
snprintf(g_sync_events_url, sizeof(g_sync_events_url), "%s", url);
|
||||
sync_unlock();
|
||||
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_sync_events_running = 0;
|
||||
g_sync_events_url[0] = '\0';
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
if(!sync_thread_start(&thread, app_sync_events_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_sync_events_running = 0;
|
||||
g_sync_events_url[0] = '\0';
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start websocket event thread");
|
||||
return;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
TraceLog(LOG_INFO, "SYNC: websocket event listener started");
|
||||
#else
|
||||
double now;
|
||||
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return;
|
||||
if(strcmp(g_sync_events_url, url) == 0) {
|
||||
sync_client_web_start_remote_events(url);
|
||||
return;
|
||||
}
|
||||
now = GetTime();
|
||||
if(now < g_sync_events_retry_at)
|
||||
return;
|
||||
if(!sync_client_web_start_remote_events(url)) {
|
||||
g_sync_events_retry_at = now + 2.0;
|
||||
return;
|
||||
}
|
||||
g_sync.remote_sync_due = 1;
|
||||
snprintf(g_sync_events_url, sizeof(g_sync_events_url), "%s", url);
|
||||
TraceLog(LOG_INFO, "SYNC: websocket event listener started");
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
app_background_sync_safe(const InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(app->modal.active)
|
||||
return 0;
|
||||
if(app->habit_edit.active ||
|
||||
app->sync_server_url_focused ||
|
||||
app->sync_alias_focused ||
|
||||
app->profile_friend_input_focused)
|
||||
return 0;
|
||||
if(app->inbe.screen == InbeScreenPracticeSession ||
|
||||
app->inbe.screen == InbeScreenMeditation ||
|
||||
app->inbe.screen == InbeScreenSunSalutation)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_modal_type_name(UIModalType type)
|
||||
{
|
||||
switch(type) {
|
||||
case UIModalNone: return "none";
|
||||
case UIModalConfirmExitSession: return "confirm_exit_session";
|
||||
case UIModalMeditationSetup: return "meditation_setup";
|
||||
case UIModalConfirmDeleteData: return "confirm_delete_data";
|
||||
case UIModalConfirmDeleteHabit: return "confirm_delete_habit";
|
||||
case UIModalEditProgressiveStartSpeed: return "edit_progressive_start_speed";
|
||||
case UIModalMeditationNetworkError: return "meditation_network_error";
|
||||
case UIModalConfirmImportDataSettings: return "confirm_import_data_settings";
|
||||
case UIModalSyncAccountBackup: return "sync_account_backup";
|
||||
case UIModalConfirmDeleteSyncAccount: return "confirm_delete_sync_account";
|
||||
case UIModalHabitPracticeListInfo: return "habit_practice_list_info";
|
||||
case UIModalHabitCountingInfo: return "habit_counting_info";
|
||||
case UIModalPracticeManual: return "practice_manual";
|
||||
case UIModalPracticeConfig: return "practice_config";
|
||||
case UIModalThemePicker: return "theme_picker";
|
||||
case UIModalSyncReview: return "sync_review";
|
||||
case UIModalSyncAlias: return "sync_alias";
|
||||
case UIModalSyncPublicId: return "sync_public_id";
|
||||
case UIModalConfirmRemoveFriend: return "confirm_remove_friend";
|
||||
default: break;
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static int
|
||||
app_input_active(void)
|
||||
{
|
||||
return IsMouseButtonDown(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT) ||
|
||||
IsMouseButtonDown(MOUSE_BUTTON_RIGHT) ||
|
||||
IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ||
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_RIGHT);
|
||||
}
|
||||
|
||||
static void
|
||||
app_apply_pending_sync_refresh(InbeApp *app)
|
||||
{
|
||||
if(!g_sync.data_refresh_pending || !app_background_sync_safe(app))
|
||||
return;
|
||||
g_sync.data_refresh_pending = 0;
|
||||
TraceLog(LOG_INFO, "SYNC: applying remote refresh");
|
||||
app_reload_after_import(app, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
app_sync_url(char *url, size_t url_size)
|
||||
{
|
||||
const char *saved_url;
|
||||
InbeSyncAccount account;
|
||||
|
||||
if(url == NULL || url_size == 0)
|
||||
return 0;
|
||||
url[0] = '\0';
|
||||
if(!sync_account_load(&account))
|
||||
return 0;
|
||||
saved_url = storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
if(!sync_client_normalize_url(saved_url != NULL && saved_url[0] != '\0'
|
||||
? saved_url
|
||||
: INBE_SYNC_SERVER_URL_DEFAULT,
|
||||
url, url_size))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_social_practice_id(int practice)
|
||||
{
|
||||
switch(practice) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return "meditation";
|
||||
case EXERCISE_SUN_SALUTATION:
|
||||
return "sun_salutation";
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return "whm";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
app_social_metric_id(int practice, int metric)
|
||||
{
|
||||
if(metric != 1)
|
||||
return "streak";
|
||||
return practice == EXERCISE_MEDITATION ? "avg_time" : "avg_hold";
|
||||
}
|
||||
|
||||
static void
|
||||
app_social_leaderboard_key(char *out, size_t out_size, int practice, int metric)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
snprintf(out, out_size, "leaderboard.inbe.%s.%s",
|
||||
app_social_practice_id(practice),
|
||||
app_social_metric_id(practice, metric));
|
||||
}
|
||||
|
||||
static void
|
||||
app_apply_pending_social_refresh(InbeApp *app)
|
||||
{
|
||||
char url[256];
|
||||
char action[16] = "";
|
||||
char action_value[96] = "";
|
||||
|
||||
if(!g_sync.social_refresh_pending || !app_background_sync_safe(app))
|
||||
return;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
{
|
||||
SyncThread thread;
|
||||
InbeSocialWorkerArgs *args;
|
||||
|
||||
sync_lock();
|
||||
if(g_sync.sync_running || g_sync.social_refresh_running) {
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(action, sizeof(action), "%s", g_sync.social_action);
|
||||
snprintf(action_value, sizeof(action_value), "%s", g_sync.social_action_value);
|
||||
g_sync.social_action[0] = '\0';
|
||||
g_sync.social_action_value[0] = '\0';
|
||||
g_sync.social_refresh_running = 1;
|
||||
sync_unlock();
|
||||
|
||||
if(!app_sync_url(url, sizeof(url))) {
|
||||
sync_lock();
|
||||
g_sync.social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
g_sync.social_refresh_pending = 0;
|
||||
return;
|
||||
}
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_sync.social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
return;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
snprintf(args->practice, sizeof(args->practice), "%s",
|
||||
app_social_practice_id(app->profile_leaderboard_practice));
|
||||
snprintf(args->metric, sizeof(args->metric), "%s",
|
||||
app_social_metric_id(app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric));
|
||||
app_social_leaderboard_key(args->leaderboard_key,
|
||||
sizeof(args->leaderboard_key),
|
||||
app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric);
|
||||
snprintf(args->action, sizeof(args->action), "%s", action);
|
||||
snprintf(args->action_value, sizeof(args->action_value), "%s", action_value);
|
||||
TraceLog(LOG_INFO, "SYNC: starting background social refresh");
|
||||
if(!sync_thread_start(&thread, app_social_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_sync.social_refresh_running = 0;
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start social refresh thread");
|
||||
return;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
}
|
||||
#else
|
||||
TraceLog(LOG_INFO, "SYNC: refreshing social cache");
|
||||
profile_social_refresh_cache(app);
|
||||
#endif
|
||||
g_sync.social_refresh_pending = 0;
|
||||
}
|
||||
|
||||
#if !defined(PLATFORM_WEB)
|
||||
static void
|
||||
app_collect_finished_social_refresh(InbeApp *app)
|
||||
{
|
||||
int finished;
|
||||
int result;
|
||||
char requests_json[8192];
|
||||
char friends_json[8192];
|
||||
char leaderboard_json[8192];
|
||||
char leaderboard_key[96];
|
||||
|
||||
sync_lock();
|
||||
finished = g_social_finished;
|
||||
result = g_social_finished_result;
|
||||
if(finished) {
|
||||
snprintf(requests_json, sizeof(requests_json), "%s",
|
||||
g_social_friend_requests_json);
|
||||
snprintf(friends_json, sizeof(friends_json), "%s", g_social_friends_json);
|
||||
snprintf(leaderboard_json, sizeof(leaderboard_json), "%s",
|
||||
g_social_leaderboard_json);
|
||||
snprintf(leaderboard_key, sizeof(leaderboard_key), "%s",
|
||||
g_social_leaderboard_key);
|
||||
g_social_finished = 0;
|
||||
}
|
||||
sync_unlock();
|
||||
|
||||
if(!finished)
|
||||
return;
|
||||
if(result != FLINT_LYRA_SYNC_OK) {
|
||||
TraceLog(LOG_WARNING, "SYNC: social refresh failed result=%d name=%s",
|
||||
result, flint_lyra_sync_result_name(result));
|
||||
return;
|
||||
}
|
||||
storage_set_social_cache_json("friends.requests", requests_json);
|
||||
storage_set_social_cache_json("friends.list", friends_json);
|
||||
if(leaderboard_key[0] != '\0')
|
||||
storage_set_social_cache_json(leaderboard_key, leaderboard_json);
|
||||
if(app != NULL) {
|
||||
snprintf(app->profile_friend_requests_json,
|
||||
sizeof(app->profile_friend_requests_json), "%s", requests_json);
|
||||
snprintf(app->profile_friends_json, sizeof(app->profile_friends_json),
|
||||
"%s", friends_json);
|
||||
if(leaderboard_key[0] != '\0') {
|
||||
char current_key[96];
|
||||
app_social_leaderboard_key(current_key, sizeof(current_key),
|
||||
app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric);
|
||||
if(strcmp(current_key, leaderboard_key) == 0)
|
||||
snprintf(app->profile_leaderboard_json,
|
||||
sizeof(app->profile_leaderboard_json), "%s",
|
||||
leaderboard_json);
|
||||
}
|
||||
app->profile_friends_loaded = 1;
|
||||
app->profile_leaderboard_loaded = 1;
|
||||
}
|
||||
TraceLog(LOG_INFO, "SYNC: social cache refreshed");
|
||||
}
|
||||
#else
|
||||
static void
|
||||
app_collect_finished_social_refresh(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
app_request_social_refresh(InbeApp *app)
|
||||
{
|
||||
(void)app;
|
||||
app_queue_social_refresh();
|
||||
}
|
||||
|
||||
static void
|
||||
app_request_social_action(const char *action, const char *value)
|
||||
{
|
||||
if(action == NULL || action[0] == '\0' || value == NULL || value[0] == '\0')
|
||||
return;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_lock();
|
||||
snprintf(g_sync.social_action, sizeof(g_sync.social_action), "%s", action);
|
||||
snprintf(g_sync.social_action_value, sizeof(g_sync.social_action_value), "%s", value);
|
||||
g_sync.social_refresh_pending = 1;
|
||||
sync_unlock();
|
||||
#else
|
||||
g_sync.social_refresh_pending = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_send(InbeApp *app, const char *target)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("send", target);
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_accept(InbeApp *app, const char *request_id)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("accept", request_id);
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_decline(InbeApp *app, const char *request_id)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("decline", request_id);
|
||||
}
|
||||
|
||||
void
|
||||
app_request_friend_remove(InbeApp *app, const char *friend_user_id)
|
||||
{
|
||||
(void)app;
|
||||
app_request_social_action("remove", friend_user_id);
|
||||
}
|
||||
|
||||
static int
|
||||
app_sync_now(InbeApp *app)
|
||||
{
|
||||
char url[256];
|
||||
|
||||
if(app == NULL || !app_sync_url(url, sizeof(url)))
|
||||
return 0;
|
||||
#if !defined(PLATFORM_WEB)
|
||||
{
|
||||
SyncThread thread;
|
||||
InbeSyncWorkerArgs *args;
|
||||
|
||||
sync_lock();
|
||||
if(g_sync.sync_running) {
|
||||
sync_unlock();
|
||||
return 0;
|
||||
}
|
||||
g_sync.sync_running = 1;
|
||||
sync_unlock();
|
||||
|
||||
args = malloc(sizeof(*args));
|
||||
if(args == NULL) {
|
||||
sync_lock();
|
||||
g_sync.sync_running = 0;
|
||||
sync_unlock();
|
||||
return 0;
|
||||
}
|
||||
snprintf(args->url, sizeof(args->url), "%s", url);
|
||||
TraceLog(LOG_INFO, "SYNC: starting background sync");
|
||||
if(!sync_thread_start(&thread, app_sync_worker, args)) {
|
||||
free(args);
|
||||
sync_lock();
|
||||
g_sync.sync_running = 0;
|
||||
sync_unlock();
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start background sync thread");
|
||||
return 0;
|
||||
}
|
||||
sync_thread_detach(thread);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if(g_sync.sync_running)
|
||||
return 0;
|
||||
g_sync.sync_running = 1;
|
||||
TraceLog(LOG_INFO, "SYNC: starting background sync");
|
||||
if(!sync_client_web_sync_start(url)) {
|
||||
g_sync.sync_running = 0;
|
||||
TraceLog(LOG_WARNING, "SYNC: failed to start background sync");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
app_auto_sync(InbeApp *app)
|
||||
{
|
||||
double due;
|
||||
double now;
|
||||
char url[256];
|
||||
|
||||
if(app == NULL || !app_sync_url(url, sizeof(url)))
|
||||
return 0;
|
||||
now = GetTime();
|
||||
g_sync.last_input_at = now;
|
||||
due = now + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
if(g_sync.dirty_sync_at <= 0.0 || due < g_sync.dirty_sync_at)
|
||||
g_sync.dirty_sync_at = due;
|
||||
TraceLog(LOG_INFO, "SYNC: queued local changes");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
app_sync_pump(InbeApp *app)
|
||||
{
|
||||
double now;
|
||||
int should_sync = 0;
|
||||
int dirty_due = 0;
|
||||
int repair_due = 0;
|
||||
char url[256];
|
||||
InbeStorageSyncStatus sync_status;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
app_collect_finished_sync();
|
||||
app_collect_finished_social_refresh(app);
|
||||
if(storage_sync_review_pending() && app_background_sync_safe(app)) {
|
||||
if(storage_sync_review_clear_if_no_visible_diff()) {
|
||||
app_reload_after_import(app, 0);
|
||||
} else {
|
||||
app_open_modal(app, UIModalSyncReview);
|
||||
}
|
||||
}
|
||||
app_apply_pending_sync_refresh(app);
|
||||
app_apply_pending_social_refresh(app);
|
||||
if(!app_sync_url(url, sizeof(url)))
|
||||
return;
|
||||
app_ensure_sync_events(url);
|
||||
now = GetTime();
|
||||
if(app_input_active())
|
||||
g_sync.last_input_at = now;
|
||||
if(g_sync.dirty_sync_at > 0.0 && now >= g_sync.dirty_sync_at) {
|
||||
should_sync = 1;
|
||||
dirty_due = 1;
|
||||
}
|
||||
if(storage_sync_status(&sync_status) && sync_status.has_account && sync_status.repair_pending &&
|
||||
(g_sync.dirty_sync_at <= 0.0 || now >= g_sync.dirty_sync_at)) {
|
||||
should_sync = 1;
|
||||
repair_due = 1;
|
||||
}
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_lock();
|
||||
#endif
|
||||
if(g_sync.remote_sync_due) {
|
||||
should_sync = 1;
|
||||
g_sync.remote_sync_due = 0;
|
||||
}
|
||||
#if !defined(PLATFORM_WEB)
|
||||
sync_unlock();
|
||||
#endif
|
||||
if(!should_sync)
|
||||
return;
|
||||
if(now < g_sync.last_input_at + INBE_SYNC_INPUT_QUIET_SECONDS) {
|
||||
if(g_sync.dirty_sync_at <= 0.0)
|
||||
g_sync.dirty_sync_at = g_sync.last_input_at + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
return;
|
||||
}
|
||||
if(!app_background_sync_safe(app)) {
|
||||
TraceLog(LOG_INFO,
|
||||
"SYNC: delayed; modal=%d type=%s screen=%d pending_review=%d tutorial_seen=%d habits_guide_seen=%d",
|
||||
app->modal.active,
|
||||
app_modal_type_name(app->modal.type),
|
||||
app->inbe.screen,
|
||||
storage_sync_review_pending(),
|
||||
app->tutorial_seen,
|
||||
app->habits_guide_seen);
|
||||
if(g_sync.dirty_sync_at <= 0.0 || repair_due)
|
||||
g_sync.dirty_sync_at = now + 1.0;
|
||||
return;
|
||||
}
|
||||
if(app_sync_now(app)) {
|
||||
if(dirty_due || repair_due)
|
||||
g_sync.dirty_sync_at = 0.0;
|
||||
TraceLog(LOG_INFO, "SYNC: dispatched");
|
||||
} else if(dirty_due || repair_due) {
|
||||
g_sync.dirty_sync_at = now + INBE_SYNC_INPUT_QUIET_SECONDS;
|
||||
}
|
||||
app_apply_pending_sync_refresh(app);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef INBE_APP_SYNC_H
|
||||
#define INBE_APP_SYNC_H
|
||||
|
||||
#include "app.h"
|
||||
|
||||
void app_sync_pump(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
#ifndef INBE_TEXT_UTILS_H
|
||||
#define INBE_TEXT_UTILS_H
|
||||
|
||||
#include "flint_text.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline void
|
||||
inbe_text_fit_ellipsis(const char *text, char *out, size_t out_size, int max_w,
|
||||
int font)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
if(text == NULL)
|
||||
text = "";
|
||||
snprintf(out, out_size, "%s", text);
|
||||
if(max_w <= 0)
|
||||
return;
|
||||
while(out[0] != '\0' && flint_text_measure(out, font) > max_w) {
|
||||
size_t len = strlen(out);
|
||||
size_t cut = len;
|
||||
|
||||
if(len <= 3)
|
||||
break;
|
||||
if(len > 3 && strcmp(out + len - 3, "...") == 0)
|
||||
len -= 3;
|
||||
cut = len;
|
||||
do {
|
||||
cut--;
|
||||
} while(cut > 0 && (((unsigned char)out[cut] & 0xC0) == 0x80));
|
||||
out[cut] = '\0';
|
||||
if(cut + 3 < out_size)
|
||||
strncat(out, "...", out_size - strlen(out) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char *
|
||||
inbe_text_fit_ellipsis_into(const char *text, char *out, size_t out_size, int max_w,
|
||||
int font)
|
||||
{
|
||||
if(text == NULL)
|
||||
text = "";
|
||||
if(max_w > 0 && flint_text_measure(text, font) <= max_w)
|
||||
return text;
|
||||
inbe_text_fit_ellipsis(text, out, out_size, max_w, font);
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline void
|
||||
inbe_text_short_label(const char *text, int max_codepoints, int append_ellipsis,
|
||||
char *out, size_t out_size)
|
||||
{
|
||||
size_t len;
|
||||
size_t cut = 0;
|
||||
int chars = 0;
|
||||
int truncated = 0;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
if(text == NULL)
|
||||
text = "";
|
||||
if(max_codepoints < 0)
|
||||
max_codepoints = 0;
|
||||
len = strlen(text);
|
||||
while(cut < len && chars < max_codepoints) {
|
||||
cut++;
|
||||
while(cut < len && (((unsigned char)text[cut] & 0xC0) == 0x80))
|
||||
cut++;
|
||||
chars++;
|
||||
}
|
||||
truncated = cut < len;
|
||||
if(cut >= out_size) {
|
||||
cut = out_size - 1;
|
||||
while(cut > 0 && (((unsigned char)text[cut] & 0xC0) == 0x80))
|
||||
cut--;
|
||||
}
|
||||
memcpy(out, text, cut);
|
||||
out[cut] = '\0';
|
||||
if(append_ellipsis && truncated && strlen(out) + 3 < out_size)
|
||||
strncat(out, "...", out_size - strlen(out) - 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
#define INBE_VERSION_MAJOR 1
|
||||
#define INBE_VERSION_MINOR 7
|
||||
#define INBE_VERSION_PATCH 3
|
||||
#define INBE_VERSION_STRING "1.7.3"
|
||||
#define INBE_VERSION_PATCH 6
|
||||
#define INBE_VERSION_STRING "1.7.6"
|
||||
|
||||
#endif
|
||||
+1
-7
@@ -173,9 +173,6 @@ windows_close_logger(void)
|
||||
#endif
|
||||
|
||||
InbeApp* get_global_inbe_app(void) {
|
||||
if (g_inbe_app_ptr == NULL) {
|
||||
TraceLog(LOG_WARNING, "WARNING: get_global_inbe_app called with NULL pointer");
|
||||
}
|
||||
return g_inbe_app_ptr;
|
||||
}
|
||||
|
||||
@@ -305,10 +302,8 @@ frame(void)
|
||||
static AndroidViewport previous_viewport = {-1, -1, -1, -1, -1, -1, -1, -1};
|
||||
|
||||
android_insets_get(&insets);
|
||||
// Safety check: Don't render if insets haven't been initialized yet
|
||||
// This prevents rendering with incorrect positioning on app start/restart
|
||||
if (!android_insets_is_initialized()) {
|
||||
return; // Skip this frame, BeginDrawing() hasn't been called yet
|
||||
return;
|
||||
}
|
||||
app_set_android_bottom_nav_height(android_nonnegative(insets.nav_bar));
|
||||
|
||||
@@ -595,7 +590,6 @@ int main(int argc, char **argv) {
|
||||
android_insets_init();
|
||||
android_device_init();
|
||||
android_wakelock_init();
|
||||
android_timer_init();
|
||||
android_runtime_assets_init();
|
||||
if(!ChangeDirectory("/data/user/0/xyz.waozi.inbe/files"))
|
||||
TraceLog(LOG_WARNING, "INBE: failed to switch to Android files directory");
|
||||
|
||||
@@ -11,13 +11,10 @@
|
||||
|
||||
#include <raylib.h>
|
||||
#include <pthread.h>
|
||||
#include <android_native_app_glue.h>
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
// External functions from main.c
|
||||
extern InbeApp* get_global_inbe_app(void);
|
||||
extern void set_global_inbe_app(InbeApp *app);
|
||||
extern void app_request_graphics_reload(InbeApp *app);
|
||||
|
||||
#define LOG_TAG "INBE_INSETS"
|
||||
@@ -26,21 +23,15 @@ extern void app_request_graphics_reload(InbeApp *app);
|
||||
#define JNI_VERSION_1_6 0x10060000
|
||||
#endif
|
||||
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
extern void android_wakelock_set_activity(JNIEnv *env, jobject activity);
|
||||
extern void android_wakelock_set_jvm(JavaVM *vm);
|
||||
extern void android_timer_activate(void);
|
||||
extern void android_timer_deactivate(void);
|
||||
|
||||
// Called from Java when activity is ready for wake lock
|
||||
static void android_wakelock_set_activity_impl(JNIEnv *env, jobject thiz) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Wake lock ready callback from Java");
|
||||
android_wakelock_set_activity(env, thiz);
|
||||
}
|
||||
|
||||
static JavaVM *g_jvm = NULL;
|
||||
static jobject g_activity = NULL;
|
||||
|
||||
static volatile struct {
|
||||
int status_bar;
|
||||
int nav_bar;
|
||||
@@ -52,7 +43,6 @@ static volatile struct {
|
||||
static pthread_mutex_t insets_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static volatile int insets_initialized = 0;
|
||||
|
||||
// JNI function - Java calls this to push inset values
|
||||
static void nativeSetInsets(JNIEnv *env, jobject thiz,
|
||||
jint status_bar, jint nav_bar,
|
||||
jint cutout_left, jint cutout_top, jint cutout_right, jint cutout_bottom)
|
||||
@@ -70,29 +60,14 @@ static void nativeSetInsets(JNIEnv *env, jobject thiz,
|
||||
current_insets.cutout_bottom = cutout_bottom;
|
||||
insets_initialized = 1;
|
||||
pthread_mutex_unlock(&insets_mutex);
|
||||
|
||||
// Memory barrier to ensure all threads see the updated values
|
||||
__sync_synchronize();
|
||||
}
|
||||
|
||||
// JNI function - Java calls this to check if play_in_background is enabled
|
||||
static jint nativeGetPlayInBackground(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeGetPlayInBackground: called");
|
||||
void *app = get_global_inbe_app();
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativeGetPlayInBackground: got app pointer %p", app);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
if (app != NULL) {
|
||||
InbeApp *inbe_app = (InbeApp*)app;
|
||||
jint result = get_play_in_background(&inbe_app->inbe);
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativeGetPlayInBackground: returning %d", result);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
return result;
|
||||
}
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeGetPlayInBackground: app is NULL, returning 0");
|
||||
return 0; // Default to disabled
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
return get_play_in_background(&((InbeApp*)app)->inbe);
|
||||
}
|
||||
|
||||
static void nativeSetBackgroundActive(JNIEnv *env, jobject thiz, jboolean active)
|
||||
@@ -107,71 +82,45 @@ static void nativeSetBackgroundActive(JNIEnv *env, jobject thiz, jboolean active
|
||||
}
|
||||
|
||||
if (active) {
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeSetBackgroundActive: activating background timer");
|
||||
android_timer_activate();
|
||||
} else {
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeSetBackgroundActive: deactivating background timer");
|
||||
android_timer_deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
// JNI function - Auto-pause session when app goes to background
|
||||
static jint nativePauseSession(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativePauseSession: called");
|
||||
void *app = get_global_inbe_app();
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativePauseSession: got app pointer %p", app);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
if (app != NULL) {
|
||||
InbeApp *inbe_app = (InbeApp*)app;
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativePauseSession: session_paused before = %d", inbe_app->session_paused);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
if (!inbe_app->session_paused) {
|
||||
inbe_app->session_paused = 1;
|
||||
inbe_app->backgrounded = 1;
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativePauseSession: set session_paused = 1");
|
||||
return 1;
|
||||
} else {
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativePauseSession: Session already paused, skipping");
|
||||
}
|
||||
} else {
|
||||
InbeApp *inbe_app = get_global_inbe_app();
|
||||
if (inbe_app == NULL) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, "INBE_JNI", "nativePauseSession: app is NULL!");
|
||||
return 0;
|
||||
}
|
||||
if (inbe_app->session_paused)
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
inbe_app->session_paused = 1;
|
||||
inbe_app->backgrounded = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// JNI function - Auto-resume session when app returns to foreground
|
||||
static void nativeResumeSession(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
(void)env;
|
||||
(void)thiz;
|
||||
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeResumeSession: called");
|
||||
void *app = get_global_inbe_app();
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativeResumeSession: got app pointer %p", app);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
if (app != NULL) {
|
||||
InbeApp *inbe_app = (InbeApp*)app;
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "nativeResumeSession: session_paused before = %d", inbe_app->session_paused);
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", msg);
|
||||
if (inbe_app->session_paused) {
|
||||
inbe_app->session_paused = 0;
|
||||
inbe_app->backgrounded = 0;
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeResumeSession: set session_paused = 0");
|
||||
} else {
|
||||
__android_log_write(ANDROID_LOG_INFO, "INBE_JNI", "nativeResumeSession: Session not paused, skipping");
|
||||
}
|
||||
} else {
|
||||
InbeApp *inbe_app = get_global_inbe_app();
|
||||
if (inbe_app == NULL) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, "INBE_JNI", "nativeResumeSession: app is NULL!");
|
||||
return;
|
||||
}
|
||||
if (!inbe_app->session_paused)
|
||||
return;
|
||||
|
||||
inbe_app->session_paused = 0;
|
||||
inbe_app->backgrounded = 0;
|
||||
}
|
||||
|
||||
static void nativeInvalidateGraphicsResources(JNIEnv *env, jobject thiz)
|
||||
@@ -184,7 +133,6 @@ static void nativeInvalidateGraphicsResources(JNIEnv *env, jobject thiz)
|
||||
app_request_graphics_reload(inbe_app);
|
||||
}
|
||||
|
||||
// JNI method table
|
||||
static const JNINativeMethod g_methods[] = {
|
||||
{"nativeSetInsets", "(IIIIII)V", (void*)nativeSetInsets},
|
||||
{"nativeWakeLockReady", "()V", (void*)android_wakelock_set_activity_impl},
|
||||
@@ -205,15 +153,11 @@ static const JNINativeMethod g_methods[] = {
|
||||
{"nativeInvalidateGraphicsResources", "()V", (void*)nativeInvalidateGraphicsResources},
|
||||
};
|
||||
|
||||
// JNI_OnLoad - Register native methods
|
||||
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
{
|
||||
JNIEnv *env = NULL;
|
||||
jint result;
|
||||
|
||||
g_jvm = vm;
|
||||
|
||||
// Also set JVM for wake lock module
|
||||
android_wakelock_set_jvm(vm);
|
||||
|
||||
result = (*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6);
|
||||
@@ -222,14 +166,12 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
return result;
|
||||
}
|
||||
|
||||
// Find the MainActivity class
|
||||
jclass clazz = (*env)->FindClass(env, "xyz/waozi/inbe/MainActivity");
|
||||
if (clazz == NULL) {
|
||||
TraceLog(LOG_ERROR, "INBE: Failed to find MainActivity class");
|
||||
return JNI_ERR;
|
||||
}
|
||||
|
||||
// Register native methods
|
||||
result = (*env)->RegisterNatives(env, clazz, g_methods, sizeof(g_methods) / sizeof(g_methods[0]));
|
||||
if (result != JNI_OK) {
|
||||
TraceLog(LOG_ERROR, "INBE: Failed to register native methods");
|
||||
@@ -240,18 +182,15 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
||||
}
|
||||
|
||||
void android_insets_init(void) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== android_insets_init ===");
|
||||
pthread_mutex_lock(&insets_mutex);
|
||||
memset((void *)¤t_insets, 0, sizeof(current_insets));
|
||||
insets_initialized = 0;
|
||||
pthread_mutex_unlock(&insets_mutex);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== android_insets_init DONE ===");
|
||||
}
|
||||
|
||||
void android_insets_get(AndroidInsets *out) {
|
||||
pthread_mutex_lock(&insets_mutex);
|
||||
|
||||
// Simply return the current values
|
||||
if (out) {
|
||||
out->status_bar = current_insets.status_bar;
|
||||
out->nav_bar = current_insets.nav_bar;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#define LOG_TAG "INBE_TIMER"
|
||||
#define TARGET_FPS 60
|
||||
#define FRAME_TIME_US (1000000 / TARGET_FPS) // ~16666 microseconds for 60fps
|
||||
#define FRAME_TIME_US (1000000 / TARGET_FPS)
|
||||
|
||||
static pthread_t timer_thread;
|
||||
static pthread_mutex_t timer_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
@@ -44,47 +44,37 @@ monotonic_elapsed_ms(struct timespec *last_tick)
|
||||
static void*
|
||||
timer_thread_func(void *arg) {
|
||||
(void)arg;
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer thread started");
|
||||
int frame_count = 0;
|
||||
struct timespec last_tick = {0};
|
||||
|
||||
while (1) {
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
|
||||
// Check if we should stop
|
||||
if (!timer_running) {
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer thread: stopping");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if we should run (active and have app pointer)
|
||||
int should_run = timer_active && g_app != NULL;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
|
||||
if (should_run) {
|
||||
// Log every 60 frames (1 second)
|
||||
if (frame_count % 60 == 0) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Running background practice step + sounds");
|
||||
}
|
||||
frame_count++;
|
||||
|
||||
// Update practice state and sounds with mutex protection
|
||||
pthread_mutex_lock(&inbe_state_mutex);
|
||||
InbeApp *app = (InbeApp*)g_app;
|
||||
practice_active_advance_elapsed(app, monotonic_elapsed_ms(&last_tick));
|
||||
pthread_mutex_unlock(&inbe_state_mutex);
|
||||
|
||||
// Sleep for exact frame time (60fps = ~16.666ms)
|
||||
usleep(FRAME_TIME_US);
|
||||
} else {
|
||||
// Not active, sleep a bit before checking again
|
||||
if (frame_count > 0) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer: Paused (inactive)");
|
||||
frame_count = 0;
|
||||
}
|
||||
last_tick = (struct timespec){0};
|
||||
usleep(50000); // 50ms
|
||||
usleep(50000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,17 +82,11 @@ timer_thread_func(void *arg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
android_timer_init(void) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== android_timer_init ===");
|
||||
}
|
||||
|
||||
void
|
||||
android_timer_set_app(void *app_ptr) {
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
g_app = app_ptr;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
TraceLog(LOG_INFO, "INBE: Timer app pointer set");
|
||||
}
|
||||
|
||||
pthread_mutex_t*
|
||||
@@ -115,24 +99,19 @@ android_timer_start(void) {
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
|
||||
if (timer_running) {
|
||||
timer_active = 1; // Activate timer (activity paused)
|
||||
timer_active = 1;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer activated (activity paused)");
|
||||
return;
|
||||
}
|
||||
|
||||
timer_running = 1;
|
||||
timer_active = 0; // Start inactive (activity active)
|
||||
timer_active = 0;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
|
||||
int result = pthread_create(&timer_thread, NULL, timer_thread_func, NULL);
|
||||
if (result != 0) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "Failed to create timer thread");
|
||||
} else {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Timer thread created");
|
||||
}
|
||||
|
||||
TraceLog(LOG_INFO, "INBE: Background timer started");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -152,7 +131,6 @@ android_timer_stop(void) {
|
||||
pthread_detach(timer_thread);
|
||||
else
|
||||
pthread_join(timer_thread, NULL);
|
||||
TraceLog(LOG_INFO, "INBE: Background timer stopped");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -160,8 +138,6 @@ android_timer_activate(void) {
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
timer_active = 1;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "ACTIVATE: Timer active");
|
||||
TraceLog(LOG_INFO, "INBE: Background timer ACTIVATED - screen off");
|
||||
}
|
||||
|
||||
void
|
||||
@@ -169,16 +145,4 @@ android_timer_deactivate(void) {
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
timer_active = 0;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "DEACTIVATE: Timer inactive");
|
||||
TraceLog(LOG_INFO, "INBE: Background timer DEACTIVATED - screen on");
|
||||
}
|
||||
|
||||
void*
|
||||
android_timer_get_app(void)
|
||||
{
|
||||
void *app;
|
||||
pthread_mutex_lock(&timer_mutex);
|
||||
app = g_app;
|
||||
pthread_mutex_unlock(&timer_mutex);
|
||||
return app;
|
||||
}
|
||||
@@ -4,25 +4,19 @@
|
||||
#include "platform.h"
|
||||
|
||||
#if ANDROID_BUILD
|
||||
#include <jni.h>
|
||||
#include <pthread.h>
|
||||
void android_timer_init(void);
|
||||
void android_timer_start(void);
|
||||
void android_timer_stop(void);
|
||||
void android_timer_set_app(void *app_ptr);
|
||||
void android_timer_activate(void);
|
||||
void android_timer_deactivate(void);
|
||||
void* android_timer_get_app(void);
|
||||
pthread_mutex_t* android_timer_get_mutex(void);
|
||||
#else
|
||||
// Stub functions for non-Android platforms
|
||||
static inline void android_timer_init(void) {}
|
||||
static inline void android_timer_start(void) {}
|
||||
static inline void android_timer_stop(void) {}
|
||||
static inline void android_timer_set_app(void *app_ptr) {(void)app_ptr;}
|
||||
static inline void android_timer_activate(void) {}
|
||||
static inline void android_timer_deactivate(void) {}
|
||||
static inline void* android_timer_get_app(void) { return NULL; }
|
||||
static inline void* android_timer_get_mutex(void) { return NULL; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
#include "android_wakelock.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <raylib.h>
|
||||
#include <pthread.h>
|
||||
#include <android/log.h>
|
||||
#include <android_native_app_glue.h>
|
||||
#include <jni.h>
|
||||
|
||||
#define LOG_TAG "INBE_WAKE"
|
||||
@@ -20,7 +17,6 @@ static jmethodID g_allow_screen_off_method = NULL;
|
||||
static pthread_mutex_t wakelock_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void android_wakelock_init(void) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== android_wakelock_init ===");
|
||||
}
|
||||
|
||||
void android_wakelock_set_activity(JNIEnv *env, jobject activity) {
|
||||
@@ -42,7 +38,6 @@ void android_wakelock_set_activity(JNIEnv *env, jobject activity) {
|
||||
g_keep_screen_on_method = (*env)->GetMethodID(env, clazz, "keepScreenOn", "()V");
|
||||
g_allow_screen_off_method = (*env)->GetMethodID(env, clazz, "allowScreenOff", "()V");
|
||||
(*env)->DeleteLocalRef(env, clazz);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "Wake lock activity set successfully");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,15 +45,8 @@ void android_wakelock_set_activity(JNIEnv *env, jobject activity) {
|
||||
}
|
||||
|
||||
void android_wakelock_acquire(void) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== ACQUIRE START ===");
|
||||
|
||||
pthread_mutex_lock(&wakelock_mutex);
|
||||
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "ACQUIRE: Checking if g_jvm and g_activity are set");
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "ACQUIRE: g_jvm=%p, g_activity=%p", g_jvm, g_activity);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, msg);
|
||||
|
||||
if (!g_jvm || !g_activity) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "ACQUIRE: JNI not initialized - skipping wake lock");
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
@@ -73,11 +61,9 @@ void android_wakelock_acquire(void) {
|
||||
|
||||
if (env && g_acquire_method) {
|
||||
(*env)->CallVoidMethod(env, g_activity, g_acquire_method);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "ACQUIRE: SUCCESS");
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
TraceLog(LOG_INFO, "INBE: Wake lock acquired");
|
||||
}
|
||||
|
||||
void android_wakelock_update_session_notification(const char *status_text) {
|
||||
@@ -109,15 +95,8 @@ void android_wakelock_update_session_notification(const char *status_text) {
|
||||
}
|
||||
|
||||
void android_wakelock_release(void) {
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "=== RELEASE START ===");
|
||||
|
||||
pthread_mutex_lock(&wakelock_mutex);
|
||||
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "RELEASE: Checking if g_jvm and g_activity are set");
|
||||
char msg[128];
|
||||
snprintf(msg, sizeof(msg), "RELEASE: g_jvm=%p, g_activity=%p", g_jvm, g_activity);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, msg);
|
||||
|
||||
if (!g_jvm || !g_activity) {
|
||||
__android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "RELEASE: JNI not initialized - skipping wake lock");
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
@@ -132,11 +111,9 @@ void android_wakelock_release(void) {
|
||||
|
||||
if (env && g_release_method) {
|
||||
(*env)->CallVoidMethod(env, g_activity, g_release_method);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "RELEASE: SUCCESS");
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
TraceLog(LOG_INFO, "INBE: Wake lock released");
|
||||
}
|
||||
|
||||
void android_keep_screen_on(void) {
|
||||
@@ -156,7 +133,6 @@ void android_keep_screen_on(void) {
|
||||
|
||||
if (env && g_keep_screen_on_method) {
|
||||
(*env)->CallVoidMethod(env, g_activity, g_keep_screen_on_method);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "KEEP_SCREEN_ON: SUCCESS");
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
@@ -179,13 +155,11 @@ void android_allow_screen_off(void) {
|
||||
|
||||
if (env && g_allow_screen_off_method) {
|
||||
(*env)->CallVoidMethod(env, g_activity, g_allow_screen_off_method);
|
||||
__android_log_write(ANDROID_LOG_INFO, LOG_TAG, "ALLOW_SCREEN_OFF: SUCCESS");
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&wakelock_mutex);
|
||||
}
|
||||
|
||||
// Called from JNI to set the JVM reference
|
||||
void android_wakelock_set_jvm(JavaVM *vm) {
|
||||
g_jvm = vm;
|
||||
}
|
||||
@@ -175,7 +175,8 @@ meditation_config_screen_draw(InbeApp *app)
|
||||
}
|
||||
|
||||
scroll_y = title_h + flint_px(16);
|
||||
scroll_h = view_height - scroll_y - bottom_reserved - flint_px(8);
|
||||
scroll_h = view_height - scroll_y - bottom_reserved -
|
||||
(integrated ? flint_px(8) : 0);
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
|
||||
@@ -383,7 +383,8 @@ whm_config_screen_draw(InbeApp *app)
|
||||
app->settings_scroll = 0;
|
||||
}
|
||||
scroll_y = title_h + config_tab_h + config_tab_gap;
|
||||
scroll_h = view_height - scroll_y - bottom_reserved - flint_px(8);
|
||||
scroll_h = view_height - scroll_y - bottom_reserved -
|
||||
(integrated ? flint_px(8) : 0);
|
||||
if(scroll_h < 0)
|
||||
scroll_h = 0;
|
||||
|
||||
|
||||
@@ -425,7 +425,7 @@ finish_round(InbeApp *app)
|
||||
if(session_ensure_results_saved(app)) {
|
||||
#if ANDROID_BUILD
|
||||
android_allow_screen_off();
|
||||
android_timer_stop();
|
||||
stop_android_background_session(app);
|
||||
#endif
|
||||
app_switch_screen(app, InbeScreenResults);
|
||||
#if ANDROID_BUILD
|
||||
|
||||
+21
-12
@@ -320,7 +320,7 @@ habit_edit_scroll_content_height(int content_w, void *user_data)
|
||||
.label = locale_get("habit_description_label"),
|
||||
.field_h = flint_px(40)
|
||||
});
|
||||
height += flint_px(32) + flint_px(34);
|
||||
height += flint_px(32) + flint_px(76);
|
||||
height += ui_section_label_height((FlintUISectionLabel){0});
|
||||
for(int i = 0; i < EXERCISE_COUNT; i++)
|
||||
height += ui_checkbox_row_height((FlintUICheckboxRow){0});
|
||||
@@ -339,7 +339,7 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
{
|
||||
const char *title;
|
||||
const char *activity_options[EXERCISE_COUNT];
|
||||
Color color_options[6];
|
||||
Color color_options[12];
|
||||
int top_h = flint_px(58);
|
||||
int bottom_reserved;
|
||||
int content_x;
|
||||
@@ -486,21 +486,30 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
flint_text_draw(locale_get("habit_underline_label"), content_x, y,
|
||||
label_font, flint_darken(flint_theme_get_text(), 34));
|
||||
y += flint_px(32);
|
||||
color_options[0] = (Color){94, 166, 232, 255};
|
||||
color_options[1] = (Color){99, 196, 165, 255};
|
||||
color_options[2] = (Color){210, 180, 72, 255};
|
||||
color_options[3] = (Color){224, 124, 104, 255};
|
||||
color_options[4] = (Color){180, 132, 220, 255};
|
||||
color_options[5] = (Color){216, 116, 164, 255};
|
||||
for(int i = 0; i < 6; i++) {
|
||||
int cx = content_x + flint_px(18) + i * flint_px(42);
|
||||
color_options[0] = (Color){224, 92, 92, 255};
|
||||
color_options[1] = (Color){224, 124, 104, 255};
|
||||
color_options[2] = (Color){232, 150, 74, 255};
|
||||
color_options[3] = (Color){210, 180, 72, 255};
|
||||
color_options[4] = (Color){160, 196, 82, 255};
|
||||
color_options[5] = (Color){99, 196, 165, 255};
|
||||
color_options[6] = (Color){74, 186, 198, 255};
|
||||
color_options[7] = (Color){94, 166, 232, 255};
|
||||
color_options[8] = (Color){116, 132, 224, 255};
|
||||
color_options[9] = (Color){180, 132, 220, 255};
|
||||
color_options[10] = (Color){216, 116, 164, 255};
|
||||
color_options[11] = (Color){198, 96, 118, 255};
|
||||
for(int i = 0; i < 12; i++) {
|
||||
int row = i / 6;
|
||||
int col = i % 6;
|
||||
int cx = content_x + flint_px(18) + col * flint_px(42);
|
||||
int cy = y + row * flint_px(42);
|
||||
int selected = app->habit_edit.color.r == color_options[i].r &&
|
||||
app->habit_edit.color.g == color_options[i].g &&
|
||||
app->habit_edit.color.b == color_options[i].b;
|
||||
if(habit_color_button(app, cx, y, color_options[i], selected))
|
||||
if(habit_color_button(app, cx, cy, color_options[i], selected))
|
||||
app->habit_edit.color = color_options[i];
|
||||
}
|
||||
y += flint_px(34);
|
||||
y += flint_px(76);
|
||||
|
||||
if(ui_draw_section_label((FlintUISectionLabel){
|
||||
.label = locale_get("habit_practice_list_title"),
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "data.h"
|
||||
#include "storage.h"
|
||||
#include "app.h"
|
||||
#include "text_utils.h"
|
||||
#include "flint_theme.h"
|
||||
#include "flint_runtime_assets.h"
|
||||
#include "flint_locale.h"
|
||||
@@ -1313,23 +1314,7 @@ habit_weekly_draw_text_line(const char *text, int x, int y, int w, int h,
|
||||
while(font_size > FLINT_TEXT_8 && flint_text_measure(text, font_size) > w)
|
||||
font_size -= flint_px(1);
|
||||
if(flint_text_measure(text, font_size) > w) {
|
||||
snprintf(fitted, sizeof(fitted), "%s", text);
|
||||
while(fitted[0] != '\0' && flint_text_measure(fitted, font_size) > w) {
|
||||
size_t len = strlen(fitted);
|
||||
size_t cut = len;
|
||||
|
||||
if(len <= 3)
|
||||
break;
|
||||
if(len > 3 && strcmp(fitted + len - 3, "...") == 0)
|
||||
len -= 3;
|
||||
cut = len;
|
||||
do {
|
||||
cut--;
|
||||
} while(cut > 0 && (((unsigned char)fitted[cut] & 0xC0) == 0x80));
|
||||
fitted[cut] = '\0';
|
||||
if(cut + 3 < sizeof(fitted))
|
||||
strncat(fitted, "...", sizeof(fitted) - strlen(fitted) - 1);
|
||||
}
|
||||
inbe_text_fit_ellipsis(text, fitted, sizeof(fitted), w, font_size);
|
||||
draw_text = fitted;
|
||||
}
|
||||
flint_text_draw(draw_text, x + (w - flint_text_measure(draw_text, font_size)) / 2,
|
||||
|
||||
+236
-722
File diff suppressed because it is too large.
Load diff
@@ -4,7 +4,7 @@
|
||||
#include "app_fwd.h"
|
||||
|
||||
int profile_screen_draw(InbeApp *app);
|
||||
void profile_screen_refresh_social_cache(InbeApp *app);
|
||||
void profile_screen_draw_remove_friend_modal(InbeApp *app);
|
||||
int profile_screen_first_run_guide_active(const InbeApp *app);
|
||||
void profile_screen_prepare_first_run_guide(InbeApp *app);
|
||||
void profile_screen_draw_first_run_guide(InbeApp *app);
|
||||
|
||||
@@ -0,0 +1,822 @@
|
||||
#include "profile_social.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "flint_locale.h"
|
||||
#include "flint_theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "settings/settings_screen.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "sync_client.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
|
||||
enum {
|
||||
PROFILE_LEADERBOARD_STREAK = 0,
|
||||
PROFILE_LEADERBOARD_AVG_HOLD,
|
||||
PROFILE_LEADERBOARD_METRIC_COUNT
|
||||
};
|
||||
|
||||
static FlintUITextInputStyle
|
||||
profile_text_style(void)
|
||||
{
|
||||
return (FlintUITextInputStyle){
|
||||
.background = flint_darken(flint_theme_get_bg(), 6),
|
||||
.border = flint_darken(flint_theme_get_bg(), 34),
|
||||
.focus_border = flint_theme_get_button(),
|
||||
.text = flint_theme_get_text(),
|
||||
.cursor = flint_theme_get_text(),
|
||||
.radius = 0.0f,
|
||||
.padding_x = flint_px(10)
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
profile_friend_filter(int codepoint, void *user_data)
|
||||
{
|
||||
(void)user_data;
|
||||
return codepoint > 32 && codepoint < 127;
|
||||
}
|
||||
|
||||
static int
|
||||
profile_sync_url(char *out, size_t out_size)
|
||||
{
|
||||
const char *saved = storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
|
||||
if(saved == NULL || saved[0] == '\0')
|
||||
return 0;
|
||||
return sync_client_normalize_url(saved, out, out_size);
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_practice_id(int index)
|
||||
{
|
||||
switch(index) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return "meditation";
|
||||
case EXERCISE_SUN_SALUTATION:
|
||||
return "sun_salutation";
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return "whm";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_practice_label(int index)
|
||||
{
|
||||
switch(index) {
|
||||
case EXERCISE_MEDITATION:
|
||||
return locale_get("exercise_meditation");
|
||||
case EXERCISE_SUN_SALUTATION:
|
||||
return locale_get("exercise_sun_salutation");
|
||||
case EXERCISE_WIM_HOF:
|
||||
default:
|
||||
return locale_get("exercise_wim_hof");
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_leaderboard_metric_id_for_practice(int practice, int metric)
|
||||
{
|
||||
if(metric != PROFILE_LEADERBOARD_AVG_HOLD)
|
||||
return "streak";
|
||||
if(practice == EXERCISE_MEDITATION)
|
||||
return "avg_time";
|
||||
return "avg_hold";
|
||||
}
|
||||
|
||||
static int
|
||||
profile_leaderboard_metric_count(int practice)
|
||||
{
|
||||
return practice == EXERCISE_SUN_SALUTATION ? 1 : PROFILE_LEADERBOARD_METRIC_COUNT;
|
||||
}
|
||||
|
||||
static void
|
||||
profile_format_leaderboard_time(long seconds, char *out, size_t out_size)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
if(seconds < 0)
|
||||
seconds = 0;
|
||||
snprintf(out, out_size, "%ld:%02ld", seconds / 3600, (seconds % 3600) / 60);
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_leaderboard_metric_label(int practice, int metric)
|
||||
{
|
||||
if(metric != PROFILE_LEADERBOARD_AVG_HOLD)
|
||||
return locale_get("profile_metric_streak");
|
||||
return practice == EXERCISE_MEDITATION
|
||||
? locale_get("profile_metric_avg_time")
|
||||
: locale_get("profile_metric_avg_hold");
|
||||
}
|
||||
|
||||
static void
|
||||
profile_leaderboard_cache_key(char *out, size_t out_size, int practice, int metric)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
snprintf(out, out_size, "leaderboard.inbe.%s.%s",
|
||||
profile_practice_id(practice),
|
||||
profile_leaderboard_metric_id_for_practice(practice, metric));
|
||||
}
|
||||
|
||||
void
|
||||
profile_social_load_friends_cache(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!storage_get_social_cache_json("friends.requests",
|
||||
app->profile_friend_requests_json,
|
||||
sizeof(app->profile_friend_requests_json)))
|
||||
snprintf(app->profile_friend_requests_json,
|
||||
sizeof(app->profile_friend_requests_json),
|
||||
"{\"incoming\":[],\"outgoing\":[]}");
|
||||
if(!storage_get_social_cache_json("friends.list", app->profile_friends_json,
|
||||
sizeof(app->profile_friends_json)))
|
||||
snprintf(app->profile_friends_json, sizeof(app->profile_friends_json),
|
||||
"{\"friends\":[]}");
|
||||
app->profile_friends_loaded = 1;
|
||||
}
|
||||
|
||||
void
|
||||
profile_social_load_leaderboard_cache(InbeApp *app)
|
||||
{
|
||||
char key[96];
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
profile_leaderboard_cache_key(key, sizeof(key),
|
||||
app->profile_leaderboard_practice,
|
||||
app->profile_leaderboard_metric);
|
||||
if(!storage_get_social_cache_json(key, app->profile_leaderboard_json,
|
||||
sizeof(app->profile_leaderboard_json)))
|
||||
snprintf(app->profile_leaderboard_json, sizeof(app->profile_leaderboard_json),
|
||||
"{\"rows\":[]}");
|
||||
app->profile_leaderboard_loaded = 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_json_string_value(const char *object, const char *key, char *out, size_t out_size)
|
||||
{
|
||||
char pattern[48];
|
||||
const char *p;
|
||||
char *w;
|
||||
size_t left;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return NULL;
|
||||
out[0] = '\0';
|
||||
snprintf(pattern, sizeof(pattern), "\"%s\"", key);
|
||||
p = strstr(object, pattern);
|
||||
if(p == NULL)
|
||||
return NULL;
|
||||
p = strchr(p + strlen(pattern), ':');
|
||||
if(p == NULL)
|
||||
return NULL;
|
||||
p++;
|
||||
while(*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r')
|
||||
p++;
|
||||
if(*p++ != '"')
|
||||
return NULL;
|
||||
w = out;
|
||||
left = out_size - 1;
|
||||
while(*p != '\0' && *p != '"' && left > 0) {
|
||||
if(*p == '\\' && p[1] != '\0')
|
||||
p++;
|
||||
*w++ = *p++;
|
||||
left--;
|
||||
}
|
||||
*w = '\0';
|
||||
return *p == '"' ? p + 1 : NULL;
|
||||
}
|
||||
|
||||
static double
|
||||
profile_json_number_value(const char *object, const char *key)
|
||||
{
|
||||
char pattern[48];
|
||||
const char *p;
|
||||
|
||||
snprintf(pattern, sizeof(pattern), "\"%s\"", key);
|
||||
p = strstr(object, pattern);
|
||||
if(p == NULL)
|
||||
return 0.0;
|
||||
p = strchr(p + strlen(pattern), ':');
|
||||
if(p == NULL)
|
||||
return 0.0;
|
||||
return atof(p + 1);
|
||||
}
|
||||
|
||||
static int
|
||||
profile_json_array_count(const char *json, const char *array_key)
|
||||
{
|
||||
char key_pattern[48];
|
||||
const char *p;
|
||||
const char *end;
|
||||
int count = 0;
|
||||
|
||||
snprintf(key_pattern, sizeof(key_pattern), "\"%s\"", array_key);
|
||||
p = strstr(json != NULL ? json : "", key_pattern);
|
||||
if(p == NULL)
|
||||
return 0;
|
||||
p = strchr(p, '[');
|
||||
end = p != NULL ? strchr(p, ']') : NULL;
|
||||
if(p == NULL || end == NULL)
|
||||
return 0;
|
||||
while((p = strchr(p, '{')) != NULL && p < end) {
|
||||
count++;
|
||||
p++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
profile_social_friends_count(InbeApp *app)
|
||||
{
|
||||
if(app != NULL && !app->profile_friends_loaded)
|
||||
profile_social_load_friends_cache(app);
|
||||
return profile_json_array_count(app != NULL ? app->profile_friends_json : "",
|
||||
"friends");
|
||||
}
|
||||
|
||||
int
|
||||
profile_social_pending_count(InbeApp *app)
|
||||
{
|
||||
if(app != NULL && !app->profile_friends_loaded)
|
||||
profile_social_load_friends_cache(app);
|
||||
return profile_json_array_count(app != NULL ? app->profile_friend_requests_json : "",
|
||||
"incoming");
|
||||
}
|
||||
|
||||
static void
|
||||
profile_public_id_short(char *out, size_t out_size, const char *user_id)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
if(user_id == NULL || user_id[0] == '\0')
|
||||
snprintf(out, out_size, "----");
|
||||
else
|
||||
snprintf(out, out_size, "%.*s", 4, user_id);
|
||||
}
|
||||
|
||||
static void
|
||||
profile_display_name(char *out, size_t out_size, const char *alias,
|
||||
const char *user_id)
|
||||
{
|
||||
char short_id[8];
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
if(alias != NULL && alias[0] != '\0') {
|
||||
snprintf(out, out_size, "@%s", alias);
|
||||
} else if(user_id != NULL && user_id[0] != '\0') {
|
||||
profile_public_id_short(short_id, sizeof(short_id), user_id);
|
||||
snprintf(out, out_size, "%s...", short_id);
|
||||
} else {
|
||||
snprintf(out, out_size, "----...");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
profile_prompt_remove_friend(InbeApp *app, const char *friend_user_id,
|
||||
const char *friend_name)
|
||||
{
|
||||
if(app == NULL || friend_user_id == NULL || friend_user_id[0] == '\0')
|
||||
return;
|
||||
snprintf(app->profile_pending_friend_remove_id,
|
||||
sizeof(app->profile_pending_friend_remove_id), "%s", friend_user_id);
|
||||
snprintf(app->profile_pending_friend_remove_name,
|
||||
sizeof(app->profile_pending_friend_remove_name), "%s",
|
||||
friend_name != NULL && friend_name[0] != '\0' ? friend_name : friend_user_id);
|
||||
app_open_modal(app, UIModalConfirmRemoveFriend);
|
||||
}
|
||||
|
||||
static void
|
||||
profile_draw_json_people(const char *json, const char *array_key,
|
||||
int x, int w, int *y, int with_actions, InbeApp *app)
|
||||
{
|
||||
char key_pattern[48];
|
||||
const char *p;
|
||||
const char *end;
|
||||
int rows = 0;
|
||||
int font = flint_ui_font();
|
||||
int small = flint_ui_font_small();
|
||||
int with_remove = !with_actions && strcmp(array_key, "friends") == 0;
|
||||
int with_cancel = !with_actions && strcmp(array_key, "outgoing") == 0;
|
||||
|
||||
snprintf(key_pattern, sizeof(key_pattern), "\"%s\"", array_key);
|
||||
p = strstr(json != NULL ? json : "", key_pattern);
|
||||
if(p == NULL) {
|
||||
flint_text_draw(locale_get("profile_none_label"), x, *y, small,
|
||||
flint_darken(flint_theme_get_text(), 35));
|
||||
*y += flint_px(24);
|
||||
return;
|
||||
}
|
||||
p = strchr(p, '[');
|
||||
end = p != NULL ? strchr(p, ']') : NULL;
|
||||
if(p == NULL || end == NULL) {
|
||||
flint_text_draw(locale_get("profile_none_label"), x, *y, small,
|
||||
flint_darken(flint_theme_get_text(), 35));
|
||||
*y += flint_px(24);
|
||||
return;
|
||||
}
|
||||
while((p = strchr(p, '{')) != NULL && p < end && rows < 8) {
|
||||
char id[80];
|
||||
char alias[48];
|
||||
char display_id[80];
|
||||
char title[96];
|
||||
int row_h = with_actions ? flint_px(42) : flint_px(30);
|
||||
int hover_accept = 0;
|
||||
int hover_decline = 0;
|
||||
int hover_remove = 0;
|
||||
int hover_cancel = 0;
|
||||
char url[256];
|
||||
|
||||
id[0] = '\0';
|
||||
alias[0] = '\0';
|
||||
display_id[0] = '\0';
|
||||
if(profile_json_string_value(p, "id", id, sizeof(id)) == NULL &&
|
||||
profile_json_string_value(p, "user_id_hash", id, sizeof(id)) == NULL)
|
||||
break;
|
||||
if(strcmp(array_key, "incoming") == 0) {
|
||||
profile_json_string_value(p, "requester_alias", alias, sizeof(alias));
|
||||
profile_json_string_value(p, "requester_user_id_hash", display_id,
|
||||
sizeof(display_id));
|
||||
} else if(strcmp(array_key, "outgoing") == 0) {
|
||||
profile_json_string_value(p, "target_alias", alias, sizeof(alias));
|
||||
profile_json_string_value(p, "target_user_id_hash", display_id,
|
||||
sizeof(display_id));
|
||||
} else {
|
||||
profile_json_string_value(p, "alias", alias, sizeof(alias));
|
||||
profile_json_string_value(p, "user_id_hash", display_id, sizeof(display_id));
|
||||
}
|
||||
if(alias[0] == '\0')
|
||||
profile_json_string_value(p, "alias", alias, sizeof(alias));
|
||||
if(display_id[0] == '\0')
|
||||
snprintf(display_id, sizeof(display_id), "%s", id);
|
||||
profile_display_name(title, sizeof(title), alias, display_id);
|
||||
flint_text_draw(title, x, *y, font, flint_theme_get_text());
|
||||
if(with_remove) {
|
||||
int icon_size = flint_px(18);
|
||||
int icon_padding = flint_px(6);
|
||||
int button_w = icon_size + icon_padding * 2;
|
||||
if(ui_draw_icon_btn_padded(x + w - button_w, *y - flint_px(6),
|
||||
icon_size, icon_padding,
|
||||
app->icons[UI_ICON_TYPE_TRASH],
|
||||
&hover_remove)) {
|
||||
profile_prompt_remove_friend(app, display_id, title);
|
||||
}
|
||||
} else if(with_cancel) {
|
||||
int icon_size = flint_px(18);
|
||||
int icon_padding = flint_px(6);
|
||||
int button_w = icon_size + icon_padding * 2;
|
||||
if(ui_draw_icon_btn_padded(x + w - button_w, *y - flint_px(6),
|
||||
icon_size, icon_padding,
|
||||
app->icons[UI_ICON_TYPE_TRASH],
|
||||
&hover_cancel) &&
|
||||
profile_sync_url(url, sizeof(url))) {
|
||||
app_request_friend_decline(app, id);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"),
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
if(with_actions) {
|
||||
int btn_w = (w - flint_px(8)) / 2;
|
||||
if(ui_draw_generic_button(x, *y + flint_px(22), btn_w, flint_px(30),
|
||||
locale_get("profile_friend_accept_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_accept) &&
|
||||
profile_sync_url(url, sizeof(url))) {
|
||||
app_request_friend_accept(app, id);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"), NULL);
|
||||
}
|
||||
if(ui_draw_generic_button(x + btn_w + flint_px(8), *y + flint_px(22), btn_w,
|
||||
flint_px(30),
|
||||
locale_get("profile_friend_decline_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY,
|
||||
0, &hover_decline) &&
|
||||
profile_sync_url(url, sizeof(url))) {
|
||||
app_request_friend_decline(app, id);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"), NULL);
|
||||
}
|
||||
}
|
||||
*y += row_h;
|
||||
rows++;
|
||||
p++;
|
||||
}
|
||||
if(rows == 0) {
|
||||
flint_text_draw(locale_get("profile_none_label"), x, *y, small,
|
||||
flint_darken(flint_theme_get_text(), 35));
|
||||
*y += flint_px(24);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
profile_screen_draw_remove_friend_modal(InbeApp *app)
|
||||
{
|
||||
char message[384];
|
||||
int modal_result;
|
||||
|
||||
if(app == NULL || !app->modal.active ||
|
||||
app->modal.type != UIModalConfirmRemoveFriend)
|
||||
return;
|
||||
|
||||
snprintf(message, sizeof(message),
|
||||
locale_get("profile_friend_remove_message"),
|
||||
app->profile_pending_friend_remove_name[0] != '\0'
|
||||
? app->profile_pending_friend_remove_name
|
||||
: "this friend");
|
||||
modal_result = ui_draw_modal(locale_get("profile_friend_remove_title"), message,
|
||||
locale_get("cancel_button"),
|
||||
locale_get("delete_button"));
|
||||
if(modal_result == 1) {
|
||||
app->profile_pending_friend_remove_id[0] = '\0';
|
||||
app->profile_pending_friend_remove_name[0] = '\0';
|
||||
app_close_modal(app);
|
||||
} else if(modal_result == 2) {
|
||||
char url[256];
|
||||
|
||||
if(profile_sync_url(url, sizeof(url))) {
|
||||
app_request_friend_remove(app, app->profile_pending_friend_remove_id);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"),
|
||||
NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
}
|
||||
app->profile_pending_friend_remove_id[0] = '\0';
|
||||
app->profile_pending_friend_remove_name[0] = '\0';
|
||||
app_close_modal(app);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
profile_social_draw_friends(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
int font = flint_ui_font();
|
||||
int btn_h = flint_px(34);
|
||||
int hover_add = 0;
|
||||
int commit = 0;
|
||||
char url[256];
|
||||
int incoming_count;
|
||||
int outgoing_count;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!app->profile_friends_loaded)
|
||||
profile_social_load_friends_cache(app);
|
||||
incoming_count = profile_json_array_count(app->profile_friend_requests_json, "incoming");
|
||||
outgoing_count = profile_json_array_count(app->profile_friend_requests_json, "outgoing");
|
||||
|
||||
*y += flint_px(16);
|
||||
flint_text_draw(locale_get("profile_friends_title"), x, *y, font,
|
||||
flint_theme_get_text());
|
||||
*y += flint_px(30);
|
||||
(void)flint_ui_text_field((FlintUITextField){
|
||||
.bounds = {x, *y, w, flint_px(38)},
|
||||
.text = app->profile_friend_input,
|
||||
.text_size = sizeof(app->profile_friend_input),
|
||||
.cursor_position = &app->profile_friend_input_cursor,
|
||||
.focused = &app->profile_friend_input_focused,
|
||||
.max_codepoints = 79,
|
||||
.font = flint_ui_font(),
|
||||
.focus_id = 810,
|
||||
.style = profile_text_style(),
|
||||
.filter = profile_friend_filter,
|
||||
.commit_pressed = &commit
|
||||
});
|
||||
*y += flint_px(46);
|
||||
if((ui_draw_generic_button(x, *y, w, btn_h,
|
||||
locale_get("profile_add_friend_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY,
|
||||
app->profile_friend_input[0] == '\0', &hover_add) || commit) &&
|
||||
app->profile_friend_input[0] != '\0') {
|
||||
if(profile_sync_url(url, sizeof(url))) {
|
||||
app_request_friend_send(app, app->profile_friend_input);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"), NULL);
|
||||
profile_social_load_friends_cache(app);
|
||||
app->profile_friend_input[0] = '\0';
|
||||
app->profile_friend_input_cursor = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(22);
|
||||
|
||||
if(incoming_count > 0) {
|
||||
flint_text_draw(locale_get("profile_incoming_title"), x, *y, font,
|
||||
flint_theme_get_text());
|
||||
*y += flint_px(28);
|
||||
profile_draw_json_people(app->profile_friend_requests_json, "incoming", x, w, y, 1, app);
|
||||
*y += flint_px(16);
|
||||
}
|
||||
flint_text_draw(locale_get("profile_friends_title"), x, *y, font,
|
||||
flint_theme_get_text());
|
||||
*y += flint_px(28);
|
||||
profile_draw_json_people(app->profile_friends_json, "friends", x, w, y, 0, app);
|
||||
if(outgoing_count > 0) {
|
||||
*y += flint_px(16);
|
||||
flint_text_draw(locale_get("profile_outgoing_title"), x, *y, font,
|
||||
flint_theme_get_text());
|
||||
*y += flint_px(28);
|
||||
profile_draw_json_people(app->profile_friend_requests_json, "outgoing", x, w, y, 0, app);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
profile_draw_leaderboard_value(int x, int w, int y, const char *value, int font)
|
||||
{
|
||||
int rank_w = flint_text_measure(value, font);
|
||||
flint_text_draw(value, x + w - rank_w, y, font, flint_theme_get_text());
|
||||
}
|
||||
|
||||
static int
|
||||
profile_today_index(void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm_value = localtime(&now);
|
||||
|
||||
if(tm_value == NULL)
|
||||
return 0;
|
||||
return (tm_value->tm_year + 1900) * 10000 +
|
||||
(tm_value->tm_mon + 1) * 100 + tm_value->tm_mday;
|
||||
}
|
||||
|
||||
static double
|
||||
profile_local_leaderboard_value(InbeApp *app, char *out, size_t out_size)
|
||||
{
|
||||
int streak = 0;
|
||||
long avg = 0;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0.0;
|
||||
out[0] = '\0';
|
||||
if(app == NULL)
|
||||
return 0.0;
|
||||
storage_profile_activity_stats(app->profile_leaderboard_practice,
|
||||
profile_today_index(), &streak, &avg);
|
||||
if(app->profile_leaderboard_metric != PROFILE_LEADERBOARD_AVG_HOLD) {
|
||||
snprintf(out, out_size, "%ld", (long)streak);
|
||||
return (double)streak;
|
||||
} else if(app->profile_leaderboard_practice == EXERCISE_MEDITATION) {
|
||||
profile_format_leaderboard_time(avg, out, out_size);
|
||||
return (double)avg;
|
||||
} else {
|
||||
snprintf(out, out_size, "%ld", avg);
|
||||
return (double)avg;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct ProfileLeaderboardDrawRow {
|
||||
char user_id[80];
|
||||
char alias[48];
|
||||
char value[48];
|
||||
double sort_value;
|
||||
} ProfileLeaderboardDrawRow;
|
||||
|
||||
static int
|
||||
profile_leaderboard_row_seen(const ProfileLeaderboardDrawRow *rows, int count,
|
||||
const char *user_id)
|
||||
{
|
||||
if(user_id == NULL || user_id[0] == '\0')
|
||||
return 1;
|
||||
for(int i = 0; i < count; i++) {
|
||||
if(strcmp(rows[i].user_id, user_id) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
profile_leaderboard_row_compare(const void *left_ptr, const void *right_ptr)
|
||||
{
|
||||
const ProfileLeaderboardDrawRow *left = left_ptr;
|
||||
const ProfileLeaderboardDrawRow *right = right_ptr;
|
||||
const char *left_name = left->alias[0] != '\0' ? left->alias : left->user_id;
|
||||
const char *right_name = right->alias[0] != '\0' ? right->alias : right->user_id;
|
||||
|
||||
if(left->sort_value < right->sort_value)
|
||||
return 1;
|
||||
if(left->sort_value > right->sort_value)
|
||||
return -1;
|
||||
return strcmp(left_name, right_name);
|
||||
}
|
||||
|
||||
static void
|
||||
profile_draw_leaderboard_rows(InbeApp *app, const char *json, int x, int w, int *y)
|
||||
{
|
||||
const char *p = strstr(json != NULL ? json : "", "\"rows\"");
|
||||
int rows = 0;
|
||||
int font = flint_ui_font();
|
||||
int small = flint_ui_font_small();
|
||||
ProfileLeaderboardDrawRow draw_rows[24];
|
||||
InbeSyncAccount account;
|
||||
int has_account = sync_account_load(&account) && account.public_id[0] != '\0';
|
||||
int self_seen = 0;
|
||||
char self_value[48];
|
||||
double self_sort_value;
|
||||
|
||||
self_sort_value = profile_local_leaderboard_value(app, self_value, sizeof(self_value));
|
||||
|
||||
while(p != NULL && (p = strchr(p, '{')) != NULL && rows < 24) {
|
||||
char alias[48];
|
||||
char user_id[80];
|
||||
char value[48];
|
||||
char label[48];
|
||||
double number;
|
||||
|
||||
if(profile_json_string_value(p, "user_id_hash", user_id, sizeof(user_id)) == NULL)
|
||||
break;
|
||||
profile_json_string_value(p, "alias", alias, sizeof(alias));
|
||||
profile_json_string_value(p, "label", label, sizeof(label));
|
||||
number = profile_json_number_value(p, "value");
|
||||
if(has_account && strcmp(user_id, account.public_id) == 0) {
|
||||
snprintf(value, sizeof(value), "%s", self_value);
|
||||
number = self_sort_value;
|
||||
self_seen = 1;
|
||||
} else if(app != NULL &&
|
||||
app->profile_leaderboard_practice == EXERCISE_MEDITATION &&
|
||||
app->profile_leaderboard_metric == PROFILE_LEADERBOARD_AVG_HOLD &&
|
||||
label[0] != '\0') {
|
||||
snprintf(value, sizeof(value), "%s", label);
|
||||
} else {
|
||||
snprintf(value, sizeof(value), "%.0f", number);
|
||||
}
|
||||
snprintf(draw_rows[rows].user_id, sizeof(draw_rows[rows].user_id), "%s", user_id);
|
||||
snprintf(draw_rows[rows].alias, sizeof(draw_rows[rows].alias), "%s", alias);
|
||||
snprintf(draw_rows[rows].value, sizeof(draw_rows[rows].value), "%s", value);
|
||||
draw_rows[rows].sort_value = number;
|
||||
rows++;
|
||||
p++;
|
||||
}
|
||||
|
||||
if(has_account && !self_seen && rows < 24) {
|
||||
const char *alias_text = storage_get_setting_text("sync_account_alias");
|
||||
|
||||
snprintf(draw_rows[rows].user_id, sizeof(draw_rows[rows].user_id), "%s",
|
||||
account.public_id);
|
||||
snprintf(draw_rows[rows].alias, sizeof(draw_rows[rows].alias), "%s",
|
||||
alias_text != NULL ? alias_text : "");
|
||||
snprintf(draw_rows[rows].value, sizeof(draw_rows[rows].value), "%s", self_value);
|
||||
draw_rows[rows].sort_value = self_sort_value;
|
||||
rows++;
|
||||
}
|
||||
|
||||
p = strstr(app != NULL ? app->profile_friends_json : "", "\"friends\"");
|
||||
while(p != NULL && (p = strchr(p, '{')) != NULL && rows < 24) {
|
||||
char alias[48];
|
||||
char user_id[80];
|
||||
|
||||
if(profile_json_string_value(p, "user_id_hash", user_id, sizeof(user_id)) == NULL)
|
||||
break;
|
||||
if(profile_leaderboard_row_seen(draw_rows, rows, user_id)) {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
profile_json_string_value(p, "alias", alias, sizeof(alias));
|
||||
snprintf(draw_rows[rows].user_id, sizeof(draw_rows[rows].user_id), "%s", user_id);
|
||||
snprintf(draw_rows[rows].alias, sizeof(draw_rows[rows].alias), "%s", alias);
|
||||
snprintf(draw_rows[rows].value, sizeof(draw_rows[rows].value), "%s",
|
||||
app != NULL &&
|
||||
app->profile_leaderboard_practice == EXERCISE_MEDITATION &&
|
||||
app->profile_leaderboard_metric == PROFILE_LEADERBOARD_AVG_HOLD
|
||||
? "0:00"
|
||||
: "0");
|
||||
draw_rows[rows].sort_value = 0.0;
|
||||
rows++;
|
||||
p++;
|
||||
}
|
||||
|
||||
qsort(draw_rows, (size_t)rows, sizeof(draw_rows[0]), profile_leaderboard_row_compare);
|
||||
for(int i = 0; i < rows && i < 12; i++) {
|
||||
char display[96];
|
||||
char name[128];
|
||||
|
||||
profile_display_name(display, sizeof(display),
|
||||
draw_rows[i].alias, draw_rows[i].user_id);
|
||||
snprintf(name, sizeof(name), "%d. %s", i + 1, display);
|
||||
flint_text_draw(name, x, *y, font, flint_theme_get_text());
|
||||
profile_draw_leaderboard_value(x, w, *y, draw_rows[i].value, font);
|
||||
*y += flint_px(30);
|
||||
}
|
||||
|
||||
if(rows == 0) {
|
||||
flint_text_draw(locale_get("profile_no_leaderboard_data"), x, *y, small,
|
||||
flint_darken(flint_theme_get_text(), 35));
|
||||
*y += flint_px(24);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
profile_refresh_leaderboard(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
profile_social_load_leaderboard_cache(app);
|
||||
app_request_social_refresh(app);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"), NULL);
|
||||
}
|
||||
|
||||
void
|
||||
profile_social_refresh_cache(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
profile_social_load_friends_cache(app);
|
||||
profile_social_load_leaderboard_cache(app);
|
||||
app_request_social_refresh(app);
|
||||
settings_screen_set_status_success(locale_get("profile_updating_status"), NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
profile_draw_choice_row(InbeApp *app, int x, int w, int *y, int *value,
|
||||
const char *const *labels, int count)
|
||||
{
|
||||
int gap = flint_px(8);
|
||||
int btn_h = flint_px(34);
|
||||
int btn_w;
|
||||
|
||||
if(count <= 0)
|
||||
return;
|
||||
btn_w = (w - gap * (count - 1)) / count;
|
||||
for(int i = 0; i < count; i++) {
|
||||
int hover = 0;
|
||||
int bx = x + i * (btn_w + gap);
|
||||
int bw = i == count - 1 ? x + w - bx : btn_w;
|
||||
int selected = *value == i;
|
||||
if(ui_draw_generic_button(bx, *y, bw, btn_h, labels[i],
|
||||
selected ? UI_BUTTON_STYLE_TAB_SELECTED
|
||||
: UI_BUTTON_STYLE_TAB,
|
||||
0, &hover) && !selected) {
|
||||
*value = i;
|
||||
profile_social_load_leaderboard_cache(app);
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(10);
|
||||
}
|
||||
|
||||
void
|
||||
profile_social_draw_leaderboard(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
const char *practice_options[EXERCISE_COUNT];
|
||||
const char *metric_options[PROFILE_LEADERBOARD_METRIC_COUNT];
|
||||
int metric_count;
|
||||
int before_practice;
|
||||
int before_metric;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
for(int i = 0; i < EXERCISE_COUNT; i++)
|
||||
practice_options[i] = profile_practice_label(i);
|
||||
if(app->profile_leaderboard_practice < 0 ||
|
||||
app->profile_leaderboard_practice >= EXERCISE_COUNT)
|
||||
app->profile_leaderboard_practice = EXERCISE_WIM_HOF;
|
||||
if(app->profile_leaderboard_metric < 0 ||
|
||||
app->profile_leaderboard_metric >= PROFILE_LEADERBOARD_METRIC_COUNT)
|
||||
app->profile_leaderboard_metric = PROFILE_LEADERBOARD_STREAK;
|
||||
metric_count = profile_leaderboard_metric_count(app->profile_leaderboard_practice);
|
||||
if(app->profile_leaderboard_metric >= metric_count)
|
||||
app->profile_leaderboard_metric = PROFILE_LEADERBOARD_STREAK;
|
||||
if(!app->profile_leaderboard_loaded)
|
||||
profile_social_load_leaderboard_cache(app);
|
||||
metric_options[PROFILE_LEADERBOARD_STREAK] =
|
||||
profile_leaderboard_metric_label(app->profile_leaderboard_practice,
|
||||
PROFILE_LEADERBOARD_STREAK);
|
||||
metric_options[PROFILE_LEADERBOARD_AVG_HOLD] =
|
||||
profile_leaderboard_metric_label(app->profile_leaderboard_practice,
|
||||
PROFILE_LEADERBOARD_AVG_HOLD);
|
||||
|
||||
*y += flint_px(16);
|
||||
flint_text_draw(locale_get("profile_practice_label"), x, *y, flint_ui_font_small(),
|
||||
flint_darken(flint_theme_get_text(), 35));
|
||||
*y += flint_px(22);
|
||||
before_practice = app->profile_leaderboard_practice;
|
||||
ui_draw_dropdown_button(811, x, *y, w, flint_px(36), practice_options,
|
||||
EXERCISE_COUNT, &app->profile_leaderboard_practice);
|
||||
if(app->profile_leaderboard_practice != before_practice) {
|
||||
metric_count = profile_leaderboard_metric_count(app->profile_leaderboard_practice);
|
||||
if(app->profile_leaderboard_metric >= metric_count)
|
||||
app->profile_leaderboard_metric = PROFILE_LEADERBOARD_STREAK;
|
||||
metric_options[PROFILE_LEADERBOARD_STREAK] =
|
||||
profile_leaderboard_metric_label(app->profile_leaderboard_practice,
|
||||
PROFILE_LEADERBOARD_STREAK);
|
||||
metric_options[PROFILE_LEADERBOARD_AVG_HOLD] =
|
||||
profile_leaderboard_metric_label(app->profile_leaderboard_practice,
|
||||
PROFILE_LEADERBOARD_AVG_HOLD);
|
||||
profile_refresh_leaderboard(app);
|
||||
}
|
||||
*y += flint_px(46);
|
||||
before_metric = app->profile_leaderboard_metric;
|
||||
profile_draw_choice_row(app, x, w, y, &app->profile_leaderboard_metric,
|
||||
metric_options, metric_count);
|
||||
if(app->profile_leaderboard_metric != before_metric)
|
||||
profile_refresh_leaderboard(app);
|
||||
*y += flint_px(22);
|
||||
if(!app->profile_friends_loaded)
|
||||
profile_social_load_friends_cache(app);
|
||||
profile_draw_leaderboard_rows(app, app->profile_leaderboard_json, x, w, y);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_PROFILE_SOCIAL_H
|
||||
#define INBE_PROFILE_SOCIAL_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
void profile_social_load_friends_cache(InbeApp *app);
|
||||
void profile_social_load_leaderboard_cache(InbeApp *app);
|
||||
void profile_social_refresh_cache(InbeApp *app);
|
||||
int profile_social_friends_count(InbeApp *app);
|
||||
int profile_social_pending_count(InbeApp *app);
|
||||
void profile_social_draw_friends(InbeApp *app, int x, int w, int *y);
|
||||
void profile_social_draw_leaderboard(InbeApp *app, int x, int w, int *y);
|
||||
|
||||
#endif
|
||||
@@ -225,10 +225,10 @@ settings_draw_sync_review_modal(InbeApp *app)
|
||||
free(diff_detail);
|
||||
return 0;
|
||||
}
|
||||
frame = ui_draw_modal_frame(modal_w, modal_h, "Sync needs review",
|
||||
frame = ui_draw_modal_frame(modal_w, modal_h, locale_get("sync_review_needed"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
intro = (FlintUIParagraph){
|
||||
.text = "Review data differences.",
|
||||
.text = locale_get("sync_review_message"),
|
||||
.width = frame.content_w,
|
||||
.font = flint_ui_font_small(),
|
||||
.line_gap = flint_px(2),
|
||||
@@ -954,9 +954,9 @@ settings_data_draw_modals(InbeApp *app)
|
||||
app_reload_after_import(app, 0);
|
||||
else
|
||||
app_auto_sync(app);
|
||||
settings_screen_set_status_success(use_remote ? "Using remote data" : "Keeping local data", NULL);
|
||||
settings_screen_set_status_success(locale_get(use_remote ? "sync_review_using_remote" : "sync_review_keeping_local"), NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error("Sync review failed");
|
||||
settings_screen_set_status_error(locale_get("sync_review_failed"));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "flint_locale.h"
|
||||
#include "flint_theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "settings_ui.h"
|
||||
|
||||
static int
|
||||
settings_device_orientation_option_count(void)
|
||||
@@ -18,59 +19,6 @@ settings_device_orientation_option_count(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static FlintUIParagraph
|
||||
settings_device_label_paragraph(const char *label, int w)
|
||||
{
|
||||
return (FlintUIParagraph){
|
||||
.text = label,
|
||||
.width = w
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
settings_device_toggle_row_height(const char *label, int w)
|
||||
{
|
||||
int label_h;
|
||||
int row_h;
|
||||
|
||||
if(w <= 0)
|
||||
w = flint_px(160);
|
||||
|
||||
label_h = flint_ui_paragraph_height(settings_device_label_paragraph(label, w));
|
||||
row_h = label_h + flint_px(8) + flint_px(30) + flint_px(22);
|
||||
if(row_h < flint_px(76))
|
||||
row_h = flint_px(76);
|
||||
return row_h;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_device_draw_toggle_row(int x, int w, int *y, const char *label, int *value)
|
||||
{
|
||||
int label_y;
|
||||
int label_h;
|
||||
int row_h;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
if(y == NULL)
|
||||
return 0;
|
||||
|
||||
row_h = settings_device_toggle_row_height(label, w);
|
||||
label_y = *y;
|
||||
flint_ui_paragraph_draw(settings_device_label_paragraph(label, w), x, &label_y);
|
||||
label_h = label_y - *y;
|
||||
|
||||
if(ui_draw_toggle_switch(x, *y + label_h + flint_px(8), toggle_w, toggle_h,
|
||||
value, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
*y += row_h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*y += row_h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
settings_device_content_height(int content_w)
|
||||
{
|
||||
@@ -80,7 +28,7 @@ settings_device_content_height(int content_w)
|
||||
#if !ANDROID_BUILD && !defined(PLATFORM_WEB)
|
||||
height += flint_px(50);
|
||||
#endif
|
||||
height += settings_device_toggle_row_height(locale_get("on_screen_keyboard_label"), label_w);
|
||||
height += settings_ui_toggle_row_height(locale_get("on_screen_keyboard_label"), label_w);
|
||||
return height;
|
||||
}
|
||||
|
||||
@@ -133,8 +81,8 @@ settings_device_draw(InbeApp *app, int x, int w, int *y, SettingsDeviceState *st
|
||||
*y += flint_px(50);
|
||||
#endif
|
||||
|
||||
if(settings_device_draw_toggle_row(x, w, y, locale_get("on_screen_keyboard_label"),
|
||||
&keyboard_toggle)) {
|
||||
if(settings_ui_draw_toggle_row(x, w, y, locale_get("on_screen_keyboard_label"),
|
||||
&keyboard_toggle)) {
|
||||
app->on_screen_keyboard_enabled = keyboard_toggle;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
|
||||
@@ -4,72 +4,20 @@
|
||||
#include "app_settings.h"
|
||||
#include "flint_locale.h"
|
||||
#include "flint_ui.h"
|
||||
#include "settings_ui.h"
|
||||
|
||||
#define SETTINGS_SESSION_SLIDER_ROW_H 52
|
||||
|
||||
static FlintUIParagraph
|
||||
settings_session_label_paragraph(const char *label, int w)
|
||||
{
|
||||
return (FlintUIParagraph){
|
||||
.text = label,
|
||||
.width = w
|
||||
};
|
||||
}
|
||||
|
||||
static int
|
||||
settings_session_toggle_row_height(const char *label, int w)
|
||||
{
|
||||
int label_h;
|
||||
int row_h;
|
||||
|
||||
if(w <= 0)
|
||||
w = flint_px(160);
|
||||
|
||||
label_h = flint_ui_paragraph_height(settings_session_label_paragraph(label, w));
|
||||
row_h = label_h + flint_px(8) + flint_px(30) + flint_px(22);
|
||||
if(row_h < flint_px(76))
|
||||
row_h = flint_px(76);
|
||||
return row_h;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_session_draw_toggle_row(int x, int w, int *y, const char *label, int *value)
|
||||
{
|
||||
int label_y;
|
||||
int label_h;
|
||||
int row_h;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
if(y == NULL)
|
||||
return 0;
|
||||
|
||||
row_h = settings_session_toggle_row_height(label, w);
|
||||
label_y = *y;
|
||||
flint_ui_paragraph_draw(settings_session_label_paragraph(label, w), x, &label_y);
|
||||
label_h = label_y - *y;
|
||||
|
||||
if(ui_draw_toggle_switch(x, *y + label_h + flint_px(8), toggle_w, toggle_h,
|
||||
value, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
*y += row_h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*y += row_h;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
settings_session_content_height(int content_w)
|
||||
{
|
||||
int label_w = content_w > 0 ? content_w : flint_px(240);
|
||||
int height = flint_px(SETTINGS_SESSION_SLIDER_ROW_H) + flint_px(40);
|
||||
|
||||
height += settings_session_toggle_row_height(locale_get("show_session_volume_control_label"),
|
||||
label_w);
|
||||
height += settings_session_toggle_row_height(locale_get("play_in_background_label"),
|
||||
label_w);
|
||||
height += settings_ui_toggle_row_height(locale_get("show_session_volume_control_label"),
|
||||
label_w);
|
||||
height += settings_ui_toggle_row_height(locale_get("play_in_background_label"),
|
||||
label_w);
|
||||
return height;
|
||||
}
|
||||
|
||||
@@ -93,17 +41,17 @@ settings_session_draw(InbeApp *app, int x, int w, int *y)
|
||||
*y += flint_px(SETTINGS_SESSION_SLIDER_ROW_H);
|
||||
|
||||
show_session_volume = app->show_session_volume_control;
|
||||
if(settings_session_draw_toggle_row(x, w, y,
|
||||
locale_get("show_session_volume_control_label"),
|
||||
&show_session_volume)) {
|
||||
if(settings_ui_draw_toggle_row(x, w, y,
|
||||
locale_get("show_session_volume_control_label"),
|
||||
&show_session_volume)) {
|
||||
app->show_session_volume_control = show_session_volume;
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
|
||||
play_in_background = app->inbe.play_in_background;
|
||||
if(settings_session_draw_toggle_row(x, w, y, locale_get("play_in_background_label"),
|
||||
&play_in_background)) {
|
||||
if(settings_ui_draw_toggle_row(x, w, y, locale_get("play_in_background_label"),
|
||||
&play_in_background)) {
|
||||
app->inbe.play_in_background = play_in_background;
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
|
||||
@@ -261,6 +261,21 @@ settings_sync_result_key(FlintLyraSyncResult result)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_create_account(InbeApp *app, InbeSyncAccount *account)
|
||||
{
|
||||
if(account == NULL)
|
||||
return 0;
|
||||
if(!sync_account_create(account)) {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
return 0;
|
||||
}
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app_auto_sync(app);
|
||||
settings_sync_open_alias_modal(app, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_run_connect(InbeApp *app)
|
||||
{
|
||||
@@ -276,6 +291,7 @@ settings_sync_run_connect(InbeApp *app)
|
||||
storage_set_setting_text(INBE_SYNC_SERVER_URL_KEY, url);
|
||||
result = sync_client_sync(url);
|
||||
if(result == FLINT_LYRA_SYNC_OK) {
|
||||
app_request_social_refresh(app);
|
||||
if(storage_sync_review_clear_if_no_visible_diff()) {
|
||||
app_reload_after_import(app, 0);
|
||||
settings_screen_set_status_success(locale_get(settings_sync_result_key(result)), NULL);
|
||||
@@ -284,7 +300,7 @@ settings_sync_run_connect(InbeApp *app)
|
||||
settings_screen_set_status_success(locale_get(settings_sync_result_key(result)), NULL);
|
||||
} else if(storage_sync_review_pending()) {
|
||||
app_open_modal(app, UIModalSyncReview);
|
||||
settings_screen_set_status_error("Sync needs review");
|
||||
settings_screen_set_status_error(locale_get("sync_review_needed"));
|
||||
} else {
|
||||
app_reload_after_import(app, 0);
|
||||
settings_screen_set_status_success(locale_get(settings_sync_result_key(result)), NULL);
|
||||
@@ -360,12 +376,7 @@ settings_sync_account_draw(InbeApp *app, int x, int w, int *y)
|
||||
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(sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
settings_sync_open_alias_modal(app, 1);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
settings_sync_create_account(app, &account);
|
||||
}
|
||||
*y += btn_h + flint_px(18);
|
||||
return;
|
||||
@@ -437,13 +448,7 @@ settings_sync_account_draw_config(InbeApp *app, int x, int w, int *y)
|
||||
.count = 2
|
||||
});
|
||||
if(clicked == 0) {
|
||||
if(sync_account_create(&account)) {
|
||||
has_account = 1;
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
settings_sync_open_alias_modal(app, 1);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
has_account = settings_sync_create_account(app, &account);
|
||||
} else if(clicked == 1) {
|
||||
if(!settings_start_sync_key_import(app))
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_import_failed"));
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "settings_ui.h"
|
||||
|
||||
#include "flint_locale.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
static FlintUIParagraph
|
||||
settings_ui_label_paragraph(const char *label, int w)
|
||||
{
|
||||
return (FlintUIParagraph){
|
||||
.text = label,
|
||||
.width = w
|
||||
};
|
||||
}
|
||||
|
||||
int
|
||||
settings_ui_toggle_row_height(const char *label, int w)
|
||||
{
|
||||
int label_h;
|
||||
int row_h;
|
||||
|
||||
if(w <= 0)
|
||||
w = flint_px(160);
|
||||
|
||||
label_h = flint_ui_paragraph_height(settings_ui_label_paragraph(label, w));
|
||||
row_h = label_h + flint_px(8) + flint_px(30) + flint_px(22);
|
||||
if(row_h < flint_px(76))
|
||||
row_h = flint_px(76);
|
||||
return row_h;
|
||||
}
|
||||
|
||||
int
|
||||
settings_ui_draw_toggle_row(int x, int w, int *y, const char *label, int *value)
|
||||
{
|
||||
int label_y;
|
||||
int label_h;
|
||||
int row_h;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
if(y == NULL)
|
||||
return 0;
|
||||
|
||||
row_h = settings_ui_toggle_row_height(label, w);
|
||||
label_y = *y;
|
||||
flint_ui_paragraph_draw(settings_ui_label_paragraph(label, w), x, &label_y);
|
||||
label_h = label_y - *y;
|
||||
|
||||
if(ui_draw_toggle_switch(x, *y + label_h + flint_px(8), toggle_w, toggle_h,
|
||||
value, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
*y += row_h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*y += row_h;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef INBE_SETTINGS_UI_H
|
||||
#define INBE_SETTINGS_UI_H
|
||||
|
||||
int settings_ui_toggle_row_height(const char *label, int w);
|
||||
int settings_ui_draw_toggle_row(int x, int w, int *y, const char *label, int *value);
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -25,7 +25,7 @@ make_user_id(char *out, size_t out_size)
|
||||
snprintf(out, out_size, "local-%lld-%u", now_seconds(), r);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
storage_join_path(char *out, size_t out_size, const char *root, const char *name)
|
||||
{
|
||||
size_t root_len;
|
||||
|
||||
@@ -22,6 +22,7 @@ extern StorageState g_storage;
|
||||
|
||||
long long now_seconds(void);
|
||||
int bind_text(sqlite3_stmt *stmt, int index, const char *text);
|
||||
int storage_join_path(char *out, size_t out_size, const char *root, const char *name);
|
||||
int path_exists(const char *path);
|
||||
int ensure_dir_local(const char *path);
|
||||
int exec_sql(const char *sql);
|
||||
@@ -38,6 +39,10 @@ void set_meta_int64(const char *key, long long value);
|
||||
|
||||
void storage_schedule_persist(void);
|
||||
void storage_enqueue_all_sync_state(void);
|
||||
int storage_enqueue_sync_habit(const char *habit_id);
|
||||
int storage_enqueue_sync_habit_day(const char *habit_id, int local_date);
|
||||
int storage_enqueue_sync_session(const char *session_id);
|
||||
int storage_has_sync_account(void);
|
||||
int storage_materialize_session_habit_days(void);
|
||||
int storage_sync_review_write_json(const char *json);
|
||||
void storage_sync_review_delete_json(void);
|
||||
|
||||
+3
-20
@@ -465,24 +465,6 @@ read_file_heap(const char *path, size_t *out_size)
|
||||
return buf;
|
||||
}
|
||||
|
||||
static int
|
||||
make_temp_path(char *out, size_t out_size, const char *name)
|
||||
{
|
||||
size_t root_len;
|
||||
size_t name_len;
|
||||
|
||||
if(out == NULL || out_size == 0 || name == NULL || g_storage.root[0] == '\0')
|
||||
return 0;
|
||||
root_len = strlen(g_storage.root);
|
||||
name_len = strlen(name);
|
||||
if(root_len + 1 + name_len + 1 > out_size)
|
||||
return 0;
|
||||
memcpy(out, g_storage.root, root_len);
|
||||
out[root_len] = '/';
|
||||
memcpy(out + root_len + 1, name, name_len + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char **paths;
|
||||
int count;
|
||||
@@ -1039,7 +1021,7 @@ storage_import_zip_ex(const char *path, InbeStorageImportMode mode)
|
||||
char temp_path[INBE_STORAGE_PATH_SIZE];
|
||||
FILE *fp;
|
||||
db_bytes = mz_zip_reader_extract_file_to_heap(&archive, "inbe-data/inbe.db", &db_size, 0);
|
||||
if(!make_temp_path(temp_path, sizeof(temp_path), "import-inbe.db")) {
|
||||
if(!storage_join_path(temp_path, sizeof(temp_path), g_storage.root, "import-inbe.db")) {
|
||||
TraceLog(LOG_ERROR, "DATA: import temp path is too long");
|
||||
free(db_bytes);
|
||||
mz_zip_reader_end(&archive);
|
||||
@@ -1091,7 +1073,8 @@ storage_inspect_import(const char *path, InbeStorageImportInfo *info)
|
||||
char temp_path[INBE_STORAGE_PATH_SIZE];
|
||||
FILE *fp;
|
||||
db_bytes = mz_zip_reader_extract_file_to_heap(&archive, "inbe-data/inbe.db", &db_size, 0);
|
||||
if(!make_temp_path(temp_path, sizeof(temp_path), "import-inspect-inbe.db")) {
|
||||
if(!storage_join_path(temp_path, sizeof(temp_path), g_storage.root,
|
||||
"import-inspect-inbe.db")) {
|
||||
free(db_bytes);
|
||||
mz_zip_reader_end(&archive);
|
||||
return 0;
|
||||
|
||||
+31
-600
@@ -1,6 +1,5 @@
|
||||
#include "storage.h"
|
||||
|
||||
#include "breath_engine.h"
|
||||
#include "db.h"
|
||||
#include "screens/habits_screen.h"
|
||||
|
||||
@@ -10,7 +9,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
@@ -29,6 +27,8 @@ storage_has_orphan_habit_days(void);
|
||||
static int
|
||||
storage_json_array_count(const char *json, const char *path);
|
||||
static int
|
||||
storage_apply_remote_full_snapshot(const char *response_json);
|
||||
static int
|
||||
storage_clear_local_sync_data(void);
|
||||
static int
|
||||
storage_json_valid(const char *json);
|
||||
@@ -270,19 +270,19 @@ storage_enqueue_sync_entity(const char *entity_type, const char *entity_id, int
|
||||
return rc == SQLITE_DONE;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
storage_enqueue_sync_habit(const char *habit_id)
|
||||
{
|
||||
return storage_enqueue_sync_entity("habit", habit_id, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
storage_enqueue_sync_habit_day(const char *habit_id, int local_date)
|
||||
{
|
||||
return storage_enqueue_sync_entity("habit_day", habit_id, local_date);
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
storage_enqueue_sync_session(const char *session_id)
|
||||
{
|
||||
return storage_enqueue_sync_entity("session", session_id, 0);
|
||||
@@ -318,39 +318,6 @@ storage_enqueue_all_sync_state(void)
|
||||
exec_sql("COMMIT");
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
hash_rounds(const int *round_times, int round_count)
|
||||
{
|
||||
unsigned int h = 2166136261u;
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
unsigned int v = (unsigned int)round_times[i];
|
||||
h ^= v & 0xffu;
|
||||
h *= 16777619u;
|
||||
h ^= (v >> 8) & 0xffu;
|
||||
h *= 16777619u;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static void
|
||||
make_session_id(long long started_at, const int *round_times, int round_count, char *out,
|
||||
size_t out_size)
|
||||
{
|
||||
snprintf(out, out_size, "s-%lld-%08x", started_at, hash_rounds(round_times, round_count));
|
||||
}
|
||||
|
||||
static int
|
||||
parse_db_id(const char *path_or_id, char *out, size_t out_size)
|
||||
{
|
||||
if(path_or_id == NULL || path_or_id[0] == '\0')
|
||||
return 0;
|
||||
if(strncmp(path_or_id, "db:", 3) == 0)
|
||||
snprintf(out, out_size, "%s", path_or_id + 3);
|
||||
else
|
||||
snprintf(out, out_size, "%s", path_or_id);
|
||||
return out[0] != '\0';
|
||||
}
|
||||
|
||||
void
|
||||
storage_reset_sync_state(void)
|
||||
{
|
||||
@@ -849,319 +816,6 @@ storage_materialize_session_habit_days(void)
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
insert_session_at_ex(long long started_at, int local_date, const int *round_times, int round_count,
|
||||
int topic, int activity, const char *source, char *out_id, size_t out_id_size)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int rc;
|
||||
int inserted;
|
||||
unsigned int rhash;
|
||||
|
||||
if(g_storage.db == NULL || round_times == NULL || round_count <= 0 || round_count > MaxRounds)
|
||||
return 0;
|
||||
|
||||
rhash = hash_rounds(round_times, round_count);
|
||||
make_session_id(started_at, round_times, round_count, id, sizeof(id));
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR IGNORE INTO "
|
||||
"sessions(id,user_id,started_at,local_date,topic,"
|
||||
"activity,source,imported_at,rounds_hash,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
sqlite3_bind_int64(stmt, 3, started_at);
|
||||
sqlite3_bind_int(stmt, 4, local_date);
|
||||
sqlite3_bind_int(stmt, 5, topic);
|
||||
sqlite3_bind_int(stmt, 6, activity);
|
||||
bind_text(stmt, 7, source != NULL ? source : "app");
|
||||
sqlite3_bind_int64(stmt, 8, now_seconds());
|
||||
sqlite3_bind_int64(stmt, 9, (sqlite3_int64)rhash);
|
||||
sqlite3_bind_int64(stmt, 10, now_seconds());
|
||||
rc = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
if(rc != SQLITE_DONE)
|
||||
return 0;
|
||||
|
||||
inserted = sqlite3_changes(g_storage.db) > 0;
|
||||
if(inserted) {
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO "
|
||||
"session_rounds(session_id,round_index,seconds) VALUES(?1,?2,?3)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int(stmt, 2, i);
|
||||
sqlite3_bind_int(stmt, 3, round_times[i]);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
storage_enqueue_sync_session(id);
|
||||
}
|
||||
|
||||
if(out_id != NULL && out_id_size > 0)
|
||||
snprintf(out_id, out_id_size, "db:%s", id);
|
||||
if(inserted)
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session_for_activity(const int *round_times, int round_count, int topic, int activity,
|
||||
char *out_id, size_t out_id_size)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm = localtime(&now);
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
int local_date;
|
||||
|
||||
if(tm == NULL)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count && i < MaxRounds; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return 0;
|
||||
local_date = (tm->tm_year + 1900) * 10000 + (tm->tm_mon + 1) * 100 + tm->tm_mday;
|
||||
return insert_session_at_ex((long long)now, local_date, saved, saved_count, topic, activity,
|
||||
"app", out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session_at_for_activity(int local_date, int hour, int minute, int second,
|
||||
const int *round_times, int round_count, int topic,
|
||||
int activity, char *out_id, size_t out_id_size)
|
||||
{
|
||||
struct tm tm;
|
||||
time_t started_at;
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
|
||||
if(local_date <= 0)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count && i < MaxRounds; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return 0;
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_year = local_date / 10000 - 1900;
|
||||
tm.tm_mon = (local_date / 100) % 100 - 1;
|
||||
tm.tm_mday = local_date % 100;
|
||||
tm.tm_hour = hour;
|
||||
tm.tm_min = minute;
|
||||
tm.tm_sec = second;
|
||||
tm.tm_isdst = -1;
|
||||
started_at = mktime(&tm);
|
||||
if(started_at == (time_t)-1)
|
||||
return 0;
|
||||
|
||||
return insert_session_at_ex((long long)started_at, local_date, saved, saved_count, topic,
|
||||
activity, "app", out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session(const int *round_times, int round_count, char *out_id, size_t out_id_size)
|
||||
{
|
||||
return storage_save_session_for_activity(round_times, round_count, 0, 0, out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_load_session(const char *path_or_id, int *round_times, int max_rounds, int *year,
|
||||
int *month, int *day, int *hour, int *minute, int *second)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int count = 0;
|
||||
long long started_at = 0;
|
||||
int local_date = 0;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || round_times == NULL || max_rounds <= 0)
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT started_at,local_date FROM sessions WHERE "
|
||||
"id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
started_at = sqlite3_column_int64(stmt, 0);
|
||||
local_date = sqlite3_column_int(stmt, 1);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
if(started_at == 0)
|
||||
return 0;
|
||||
|
||||
if(year)
|
||||
*year = local_date / 10000;
|
||||
if(month)
|
||||
*month = (local_date / 100) % 100;
|
||||
if(day)
|
||||
*day = local_date % 100;
|
||||
{
|
||||
time_t t = (time_t)started_at;
|
||||
struct tm *tm = localtime(&t);
|
||||
if(tm != NULL) {
|
||||
if(hour)
|
||||
*hour = tm->tm_hour;
|
||||
if(minute)
|
||||
*minute = tm->tm_min;
|
||||
if(second)
|
||||
*second = tm->tm_sec;
|
||||
}
|
||||
}
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT seconds FROM session_rounds WHERE "
|
||||
"session_id=?1 ORDER BY round_index",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
while(count < max_rounds && sqlite3_step(stmt) == SQLITE_ROW)
|
||||
round_times[count++] = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
storage_replace_session(const char *path_or_id, const int *round_times, int round_count)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || round_times == NULL || round_count < 0 ||
|
||||
round_count > MaxRounds)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return storage_delete_session(path_or_id);
|
||||
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
if(sqlite3_prepare_v2(g_storage.db, "DELETE FROM session_rounds WHERE session_id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
for(int i = 0; i < saved_count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO session_rounds(session_id,round_index,seconds) "
|
||||
"VALUES(?1,?2,?3)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int(stmt, 2, i);
|
||||
sqlite3_bind_int(stmt, 3, saved[i]);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET rounds_hash=?2,updated_at=?3 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)hash_rounds(saved, saved_count));
|
||||
sqlite3_bind_int64(stmt, 3, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
exec_sql("COMMIT");
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
storage_rename_session_time(const char *path_or_id, int hour, int minute)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
long long started_at = 0;
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || hour < 0 || hour > 23 || minute < 0 ||
|
||||
minute > 59)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT started_at FROM sessions WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
started_at = sqlite3_column_int64(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
if(started_at == 0)
|
||||
return 0;
|
||||
t = (time_t)started_at;
|
||||
tm = localtime(&t);
|
||||
if(tm == NULL)
|
||||
return 0;
|
||||
tm->tm_hour = hour;
|
||||
tm->tm_min = minute;
|
||||
t = mktime(tm);
|
||||
if(t == (time_t)-1)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET started_at=?2,updated_at=?3 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)t);
|
||||
sqlite3_bind_int64(stmt, 3, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
storage_delete_session(const char *path_or_id)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET deleted_at=?2,updated_at=?2 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_habits_json(JsonBuilder *json, long long through_seq)
|
||||
{
|
||||
@@ -1736,7 +1390,7 @@ storage_has_orphan_habit_days(void)
|
||||
return found;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
storage_has_sync_account(void)
|
||||
{
|
||||
const char *public_id = storage_get_setting_text(STORAGE_SYNC_PUBLIC_ID_KEY);
|
||||
@@ -2112,20 +1766,9 @@ storage_apply_sync_response_json(const char *response_json)
|
||||
storage_set_setting_text(STORAGE_SYNC_ACCOUNT_ALIAS_KEY, account_alias);
|
||||
if(storage_json_extract_int64(response_json, "$.full_snapshot_required", 0) != 0 &&
|
||||
get_meta_int64(STORAGE_SYNC_APPLY_REVIEW_KEY, 0) == 0) {
|
||||
if(!storage_sync_review_json_has_visible_diff(response_json)) {
|
||||
char *copy = strdup(response_json);
|
||||
int ok;
|
||||
if(copy == NULL)
|
||||
return 0;
|
||||
if(!storage_clear_local_sync_data()) {
|
||||
free(copy);
|
||||
return 0;
|
||||
}
|
||||
set_meta_int64(STORAGE_SYNC_APPLY_REVIEW_KEY, 1);
|
||||
ok = storage_apply_sync_response_json(copy);
|
||||
free(copy);
|
||||
return ok;
|
||||
}
|
||||
if(!storage_has_any() ||
|
||||
storage_sync_review_json_should_auto_apply_remote(response_json))
|
||||
return storage_apply_remote_full_snapshot(response_json);
|
||||
if(!storage_sync_review_write_json(response_json))
|
||||
return 0;
|
||||
set_meta(STORAGE_SYNC_PENDING_REVIEW_KEY, "1");
|
||||
@@ -2185,6 +1828,27 @@ storage_apply_sync_response_json(const char *response_json)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
storage_apply_remote_full_snapshot(const char *response_json)
|
||||
{
|
||||
char *copy;
|
||||
int ok;
|
||||
|
||||
if(response_json == NULL)
|
||||
return 0;
|
||||
copy = strdup(response_json);
|
||||
if(copy == NULL)
|
||||
return 0;
|
||||
if(!storage_clear_local_sync_data()) {
|
||||
free(copy);
|
||||
return 0;
|
||||
}
|
||||
set_meta_int64(STORAGE_SYNC_APPLY_REVIEW_KEY, 1);
|
||||
ok = storage_apply_sync_response_json(copy);
|
||||
free(copy);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int
|
||||
storage_clear_local_sync_data(void)
|
||||
{
|
||||
@@ -2276,84 +1940,6 @@ fail:
|
||||
exec_sql("ROLLBACK");
|
||||
}
|
||||
|
||||
void
|
||||
storage_list_session_records(InbeStorageSessionRecordCallback callback, void *user)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
if(callback == NULL || g_storage.db == NULL)
|
||||
return;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,started_at,local_date,topic,activity FROM sessions WHERE "
|
||||
"deleted_at=0 ORDER BY started_at DESC LIMIT 48",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return;
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
char dbid[INBE_STORAGE_ID_SIZE + 4];
|
||||
int rounds[MaxRounds];
|
||||
int count = 0;
|
||||
const char *id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
long long started_at = sqlite3_column_int64(stmt, 1);
|
||||
int local_date = sqlite3_column_int(stmt, 2);
|
||||
int topic = sqlite3_column_int(stmt, 3);
|
||||
int activity = sqlite3_column_int(stmt, 4);
|
||||
int y = local_date / 10000;
|
||||
int m = (local_date / 100) % 100;
|
||||
int d = local_date % 100;
|
||||
int hh = 0, mm = 0, ss = 0;
|
||||
time_t t = (time_t)started_at;
|
||||
struct tm *tm = localtime(&t);
|
||||
if(tm != NULL) {
|
||||
hh = tm->tm_hour;
|
||||
mm = tm->tm_min;
|
||||
ss = tm->tm_sec;
|
||||
}
|
||||
snprintf(dbid, sizeof(dbid), "db:%s", id != NULL ? id : "");
|
||||
count = storage_load_session(dbid, rounds, MaxRounds, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
if(count > 0)
|
||||
callback(dbid, y, m, d, hh, mm, ss, topic, activity, rounds, count, user);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
int
|
||||
storage_has_any(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = storage_session_count();
|
||||
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
count = storage_habit_count();
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT COUNT(*) FROM habit_days WHERE completed!=0 OR count>0", -1,
|
||||
&stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
int
|
||||
storage_session_count(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = 0;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT COUNT(*) FROM sessions WHERE deleted_at=0", -1,
|
||||
&stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
storage_profile_day_offset(int local_date, int today_date)
|
||||
{
|
||||
@@ -2389,7 +1975,6 @@ storage_profile_activity_stats(int activity, int today_date,
|
||||
int seen[371] = {0};
|
||||
int streak = 0;
|
||||
long avg_value = 0;
|
||||
int mask = 1 << activity;
|
||||
|
||||
if(streak_out != NULL)
|
||||
*streak_out = 0;
|
||||
@@ -2401,19 +1986,11 @@ storage_profile_activity_stats(int activity, int today_date,
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT local_date FROM sessions "
|
||||
"WHERE user_id=?1 AND deleted_at=0 AND activity=?2 "
|
||||
" AND local_date>0 "
|
||||
"UNION "
|
||||
"SELECT hd.local_date "
|
||||
"FROM habit_days hd JOIN habits h ON h.id=hd.habit_id "
|
||||
"WHERE h.user_id=?1 AND h.deleted_at=0 "
|
||||
" AND h.sync_mode=?3 AND (h.sync_activity & ?4)<>0 "
|
||||
" AND (hd.completed!=0 OR hd.count>0)",
|
||||
" AND local_date>0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
sqlite3_bind_int(stmt, 2, activity);
|
||||
sqlite3_bind_int(stmt, 3, INBE_HABIT_SYNC_ACTIVITIES);
|
||||
sqlite3_bind_int(stmt, 4, mask);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int offset = storage_profile_day_offset(sqlite3_column_int(stmt, 0), today_date);
|
||||
if(offset >= 0 && offset <= 370)
|
||||
@@ -2464,152 +2041,6 @@ storage_profile_activity_stats(int activity, int today_date,
|
||||
return 1;
|
||||
}
|
||||
|
||||
long long
|
||||
storage_total_size(void)
|
||||
{
|
||||
struct stat st;
|
||||
if(!storage_has_any())
|
||||
return 0;
|
||||
if(g_storage.db_path[0] != '\0' && stat(g_storage.db_path, &st) == 0)
|
||||
return (long long)st.st_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long
|
||||
storage_delete_all_sessions(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = storage_session_count();
|
||||
int habit_day_count = 0;
|
||||
int habit_count = storage_habit_count();
|
||||
long long deleted_at = now_seconds();
|
||||
int changed = 0;
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT COUNT(*) FROM habit_days WHERE completed!=0 OR count>0", -1,
|
||||
&stmt, NULL) == SQLITE_OK) {
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
habit_day_count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if(count <= 0 && habit_day_count <= 0 && habit_count <= 0)
|
||||
return 0;
|
||||
|
||||
if(!storage_has_sync_account()) {
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
return 0;
|
||||
if(!exec_sql("DELETE FROM session_rounds WHERE session_id IN "
|
||||
"(SELECT id FROM sessions WHERE user_id=(SELECT id FROM users "
|
||||
"LIMIT 1));"
|
||||
"DELETE FROM sessions WHERE user_id=(SELECT id FROM users LIMIT 1);"
|
||||
"DELETE FROM habit_days WHERE habit_id IN "
|
||||
"(SELECT id FROM habits WHERE user_id=(SELECT id FROM users LIMIT "
|
||||
"1));"
|
||||
"DELETE FROM habits WHERE user_id=(SELECT id FROM users LIMIT 1);"
|
||||
"DELETE FROM sync_outbox;")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
set_meta_int64("sync_last_server_version", 0);
|
||||
set_meta_int64("sync_last_upload_at", 0);
|
||||
set_meta_int64("sync_full_upload_done", 0);
|
||||
set_meta_int64(STORAGE_SYNC_BACKFILL_KEY, 0);
|
||||
set_meta_int64(STORAGE_SYNC_HABIT_NAME_REPAIR_KEY, 0);
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
storage_schedule_persist();
|
||||
return count + habit_day_count + habit_count;
|
||||
}
|
||||
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT id FROM sessions WHERE user_id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_session((const char *)sqlite3_column_text(stmt, 0));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT habit_id,local_date FROM habit_days "
|
||||
"WHERE habit_id IN (SELECT id FROM habits WHERE user_id=?1) "
|
||||
"AND (completed!=0 OR count>0 OR session_count>0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_habit_day((const char *)sqlite3_column_text(stmt, 0),
|
||||
sqlite3_column_int(stmt, 1));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT id FROM habits WHERE user_id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_habit((const char *)sqlite3_column_text(stmt, 0));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET deleted_at=?1,updated_at=?1 "
|
||||
"WHERE user_id=?2 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE habit_days SET "
|
||||
"completed=0,count=0,session_count=0,updated_at=?1 "
|
||||
"WHERE habit_id IN (SELECT id FROM habits WHERE user_id=?2) "
|
||||
" AND (completed!=0 OR count>0 OR session_count>0)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE habits SET deleted_at=?1,updated_at=?1 "
|
||||
"WHERE user_id=?2 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
storage_schedule_persist();
|
||||
return changed > 0 ? count + habit_day_count + habit_count : 0;
|
||||
|
||||
fail:
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
storage_habits_empty(void)
|
||||
|
||||
@@ -89,6 +89,7 @@ int storage_sync_review_details(char **local_out, char **remote_out);
|
||||
int storage_sync_review_diff(char **diff_out);
|
||||
int storage_sync_review_has_visible_diff(void);
|
||||
int storage_sync_review_json_has_visible_diff(const char *json);
|
||||
int storage_sync_review_json_should_auto_apply_remote(const char *json);
|
||||
int storage_sync_review_clear_if_no_visible_diff(void);
|
||||
int storage_sync_review_apply_remote_if_local_empty(void);
|
||||
int storage_apply_pending_sync_review(int use_remote);
|
||||
|
||||
@@ -0,0 +1,581 @@
|
||||
#include "storage.h"
|
||||
|
||||
#include "breath_engine.h"
|
||||
#include "db.h"
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
static unsigned int
|
||||
hash_rounds(const int *round_times, int round_count)
|
||||
{
|
||||
unsigned int h = 2166136261u;
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
unsigned int v = (unsigned int)round_times[i];
|
||||
h ^= v & 0xffu;
|
||||
h *= 16777619u;
|
||||
h ^= (v >> 8) & 0xffu;
|
||||
h *= 16777619u;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
static void
|
||||
make_session_id(long long started_at, const int *round_times, int round_count, char *out,
|
||||
size_t out_size)
|
||||
{
|
||||
snprintf(out, out_size, "s-%lld-%08x", started_at, hash_rounds(round_times, round_count));
|
||||
}
|
||||
|
||||
static int
|
||||
parse_db_id(const char *path_or_id, char *out, size_t out_size)
|
||||
{
|
||||
if(path_or_id == NULL || path_or_id[0] == '\0')
|
||||
return 0;
|
||||
if(strncmp(path_or_id, "db:", 3) == 0)
|
||||
snprintf(out, out_size, "%s", path_or_id + 3);
|
||||
else
|
||||
snprintf(out, out_size, "%s", path_or_id);
|
||||
return out[0] != '\0';
|
||||
}
|
||||
|
||||
int
|
||||
insert_session_at_ex(long long started_at, int local_date, const int *round_times, int round_count,
|
||||
int topic, int activity, const char *source, char *out_id, size_t out_id_size)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int rc;
|
||||
int inserted;
|
||||
unsigned int rhash;
|
||||
|
||||
if(g_storage.db == NULL || round_times == NULL || round_count <= 0 || round_count > MaxRounds)
|
||||
return 0;
|
||||
|
||||
rhash = hash_rounds(round_times, round_count);
|
||||
make_session_id(started_at, round_times, round_count, id, sizeof(id));
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR IGNORE INTO "
|
||||
"sessions(id,user_id,started_at,local_date,topic,"
|
||||
"activity,source,imported_at,rounds_hash,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
sqlite3_bind_int64(stmt, 3, started_at);
|
||||
sqlite3_bind_int(stmt, 4, local_date);
|
||||
sqlite3_bind_int(stmt, 5, topic);
|
||||
sqlite3_bind_int(stmt, 6, activity);
|
||||
bind_text(stmt, 7, source != NULL ? source : "app");
|
||||
sqlite3_bind_int64(stmt, 8, now_seconds());
|
||||
sqlite3_bind_int64(stmt, 9, (sqlite3_int64)rhash);
|
||||
sqlite3_bind_int64(stmt, 10, now_seconds());
|
||||
rc = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
if(rc != SQLITE_DONE)
|
||||
return 0;
|
||||
|
||||
inserted = sqlite3_changes(g_storage.db) > 0;
|
||||
if(inserted) {
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO "
|
||||
"session_rounds(session_id,round_index,seconds) VALUES(?1,?2,?3)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int(stmt, 2, i);
|
||||
sqlite3_bind_int(stmt, 3, round_times[i]);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
storage_enqueue_sync_session(id);
|
||||
}
|
||||
|
||||
if(out_id != NULL && out_id_size > 0)
|
||||
snprintf(out_id, out_id_size, "db:%s", id);
|
||||
if(inserted)
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session_for_activity(const int *round_times, int round_count, int topic, int activity,
|
||||
char *out_id, size_t out_id_size)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
struct tm *tm = localtime(&now);
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
int local_date;
|
||||
|
||||
if(tm == NULL)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count && i < MaxRounds; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return 0;
|
||||
local_date = (tm->tm_year + 1900) * 10000 + (tm->tm_mon + 1) * 100 + tm->tm_mday;
|
||||
return insert_session_at_ex((long long)now, local_date, saved, saved_count, topic, activity,
|
||||
"app", out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session_at_for_activity(int local_date, int hour, int minute, int second,
|
||||
const int *round_times, int round_count, int topic,
|
||||
int activity, char *out_id, size_t out_id_size)
|
||||
{
|
||||
struct tm tm;
|
||||
time_t started_at;
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
|
||||
if(local_date <= 0)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count && i < MaxRounds; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return 0;
|
||||
|
||||
memset(&tm, 0, sizeof(tm));
|
||||
tm.tm_year = local_date / 10000 - 1900;
|
||||
tm.tm_mon = (local_date / 100) % 100 - 1;
|
||||
tm.tm_mday = local_date % 100;
|
||||
tm.tm_hour = hour;
|
||||
tm.tm_min = minute;
|
||||
tm.tm_sec = second;
|
||||
tm.tm_isdst = -1;
|
||||
started_at = mktime(&tm);
|
||||
if(started_at == (time_t)-1)
|
||||
return 0;
|
||||
|
||||
return insert_session_at_ex((long long)started_at, local_date, saved, saved_count, topic,
|
||||
activity, "app", out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_save_session(const int *round_times, int round_count, char *out_id, size_t out_id_size)
|
||||
{
|
||||
return storage_save_session_for_activity(round_times, round_count, 0, 0, out_id, out_id_size);
|
||||
}
|
||||
|
||||
int
|
||||
storage_load_session(const char *path_or_id, int *round_times, int max_rounds, int *year,
|
||||
int *month, int *day, int *hour, int *minute, int *second)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int count = 0;
|
||||
long long started_at = 0;
|
||||
int local_date = 0;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || round_times == NULL || max_rounds <= 0)
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT started_at,local_date FROM sessions WHERE "
|
||||
"id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
started_at = sqlite3_column_int64(stmt, 0);
|
||||
local_date = sqlite3_column_int(stmt, 1);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
if(started_at == 0)
|
||||
return 0;
|
||||
|
||||
if(year)
|
||||
*year = local_date / 10000;
|
||||
if(month)
|
||||
*month = (local_date / 100) % 100;
|
||||
if(day)
|
||||
*day = local_date % 100;
|
||||
{
|
||||
time_t t = (time_t)started_at;
|
||||
struct tm *tm = localtime(&t);
|
||||
if(tm != NULL) {
|
||||
if(hour)
|
||||
*hour = tm->tm_hour;
|
||||
if(minute)
|
||||
*minute = tm->tm_min;
|
||||
if(second)
|
||||
*second = tm->tm_sec;
|
||||
}
|
||||
}
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT seconds FROM session_rounds WHERE "
|
||||
"session_id=?1 ORDER BY round_index",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
while(count < max_rounds && sqlite3_step(stmt) == SQLITE_ROW)
|
||||
round_times[count++] = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
storage_replace_session(const char *path_or_id, const int *round_times, int round_count)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
int saved[MaxRounds];
|
||||
int saved_count = 0;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || round_times == NULL || round_count < 0 ||
|
||||
round_count > MaxRounds)
|
||||
return 0;
|
||||
for(int i = 0; i < round_count; i++) {
|
||||
if(round_times[i] > 0)
|
||||
saved[saved_count++] = round_times[i];
|
||||
}
|
||||
if(saved_count <= 0)
|
||||
return storage_delete_session(path_or_id);
|
||||
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
if(sqlite3_prepare_v2(g_storage.db, "DELETE FROM session_rounds WHERE session_id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
for(int i = 0; i < saved_count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO session_rounds(session_id,round_index,seconds) "
|
||||
"VALUES(?1,?2,?3)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int(stmt, 2, i);
|
||||
sqlite3_bind_int(stmt, 3, saved[i]);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET rounds_hash=?2,updated_at=?3 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)hash_rounds(saved, saved_count));
|
||||
sqlite3_bind_int64(stmt, 3, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
exec_sql("COMMIT");
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
storage_rename_session_time(const char *path_or_id, int hour, int minute)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
long long started_at = 0;
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)) || hour < 0 || hour > 23 || minute < 0 ||
|
||||
minute > 59)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT started_at FROM sessions WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
started_at = sqlite3_column_int64(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
if(started_at == 0)
|
||||
return 0;
|
||||
t = (time_t)started_at;
|
||||
tm = localtime(&t);
|
||||
if(tm == NULL)
|
||||
return 0;
|
||||
tm->tm_hour = hour;
|
||||
tm->tm_min = minute;
|
||||
t = mktime(tm);
|
||||
if(t == (time_t)-1)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET started_at=?2,updated_at=?3 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, (sqlite3_int64)t);
|
||||
sqlite3_bind_int64(stmt, 3, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
storage_delete_session(const char *path_or_id)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char id[INBE_STORAGE_ID_SIZE];
|
||||
if(!parse_db_id(path_or_id, id, sizeof(id)))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET deleted_at=?2,updated_at=?2 WHERE id=?1", -1, &stmt,
|
||||
NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
bind_text(stmt, 1, id);
|
||||
sqlite3_bind_int64(stmt, 2, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
storage_enqueue_sync_session(id);
|
||||
storage_materialize_session_habit_days();
|
||||
storage_schedule_persist();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
storage_list_session_records(InbeStorageSessionRecordCallback callback, void *user)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
if(callback == NULL || g_storage.db == NULL)
|
||||
return;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,started_at,local_date,topic,activity FROM sessions WHERE "
|
||||
"deleted_at=0 ORDER BY started_at DESC LIMIT 48",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return;
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
char dbid[INBE_STORAGE_ID_SIZE + 4];
|
||||
int rounds[MaxRounds];
|
||||
int count = 0;
|
||||
const char *id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
long long started_at = sqlite3_column_int64(stmt, 1);
|
||||
int local_date = sqlite3_column_int(stmt, 2);
|
||||
int topic = sqlite3_column_int(stmt, 3);
|
||||
int activity = sqlite3_column_int(stmt, 4);
|
||||
int y = local_date / 10000;
|
||||
int m = (local_date / 100) % 100;
|
||||
int d = local_date % 100;
|
||||
int hh = 0, mm = 0, ss = 0;
|
||||
time_t t = (time_t)started_at;
|
||||
struct tm *tm = localtime(&t);
|
||||
if(tm != NULL) {
|
||||
hh = tm->tm_hour;
|
||||
mm = tm->tm_min;
|
||||
ss = tm->tm_sec;
|
||||
}
|
||||
snprintf(dbid, sizeof(dbid), "db:%s", id != NULL ? id : "");
|
||||
count = storage_load_session(dbid, rounds, MaxRounds, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
if(count > 0)
|
||||
callback(dbid, y, m, d, hh, mm, ss, topic, activity, rounds, count, user);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
int
|
||||
storage_has_any(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = storage_session_count();
|
||||
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
count = storage_habit_count();
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT COUNT(*) FROM habit_days WHERE completed!=0 OR count>0", -1,
|
||||
&stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
int
|
||||
storage_session_count(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = 0;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT COUNT(*) FROM sessions WHERE deleted_at=0", -1,
|
||||
&stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
return count;
|
||||
}
|
||||
|
||||
long long
|
||||
storage_total_size(void)
|
||||
{
|
||||
struct stat st;
|
||||
if(!storage_has_any())
|
||||
return 0;
|
||||
if(g_storage.db_path[0] != '\0' && stat(g_storage.db_path, &st) == 0)
|
||||
return (long long)st.st_size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long long
|
||||
storage_delete_all_sessions(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = storage_session_count();
|
||||
int habit_day_count = 0;
|
||||
int habit_count = storage_habit_count();
|
||||
long long deleted_at = now_seconds();
|
||||
int changed = 0;
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT COUNT(*) FROM habit_days WHERE completed!=0 OR count>0", -1,
|
||||
&stmt, NULL) == SQLITE_OK) {
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
habit_day_count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if(count <= 0 && habit_day_count <= 0 && habit_count <= 0)
|
||||
return 0;
|
||||
|
||||
if(!storage_has_sync_account()) {
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
return 0;
|
||||
if(!exec_sql("DELETE FROM session_rounds WHERE session_id IN "
|
||||
"(SELECT id FROM sessions WHERE user_id=(SELECT id FROM users "
|
||||
"LIMIT 1));"
|
||||
"DELETE FROM sessions WHERE user_id=(SELECT id FROM users LIMIT 1);"
|
||||
"DELETE FROM habit_days WHERE habit_id IN "
|
||||
"(SELECT id FROM habits WHERE user_id=(SELECT id FROM users LIMIT "
|
||||
"1));"
|
||||
"DELETE FROM habits WHERE user_id=(SELECT id FROM users LIMIT 1);"
|
||||
"DELETE FROM sync_outbox;")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
set_meta_int64("sync_last_server_version", 0);
|
||||
set_meta_int64("sync_last_upload_at", 0);
|
||||
set_meta_int64("sync_full_upload_done", 0);
|
||||
set_meta_int64("sync_backfill_v2_done", 0);
|
||||
set_meta_int64("sync_habit_name_repair_v1_done", 0);
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
storage_schedule_persist();
|
||||
return count + habit_day_count + habit_count;
|
||||
}
|
||||
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT id FROM sessions WHERE user_id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_session((const char *)sqlite3_column_text(stmt, 0));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT habit_id,local_date FROM habit_days "
|
||||
"WHERE habit_id IN (SELECT id FROM habits WHERE user_id=?1) "
|
||||
"AND (completed!=0 OR count>0 OR session_count>0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_habit_day((const char *)sqlite3_column_text(stmt, 0),
|
||||
sqlite3_column_int(stmt, 1));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT id FROM habits WHERE user_id=?1 AND deleted_at=0",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
storage_enqueue_sync_habit((const char *)sqlite3_column_text(stmt, 0));
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
}
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE sessions SET deleted_at=?1,updated_at=?1 "
|
||||
"WHERE user_id=?2 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE habit_days SET "
|
||||
"completed=0,count=0,session_count=0,updated_at=?1 "
|
||||
"WHERE habit_id IN (SELECT id FROM habits WHERE user_id=?2) "
|
||||
" AND (completed!=0 OR count>0 OR session_count>0)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"UPDATE habits SET deleted_at=?1,updated_at=?1 "
|
||||
"WHERE user_id=?2 AND deleted_at=0",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
goto fail;
|
||||
sqlite3_bind_int64(stmt, 1, deleted_at);
|
||||
bind_text(stmt, 2, g_storage.user_id);
|
||||
if(sqlite3_step(stmt) != SQLITE_DONE)
|
||||
goto fail;
|
||||
changed += sqlite3_changes(g_storage.db);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
storage_schedule_persist();
|
||||
return changed > 0 ? count + habit_day_count + habit_count : 0;
|
||||
|
||||
fail:
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
+150
-15
@@ -11,6 +11,7 @@
|
||||
#define STORAGE_SYNC_APPLY_REVIEW_KEY "sync_apply_pending_review"
|
||||
#define STORAGE_SYNC_FULL_REPLACE_KEY "sync_full_replace_requested"
|
||||
#define STORAGE_SYNC_LAST_SERVER_HASH_KEY "sync_last_server_state_hash"
|
||||
#define STORAGE_SYNC_AUTO_APPLY_VISIBLE_CHANGE_LIMIT 2
|
||||
|
||||
typedef struct ReviewText {
|
||||
char *data;
|
||||
@@ -23,8 +24,12 @@ static void review_append_local(ReviewText *out);
|
||||
static void review_append_remote(ReviewText *out, const char *json);
|
||||
static void review_append_unique_lines(ReviewText *out, const char *prefix,
|
||||
const char *lines, const char *other);
|
||||
static int review_has_local_activity(void);
|
||||
static int review_has_pending_outbox(void);
|
||||
static int review_pending_outbox_sessions_only(void);
|
||||
static int review_has_unknown_activity(const char *json);
|
||||
static int review_small_session_only_change(const char *diff);
|
||||
static int review_visible_change_count(const char *diff);
|
||||
|
||||
static int
|
||||
review_reserve(ReviewText *text, size_t extra)
|
||||
@@ -92,21 +97,9 @@ review_appendf(ReviewText *text, const char *fmt, ...)
|
||||
static void
|
||||
storage_sync_review_path(char *out, size_t out_size)
|
||||
{
|
||||
const char *name = "sync-review.json";
|
||||
size_t root_len;
|
||||
size_t name_len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
root_len = strlen(g_storage.root);
|
||||
name_len = strlen(name);
|
||||
if(root_len + 1 + name_len + 1 > out_size) {
|
||||
if(!storage_join_path(out, out_size, g_storage.root, "sync-review.json") &&
|
||||
out != NULL && out_size > 0)
|
||||
out[0] = '\0';
|
||||
return;
|
||||
}
|
||||
memcpy(out, g_storage.root, root_len);
|
||||
out[root_len] = '/';
|
||||
memcpy(out + root_len + 1, name, name_len + 1);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -596,7 +589,7 @@ storage_sync_review_apply_remote_if_local_empty(void)
|
||||
{
|
||||
if(!storage_sync_review_pending())
|
||||
return 0;
|
||||
if(storage_has_any())
|
||||
if(review_has_local_activity())
|
||||
return 0;
|
||||
return storage_apply_pending_sync_review(1);
|
||||
}
|
||||
@@ -617,6 +610,59 @@ storage_sync_review_json_has_visible_diff(const char *json)
|
||||
return has_diff;
|
||||
}
|
||||
|
||||
int
|
||||
storage_sync_review_json_should_auto_apply_remote(const char *json)
|
||||
{
|
||||
char *diff = NULL;
|
||||
int result;
|
||||
|
||||
if(review_has_unknown_activity(json))
|
||||
return 0;
|
||||
if(!storage_sync_review_diff_for_json(json, 0, &diff)) {
|
||||
free(diff);
|
||||
return 0;
|
||||
}
|
||||
if(diff == NULL || diff[0] == '\0') {
|
||||
free(diff);
|
||||
return 1;
|
||||
}
|
||||
if(!review_has_local_activity()) {
|
||||
free(diff);
|
||||
return 1;
|
||||
}
|
||||
if(!review_has_pending_outbox()) {
|
||||
free(diff);
|
||||
return 1;
|
||||
}
|
||||
result = review_small_session_only_change(diff);
|
||||
free(diff);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
review_has_local_activity(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int result = 0;
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT EXISTS("
|
||||
" SELECT 1 FROM sessions WHERE deleted_at=0"
|
||||
" UNION ALL"
|
||||
" SELECT 1 FROM habit_days "
|
||||
" WHERE completed!=0 OR count>0 OR session_count>0"
|
||||
" LIMIT 1"
|
||||
")",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 1;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
result = sqlite3_column_int(stmt, 0) != 0;
|
||||
sqlite3_finalize(stmt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
review_has_pending_outbox(void)
|
||||
{
|
||||
@@ -635,6 +681,25 @@ review_has_pending_outbox(void)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
review_pending_outbox_sessions_only(void)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int result = 0;
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT EXISTS(SELECT 1 FROM sync_outbox LIMIT 1) "
|
||||
"AND NOT EXISTS(SELECT 1 FROM sync_outbox WHERE entity_type<>'session')",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
result = sqlite3_column_int(stmt, 0) != 0;
|
||||
sqlite3_finalize(stmt);
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
review_has_unknown_activity(const char *json)
|
||||
{
|
||||
@@ -673,6 +738,76 @@ review_has_unknown_activity(const char *json)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
review_small_session_only_change(const char *diff)
|
||||
{
|
||||
int count;
|
||||
|
||||
if(!review_pending_outbox_sessions_only())
|
||||
return 0;
|
||||
count = review_visible_change_count(diff);
|
||||
return count > 0 && count <= STORAGE_SYNC_AUTO_APPLY_VISIBLE_CHANGE_LIMIT;
|
||||
}
|
||||
|
||||
static int
|
||||
review_line_starts_with_date(const char *line, size_t len)
|
||||
{
|
||||
if(line == NULL || len < 10)
|
||||
return 0;
|
||||
return line[0] >= '0' && line[0] <= '9' &&
|
||||
line[1] >= '0' && line[1] <= '9' &&
|
||||
line[2] >= '0' && line[2] <= '9' &&
|
||||
line[3] >= '0' && line[3] <= '9' &&
|
||||
line[4] == '-' &&
|
||||
line[5] >= '0' && line[5] <= '9' &&
|
||||
line[6] >= '0' && line[6] <= '9' &&
|
||||
line[7] == '-' &&
|
||||
line[8] >= '0' && line[8] <= '9' &&
|
||||
line[9] >= '0' && line[9] <= '9';
|
||||
}
|
||||
|
||||
static int
|
||||
review_line_equals_literal(const char *line, size_t len, const char *literal)
|
||||
{
|
||||
size_t literal_len;
|
||||
|
||||
if(line == NULL || literal == NULL)
|
||||
return 0;
|
||||
literal_len = strlen(literal);
|
||||
return len == literal_len && strncmp(line, literal, len) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
review_visible_change_count(const char *diff)
|
||||
{
|
||||
const char *p = diff;
|
||||
const char *line;
|
||||
const char *end;
|
||||
size_t len;
|
||||
int date_lines = 0;
|
||||
int changed_lines = 0;
|
||||
|
||||
if(diff == NULL)
|
||||
return 0;
|
||||
while(*p != '\0') {
|
||||
end = strchr(p, '\n');
|
||||
len = end != NULL ? (size_t)(end - p) : strlen(p);
|
||||
if(len > 2 && (p[0] == '-' || p[0] == '+') && p[1] == ' ') {
|
||||
line = p + 2;
|
||||
len -= 2;
|
||||
if(review_line_starts_with_date(line, len))
|
||||
date_lines++;
|
||||
else if(!review_line_equals_literal(line, len, "Sessions") &&
|
||||
!review_line_equals_literal(line, len, "Habit days"))
|
||||
changed_lines++;
|
||||
}
|
||||
if(end == NULL)
|
||||
break;
|
||||
p = end + 1;
|
||||
}
|
||||
return date_lines > 0 ? date_lines : changed_lines;
|
||||
}
|
||||
|
||||
int
|
||||
storage_apply_pending_sync_review(int use_remote)
|
||||
{
|
||||
|
||||
+111
-2
@@ -261,6 +261,39 @@ mark_empty_local_pending(const char *root)
|
||||
"VALUES('account','alias',0,1782300000);"));
|
||||
}
|
||||
|
||||
static void
|
||||
seed_local_habit_without_activity(const char *root)
|
||||
{
|
||||
check_true("seed local habit without activity",
|
||||
exec_db_sql(root, "INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,"
|
||||
"sync_mode,sync_activity,counter_enabled,sort_order,deleted_at,"
|
||||
"updated_at)"
|
||||
"VALUES('empty-local-habit',(SELECT id FROM users LIMIT 1),"
|
||||
"'Empty Habit',10,20,30,0,0,1,1,0,1782300000);"));
|
||||
}
|
||||
|
||||
static void
|
||||
seed_local_session_only(const char *root)
|
||||
{
|
||||
check_true("seed local session only",
|
||||
exec_db_sql(root, "INSERT INTO "
|
||||
"sessions(id,user_id,started_at,local_date,topic,activity,source,"
|
||||
"imported_at,rounds_hash,deleted_at,updated_at)"
|
||||
"VALUES('tiny-local-session',(SELECT id FROM users LIMIT "
|
||||
"1),1782300000,20260624,1,1,'test',1782300000,101,0,1782300000);"
|
||||
"INSERT INTO session_rounds(session_id,round_index,seconds)"
|
||||
"VALUES('tiny-local-session',0,40);"));
|
||||
}
|
||||
|
||||
static void
|
||||
mark_local_session_only_pending(const char *root)
|
||||
{
|
||||
check_true("mark local session only pending",
|
||||
exec_db_sql(root, "INSERT OR REPLACE INTO "
|
||||
"sync_outbox(entity_type,entity_id,local_date,queued_at)"
|
||||
"VALUES('session','tiny-local-session',0,1782300000);"));
|
||||
}
|
||||
|
||||
static void
|
||||
seed_local_yoga_data(const char *root)
|
||||
{
|
||||
@@ -356,6 +389,29 @@ remote_additive_yoga_response(void)
|
||||
"}";
|
||||
}
|
||||
|
||||
static const char *
|
||||
remote_tiny_session_snapshot_response(void)
|
||||
{
|
||||
return "{"
|
||||
"\"server_version\":15,"
|
||||
"\"server_state_hash\":\"remote-hash-tiny-session\","
|
||||
"\"full_snapshot_required\":true,"
|
||||
"\"changes_complete\":false,"
|
||||
"\"changes\":{"
|
||||
"\"habits\":[],"
|
||||
"\"habit_days\":[],"
|
||||
"\"sessions\":[{\"id\":\"tiny-remote-session\",\"started_at\":\"2026-06-24T10:"
|
||||
"05:00Z\","
|
||||
"\"local_date\":20260624,\"topic\":1,\"activity\":1,\"source\":\"lyra-"
|
||||
"test\","
|
||||
"\"rounds_hash\":404,\"deleted_at\":0,\"updated_at\":\"2026-06-24T10:"
|
||||
"05:00Z\","
|
||||
"\"rounds\":[{\"round_index\":0,\"hold_seconds\":55}]}],"
|
||||
"\"meditation_logs\":[]"
|
||||
"}"
|
||||
"}";
|
||||
}
|
||||
|
||||
static void
|
||||
test_full_snapshot_waits_for_review(void)
|
||||
{
|
||||
@@ -406,6 +462,34 @@ test_full_snapshot_waits_for_review(void)
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tiny_pending_snapshot_applies_remote_without_review(void)
|
||||
{
|
||||
char root[1024];
|
||||
|
||||
make_clean_root(root, sizeof(root), "tiny-pending");
|
||||
check_true("init tiny pending db", storage_init(root));
|
||||
seed_local_session_only(root);
|
||||
mark_local_session_only_pending(root);
|
||||
|
||||
check_true("apply tiny review response",
|
||||
storage_apply_sync_response_json(remote_tiny_session_snapshot_response()));
|
||||
check_false("tiny review not pending", storage_sync_review_pending());
|
||||
check_int("tiny local session replaced",
|
||||
read_db_count(root,
|
||||
"SELECT COUNT(*) FROM sessions WHERE id='tiny-local-session'"),
|
||||
0);
|
||||
check_int("tiny remote session applied",
|
||||
read_db_count(root,
|
||||
"SELECT COUNT(*) FROM sessions WHERE id='tiny-remote-session'"),
|
||||
1);
|
||||
check_int("tiny outbox cleared",
|
||||
read_db_count(root, "SELECT COUNT(*) FROM sync_outbox"), 0);
|
||||
|
||||
storage_close();
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
test_empty_local_pending_snapshot_applies_remote(void)
|
||||
{
|
||||
@@ -417,8 +501,7 @@ test_empty_local_pending_snapshot_applies_remote(void)
|
||||
|
||||
check_true("apply empty local review response",
|
||||
storage_apply_sync_response_json(remote_snapshot_response()));
|
||||
check_true("empty local review pending before policy", storage_sync_review_pending());
|
||||
check_true("empty local applies remote", storage_sync_review_apply_remote_if_local_empty());
|
||||
check_false("empty local review not pending", storage_sync_review_pending());
|
||||
check_false("empty local review cleared", storage_sync_review_pending());
|
||||
check_int("empty local remote session applied",
|
||||
read_db_count(root, "SELECT COUNT(*) FROM sessions WHERE id='remote-session'"), 1);
|
||||
@@ -431,6 +514,30 @@ test_empty_local_pending_snapshot_applies_remote(void)
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
test_local_habit_without_activity_does_not_force_review(void)
|
||||
{
|
||||
char root[1024];
|
||||
|
||||
make_clean_root(root, sizeof(root), "empty-habit-local");
|
||||
check_true("init empty habit local db", storage_init(root));
|
||||
seed_local_habit_without_activity(root);
|
||||
mark_empty_local_pending(root);
|
||||
|
||||
check_true("apply empty habit local response",
|
||||
storage_apply_sync_response_json(remote_snapshot_response()));
|
||||
check_false("empty habit local review not pending", storage_sync_review_pending());
|
||||
check_int("empty habit local remote session applied",
|
||||
read_db_count(root, "SELECT COUNT(*) FROM sessions WHERE id='remote-session'"), 1);
|
||||
check_int("empty habit local remote habit applied",
|
||||
read_db_count(root, "SELECT COUNT(*) FROM habits WHERE id='remote-habit'"), 1);
|
||||
check_int("empty habit local outbox cleared",
|
||||
read_db_count(root, "SELECT COUNT(*) FROM sync_outbox"), 0);
|
||||
|
||||
storage_close();
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
test_review_ignores_deleted_remote_rows(void)
|
||||
{
|
||||
@@ -696,7 +803,9 @@ main(void)
|
||||
tzset();
|
||||
|
||||
test_full_snapshot_waits_for_review();
|
||||
test_tiny_pending_snapshot_applies_remote_without_review();
|
||||
test_empty_local_pending_snapshot_applies_remote();
|
||||
test_local_habit_without_activity_does_not_force_review();
|
||||
test_review_ignores_deleted_remote_rows();
|
||||
test_remote_additions_apply_without_review();
|
||||
test_remote_snapshot_removes_absent_local_yoga_without_pending_edits();
|
||||
|
||||
+4
-4
@@ -3,8 +3,8 @@
|
||||
IDI_APP_ICON ICON "inbe.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,7,3,0
|
||||
PRODUCTVERSION 1,7,3,0
|
||||
FILEVERSION 1,7,6,0
|
||||
PRODUCTVERSION 1,7,6,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -21,11 +21,11 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "waozi"
|
||||
VALUE "FileDescription", "Inner Breeze"
|
||||
VALUE "FileVersion", "1.7.3"
|
||||
VALUE "FileVersion", "1.7.6"
|
||||
VALUE "InternalName", "inbe"
|
||||
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
|
||||
VALUE "ProductName", "Inner Breeze"
|
||||
VALUE "ProductVersion", "1.7.3"
|
||||
VALUE "ProductVersion", "1.7.6"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
Reference in new issue
Block a user