Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0b5bb3599 | ||
|
|
e62357670f | ||
|
|
59ebb09921 | ||
|
|
d8a6521ce4 | ||
|
|
e5c77d0a0e | ||
|
|
0c13c833e3 | ||
|
|
f29a1f8cf7 | ||
|
|
1b0e06dce2 | ||
|
|
db7bb624e4 | ||
|
|
4a8a554396 |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
build-essential
|
||||
ca-certificates
|
||||
curl
|
||||
libcurl4-openssl-dev
|
||||
libdrm-dev
|
||||
libegl1-mesa-dev
|
||||
libgbm-dev
|
||||
libgles2-mesa-dev
|
||||
libsdl2-dev
|
||||
patchelf
|
||||
pkg-config
|
||||
zip
|
||||
@@ -80,6 +80,8 @@ jobs:
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
env:
|
||||
APT_CACHE_DIR: /tmp/apt-cache
|
||||
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
@@ -88,22 +90,24 @@ jobs:
|
||||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache Linux apt packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ env.APT_CACHE_DIR }}
|
||||
key: linux-apt-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.github/apt/linux-packages.txt') }}
|
||||
restore-keys: |
|
||||
linux-apt-${{ runner.os }}-${{ runner.arch }}-
|
||||
|
||||
- name: Install Linux Dependencies
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mapfile -t packages < .github/apt/linux-packages.txt
|
||||
mkdir -p "$APT_CACHE_DIR/partial"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
curl \
|
||||
libcurl4-openssl-dev \
|
||||
libdrm-dev \
|
||||
libegl1-mesa-dev \
|
||||
libgbm-dev \
|
||||
libgles2-mesa-dev \
|
||||
libsdl2-dev \
|
||||
patchelf \
|
||||
pkg-config \
|
||||
zip
|
||||
sudo apt-get \
|
||||
-o Dir::Cache::archives="$APT_CACHE_DIR" \
|
||||
install -y "${packages[@]}"
|
||||
sudo chown -R "$USER:$USER" "$APT_CACHE_DIR"
|
||||
|
||||
- name: Install AppImage Tools
|
||||
run: |
|
||||
|
||||
@@ -10,3 +10,6 @@
|
||||
[submodule "vendor/sqlite"]
|
||||
path = vendor/sqlite
|
||||
url = https://github.com/sqlite/sqlite
|
||||
[submodule "vendor/liboqs"]
|
||||
path = vendor/liboqs
|
||||
url = https://github.com/open-quantum-safe/liboqs.git
|
||||
@@ -1,4 +1,17 @@
|
||||
# Changelog
|
||||
## [1.4.0] - 2026-06-19
|
||||
### Added
|
||||
- optional sync client, offline account creation
|
||||
- simplify tutorial
|
||||
|
||||
## [1.3.6] - 2026-06-18
|
||||
### Fixed
|
||||
- Fixed Tickmate `.db` imports so zero-based months map correctly and long habit histories load without dropping later dates.
|
||||
|
||||
## [1.3.5] - 2026-06-18
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
|
||||
## [1.3.4] - 2026-06-18
|
||||
### Changed
|
||||
- Reorganized WHM and Meditation into practice-owned modules for cleaner code boundaries.
|
||||
|
||||
@@ -69,10 +69,15 @@ SQLITE_AMALGAMATION_C := $(SQLITE_BUILD_DIR)/sqlite3.c
|
||||
SQLITE_AMALGAMATION_H := $(SQLITE_BUILD_DIR)/sqlite3.h
|
||||
SQLITE_SRC := $(SQLITE_AMALGAMATION_C)
|
||||
SQLITE_INCLUDE := -I$(SQLITE_BUILD_DIR)
|
||||
LIBOQS_DIR := vendor/liboqs
|
||||
LIBOQS_BUILD_DIR := $(BUILD_OBJ_DIR)/liboqs/linux/$(ARCH)
|
||||
LIBOQS_A := $(LIBOQS_BUILD_DIR)/lib/liboqs.a
|
||||
LIBOQS_INCLUDE := -I$(LIBOQS_BUILD_DIR)/include
|
||||
TEST_BIN_DIR := $(BUILD_BIN_DIR)/tests
|
||||
STORAGE_IMPORT_TEST := $(TEST_BIN_DIR)/storage_import_test
|
||||
FLINT_TEXT_SCALING_TEST := $(TEST_BIN_DIR)/flint_text_scaling_test
|
||||
LOCALE_KEYS_TEST := $(TEST_BIN_DIR)/locale_keys_test
|
||||
SYNC_URL_TEST := $(TEST_BIN_DIR)/sync_url_test
|
||||
FLINT_RUNTIME_ASSET_CFLAGS := -DFLINT_HAS_LIBCURL=1 $(FLINT_CURL_CFLAGS)
|
||||
FLINT_RUNTIME_ASSET_LDLIBS := $(FLINT_CURL_LDLIBS)
|
||||
|
||||
@@ -97,12 +102,18 @@ APP_SRCS := \
|
||||
src/core/theme.c \
|
||||
src/storage/data.c \
|
||||
src/storage/storage.c \
|
||||
src/storage/sync_account.c \
|
||||
src/storage/sync_client.c \
|
||||
src/third_party/miniz.c \
|
||||
src/platform/android/android_device.c \
|
||||
src/screens/practice_screen.c \
|
||||
src/screens/language_screen.c \
|
||||
src/screens/manual_screen.c \
|
||||
src/screens/settings/settings_screen.c
|
||||
src/screens/settings/settings_screen.c \
|
||||
src/screens/settings/settings_device.c \
|
||||
src/screens/settings/settings_theme.c \
|
||||
src/screens/settings/settings_data.c \
|
||||
src/screens/settings/settings_sync_account.c
|
||||
|
||||
LOCALE_FILES := $(wildcard locales/*.txt)
|
||||
IMAGE_FILES := assets/practices/whm/1.jpg assets/practices/whm/2.jpg assets/practices/meditation/1.jpg
|
||||
@@ -187,10 +198,11 @@ appimage: $(APPIMAGE_TARGET)
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST)
|
||||
test: $(STORAGE_IMPORT_TEST) $(FLINT_TEXT_SCALING_TEST) $(LOCALE_KEYS_TEST) $(SYNC_URL_TEST)
|
||||
$(STORAGE_IMPORT_TEST)
|
||||
$(FLINT_TEXT_SCALING_TEST)
|
||||
$(LOCALE_KEYS_TEST)
|
||||
$(SYNC_URL_TEST)
|
||||
|
||||
$(STORAGE_IMPORT_TEST): tests/storage_import_test.c src/storage/storage.c src/storage/storage.h src/screens/habits_screen.c src/screens/habits_screen.h src/third_party/miniz.c src/third_party/miniz.h $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -DMINIZ_NO_ZLIB_COMPATIBLE_NAMES -ffunction-sections -fdata-sections \
|
||||
@@ -211,6 +223,12 @@ $(LOCALE_KEYS_TEST): tests/locale_keys_test.c $(LOCALE_FILES) | $(TEST_BIN_DIR)
|
||||
-o $@ \
|
||||
tests/locale_keys_test.c
|
||||
|
||||
$(SYNC_URL_TEST): tests/sync_url_test.c src/storage/sync_client.c src/storage/sync_client.h | $(TEST_BIN_DIR)
|
||||
$(CC) -Wall -Wextra -Wno-unused-function -std=c99 -D_DEFAULT_SOURCE -DINBE_SYNC_CLIENT_TESTS -ffunction-sections -fdata-sections \
|
||||
-Isrc/storage -Isrc -Ivendor/raylib/src -o $@ \
|
||||
tests/sync_url_test.c src/storage/sync_client.c \
|
||||
-Wl,--gc-sections
|
||||
|
||||
$(BUILD_OBJ_DIR) $(LINUX_BIN_DIR) $(LINUX_DIST_DIR) $(LINUX_APPIMAGE_BUILD_DIR) $(WINDOWS_DIST_DIR) $(ANDROID_BUILD_DIR) $(TEST_BIN_DIR) $(WEB_OBJ_DIR) $(WEB_DIST_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
@@ -303,13 +321,24 @@ $(SQLITE_AMALGAMATION_C) $(SQLITE_AMALGAMATION_H): $(SQLITE_DIR)/configure $(SQL
|
||||
cd $(SQLITE_BUILD_DIR) && ../../../$(SQLITE_DIR)/configure
|
||||
$(MAKE) -C $(SQLITE_BUILD_DIR) sqlite3.c sqlite3.h
|
||||
|
||||
$(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(RAYLIB_A) | $(LINUX_BIN_DIR)
|
||||
$(LIBOQS_A): $(LIBOQS_DIR)/CMakeLists.txt | $(BUILD_OBJ_DIR)
|
||||
cmake -S $(LIBOQS_DIR) -B $(LIBOQS_BUILD_DIR) \
|
||||
-DCMAKE_BUILD_TYPE=MinSizeRel \
|
||||
-DBUILD_SHARED_LIBS=OFF \
|
||||
-DOQS_BUILD_ONLY_LIB=ON \
|
||||
-DOQS_USE_OPENSSL=OFF \
|
||||
-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44
|
||||
cmake --build $(LIBOQS_BUILD_DIR) --target oqs
|
||||
|
||||
$(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) $(FONT_OUTPUTS) $(EMBEDDED_ASSETS_C) $(RAYLIB_A) $(LIBOQS_A) | $(LINUX_BIN_DIR)
|
||||
$(CC) $(CFLAGS) \
|
||||
$(APP_INCLUDE) \
|
||||
$(FLINT_INCLUDE) \
|
||||
$(SQLITE_INCLUDE) \
|
||||
$(LIBOQS_INCLUDE) \
|
||||
-I$(RAYLIB_DIR) \
|
||||
$(RAY_CFLAGS) \
|
||||
-DINBE_HAS_LIBOQS=1 \
|
||||
-DSUPPORT_MODULE_RAUDIO=1 \
|
||||
-DSUPPORT_FILEFORMAT_OGG=1 \
|
||||
-DSUPPORT_FILEFORMAT_MP3=1 \
|
||||
@@ -318,6 +347,7 @@ $(TARGET): Makefile $(SRC) $(FLINT_SRCS) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H)
|
||||
$(FLINT_SRCS) \
|
||||
$(SQLITE_SRC) \
|
||||
$(RAYLIB_A) \
|
||||
$(LIBOQS_A) \
|
||||
$(RAY_LDLIBS) \
|
||||
$(FLINT_RUNTIME_ASSET_LDLIBS) \
|
||||
-lm -lpthread -ldl -lrt \
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 35 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 67 KiB |
@@ -35,8 +35,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdk 19
|
||||
targetSdk 35
|
||||
versionCode 32
|
||||
versionName "1.3.4"
|
||||
versionCode 35
|
||||
versionName "1.4.0"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ set(SQLITE_BUILD_DIR "${CMAKE_BINARY_DIR}/sqlite")
|
||||
set(SQLITE_AMALGAMATION_C "${SQLITE_BUILD_DIR}/sqlite3.c")
|
||||
set(SQLITE_AMALGAMATION_H "${SQLITE_BUILD_DIR}/sqlite3.h")
|
||||
set(NATIVE_APP_GLUE_DIR "${ANDROID_NDK}/sources/android/native_app_glue")
|
||||
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "" FORCE)
|
||||
set(OQS_USE_OPENSSL OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44" CACHE STRING "" FORCE)
|
||||
add_subdirectory("${REPO_ROOT}/vendor/liboqs" "${CMAKE_BINARY_DIR}/liboqs")
|
||||
file(GLOB FLINT_SOURCES CONFIGURE_DEPENDS "${FLINT_DIR}/src/*.c")
|
||||
list(REMOVE_ITEM FLINT_SOURCES "${FLINT_DIR}/src/flint_file_dialog.c")
|
||||
file(GLOB INBE_LOCALE_ASSETS RELATIVE "${REPO_ROOT}" CONFIGURE_DEPENDS "${REPO_ROOT}/locales/*.txt")
|
||||
@@ -106,6 +110,8 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/core/theme.c"
|
||||
"${SRC_DIR}/storage/data.c"
|
||||
"${SRC_DIR}/storage/storage.c"
|
||||
"${SRC_DIR}/storage/sync_account.c"
|
||||
"${SRC_DIR}/storage/sync_client.c"
|
||||
"${SRC_DIR}/third_party/miniz.c"
|
||||
"${SQLITE_AMALGAMATION_C}"
|
||||
"${SRC_DIR}/platform/android/android_device.c"
|
||||
@@ -116,6 +122,10 @@ add_library(main SHARED
|
||||
"${SRC_DIR}/screens/language_screen.c"
|
||||
"${SRC_DIR}/screens/manual_screen.c"
|
||||
"${SRC_DIR}/screens/settings/settings_screen.c"
|
||||
"${SRC_DIR}/screens/settings/settings_device.c"
|
||||
"${SRC_DIR}/screens/settings/settings_theme.c"
|
||||
"${SRC_DIR}/screens/settings/settings_data.c"
|
||||
"${SRC_DIR}/screens/settings/settings_sync_account.c"
|
||||
"${INBE_EMBEDDED_ASSETS_C}"
|
||||
${FLINT_SOURCES}
|
||||
"${SRC_DIR}/platform/android/android_insets.c"
|
||||
@@ -153,6 +163,7 @@ target_compile_definitions(main PRIVATE
|
||||
SUPPORT_MODULE_RAUDIO=1
|
||||
SUPPORT_FILEFORMAT_OGG=1
|
||||
FLINT_EMBEDDED_ONLY=1
|
||||
INBE_HAS_LIBOQS=1
|
||||
)
|
||||
|
||||
target_compile_options(main PRIVATE
|
||||
@@ -170,6 +181,7 @@ target_link_options(main PRIVATE
|
||||
|
||||
target_link_libraries(main
|
||||
raylib
|
||||
oqs
|
||||
android
|
||||
log
|
||||
OpenSLES
|
||||
|
||||
@@ -26,11 +26,13 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class MainActivity extends NativeActivity {
|
||||
private static final String TAG = "InbeMainActivity";
|
||||
@@ -51,6 +53,7 @@ public class MainActivity extends NativeActivity {
|
||||
private boolean windowFocused = true;
|
||||
private boolean backgroundExecutionActive = false;
|
||||
private boolean autoPausedForLifecycle = false;
|
||||
private int lastDeleteRepeatCount = -1;
|
||||
|
||||
private native void nativeSetInsets(int status, int nav,
|
||||
int cutoutLeft, int cutoutTop, int cutoutRight, int cutoutBottom);
|
||||
@@ -149,18 +152,32 @@ public class MainActivity extends NativeActivity {
|
||||
if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
int keyCode = event.getKeyCode();
|
||||
if (keyCode == KeyEvent.KEYCODE_DEL) {
|
||||
nativeTextInputBackspace();
|
||||
int repeatCount = event.getRepeatCount();
|
||||
int deleteCount = lastDeleteRepeatCount < 0
|
||||
? 1
|
||||
: Math.max(1, repeatCount - lastDeleteRepeatCount);
|
||||
lastDeleteRepeatCount = repeatCount;
|
||||
for (int i = 0; i < deleteCount; i++) {
|
||||
nativeTextInputBackspace();
|
||||
}
|
||||
} else if (keyCode == KeyEvent.KEYCODE_ENTER ||
|
||||
keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
nativeTextInputEnter();
|
||||
} else {
|
||||
lastDeleteRepeatCount = -1;
|
||||
int unicode = event.getUnicodeChar();
|
||||
if (unicode >= 32) {
|
||||
nativeTextInputCommit(unicode);
|
||||
}
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
}
|
||||
} else if (event != null && event.getAction() == KeyEvent.ACTION_MULTIPLE &&
|
||||
event.getCharacters() != null) {
|
||||
lastDeleteRepeatCount = -1;
|
||||
String chars = event.getCharacters();
|
||||
for (int i = 0; i < chars.length();) {
|
||||
int codepoint = chars.codePointAt(i);
|
||||
@@ -268,6 +285,68 @@ public class MainActivity extends NativeActivity {
|
||||
}, "inbe-runtime-asset-download").start();
|
||||
}
|
||||
|
||||
public String syncHttpRequest(String method, String urlText, String body, String[] headers) {
|
||||
HttpURLConnection connection = null;
|
||||
int status = 0;
|
||||
|
||||
try {
|
||||
byte[] bodyBytes = body != null ? body.getBytes(StandardCharsets.UTF_8) : new byte[0];
|
||||
connection = (HttpURLConnection)new URL(urlText).openConnection();
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.setConnectTimeout(15000);
|
||||
connection.setReadTimeout(30000);
|
||||
connection.setRequestMethod(method);
|
||||
connection.setRequestProperty("User-Agent", "inbe-sync/1");
|
||||
if (headers != null) {
|
||||
for (String header : headers) {
|
||||
if (header == null) continue;
|
||||
int colon = header.indexOf(':');
|
||||
if (colon <= 0) continue;
|
||||
String key = header.substring(0, colon).trim();
|
||||
String value = header.substring(colon + 1).trim();
|
||||
if (!key.isEmpty()) {
|
||||
connection.setRequestProperty(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("POST".equals(method) || "DELETE".equals(method)) {
|
||||
connection.setDoOutput(true);
|
||||
connection.setFixedLengthStreamingMode(bodyBytes.length);
|
||||
try (OutputStream output = connection.getOutputStream()) {
|
||||
output.write(bodyBytes);
|
||||
}
|
||||
}
|
||||
|
||||
status = connection.getResponseCode();
|
||||
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
|
||||
String response = "";
|
||||
if (stream != null) {
|
||||
try (InputStream input = stream) {
|
||||
byte[] bytes = readAllBytesCompat(input);
|
||||
response = new String(bytes, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
return status + "\n" + response;
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Sync HTTP request failed", e);
|
||||
return status + "\n" + (e.getMessage() != null ? e.getMessage() : "request failed");
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] readAllBytesCompat(InputStream input) throws java.io.IOException {
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
|
||||
while ((read = input.read(buffer)) != -1) {
|
||||
output.write(buffer, 0, read);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
public void openImportPicker() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@@ -281,7 +360,8 @@ public class MainActivity extends NativeActivity {
|
||||
"application/x-zip-compressed",
|
||||
"application/vnd.sqlite3",
|
||||
"application/x-sqlite",
|
||||
"application/x-sqlite3"
|
||||
"application/x-sqlite3",
|
||||
"application/octet-stream"
|
||||
});
|
||||
startActivityForResult(intent, REQUEST_IMPORT_ZIP);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -11,6 +11,40 @@ import java.io.FileOutputStream;
|
||||
public class ShareHelper {
|
||||
private static final String TAG = "InbeShare";
|
||||
|
||||
public static void shareFile(Activity activity, byte[] data, String filename, String mimeType, String chooserTitle) {
|
||||
if (activity == null || data == null) return;
|
||||
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File cacheFile = new File(activity.getCacheDir(), filename);
|
||||
FileOutputStream fos = new FileOutputStream(cacheFile);
|
||||
fos.write(data);
|
||||
fos.close();
|
||||
|
||||
Uri contentUri = FileProvider.getUriForFile(
|
||||
activity,
|
||||
"xyz.waozi.inbe.fileprovider",
|
||||
cacheFile
|
||||
);
|
||||
|
||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.setType(mimeType != null ? mimeType : "application/octet-stream");
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
Intent shareIntent = Intent.createChooser(sendIntent, chooserTitle);
|
||||
activity.startActivity(shareIntent);
|
||||
|
||||
Log.i(TAG, "Share sheet shown");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Share failed", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void shareZipFile(Activity activity, byte[] zipData, String filename, String chooserTitle) {
|
||||
if (activity == null || zipData == null) return;
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Improved Android data import for `.db` backups, weekly habit rows, and import conflict handling.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Fixed
|
||||
- Fixed Tickmate `.db` imports so zero-based months map correctly and long habit histories load without dropping later dates.
|
||||
@@ -0,0 +1,2 @@
|
||||
### Added
|
||||
- optional sync client, offline account creation
|
||||
@@ -216,6 +216,8 @@ int ui_draw_slider_vertical_with_marks(int id, int x, int y, int h,
|
||||
int ui_draw_toggle_switch(int x, int y, int w, int h, int *value,
|
||||
const char *off_label, const char *on_label);
|
||||
int ui_draw_checkbox_toggle(int x, int y, const char *label, int *value);
|
||||
int ui_draw_checkbox_toggle_disabled(int x, int y, const char *label,
|
||||
int *value, int disabled);
|
||||
int ui_draw_dropdown_button(int id, int x, int y, int w, int h, const char **options, int option_count, int *selected_index);
|
||||
int ui_draw_dropdown_menu(int id);
|
||||
int ui_dropdown_captures_click(Vector2 point);
|
||||
|
||||
@@ -38,6 +38,10 @@ void flint_file_dialog_set_theme_scope(const char *scope) {
|
||||
|
||||
static FlintFileDialogInternal *create_internal(void) {
|
||||
FlintFileDialogInternal *internal = calloc(1, sizeof(FlintFileDialogInternal));
|
||||
if(internal != NULL) {
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
}
|
||||
return internal;
|
||||
}
|
||||
|
||||
@@ -214,6 +218,9 @@ static int scan_directory(FlintFileDialogInternal *internal) {
|
||||
qsort(internal->entries, internal->file_count,
|
||||
sizeof(DirEntry), compare_entries);
|
||||
}
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->last_click_time = 0.0f;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -306,7 +313,7 @@ static void render_file_list(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
int list_x = dialog_rect.x + flint_px(16);
|
||||
int scrollbar_w = flint_px(12);
|
||||
int list_width = dialog_rect.width - flint_px(32);
|
||||
int bottom_y = dialog_rect.y + internal->dialog_height - flint_px(72);
|
||||
int bottom_y = dialog_rect.y + internal->dialog_height - flint_px(112);
|
||||
int list_height = bottom_y - list_y;
|
||||
if(list_height < FILE_DIALOG_ITEM_HEIGHT)
|
||||
list_height = FILE_DIALOG_ITEM_HEIGHT;
|
||||
@@ -401,12 +408,11 @@ static void render_scrollbar(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
static void render_filename_input(FlintFileDialog *dlg, Rectangle dialog_rect) {
|
||||
FlintFileDialogInternal *internal = (FlintFileDialogInternal *)dlg->_internal;
|
||||
|
||||
int input_y = dialog_rect.y + internal->dialog_height - flint_px(58);
|
||||
int input_y = dialog_rect.y + internal->dialog_height - flint_px(96);
|
||||
int input_x = dialog_rect.x + flint_px(16);
|
||||
int font = flint_ui_font_small();
|
||||
int label_width = flint_text_measure("Filename:", font) + flint_px(8);
|
||||
int button_area_width = flint_px(176);
|
||||
int input_width = dialog_rect.width - flint_px(32) - label_width - button_area_width;
|
||||
int input_width = dialog_rect.width - flint_px(32) - label_width;
|
||||
int input_height = flint_px(24);
|
||||
if(input_width < flint_px(24))
|
||||
input_width = flint_px(24);
|
||||
@@ -575,9 +581,10 @@ static int handle_mouse_input(FlintFileDialog *dlg) {
|
||||
if(hover_idx >= 0 && hover_idx < internal->file_count) {
|
||||
float current_time = GetTime();
|
||||
if(current_time - internal->last_click_time < 0.5 &&
|
||||
internal->hover_index == hover_idx) {
|
||||
internal->last_clicked_index == hover_idx) {
|
||||
if(internal->entries[hover_idx].is_dir) {
|
||||
navigate_into(internal, internal->entries[hover_idx].name);
|
||||
internal->last_clicked_index = -1;
|
||||
} else {
|
||||
copy_text(internal->selected_file, sizeof(internal->selected_file),
|
||||
internal->entries[hover_idx].name);
|
||||
@@ -595,6 +602,7 @@ static int handle_mouse_input(FlintFileDialog *dlg) {
|
||||
}
|
||||
|
||||
internal->last_click_time = current_time;
|
||||
internal->last_clicked_index = hover_idx;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,7 +779,8 @@ flint_file_dialog_begin_load(FlintFileDialog *dlg, const char *title)
|
||||
scan_directory(internal);
|
||||
internal->filename_input[0] = '\0';
|
||||
internal->selected_file[0] = '\0';
|
||||
internal->hover_index = 0;
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->focus_area = 0;
|
||||
}
|
||||
|
||||
@@ -839,7 +848,8 @@ int flint_file_dialog_select_folder(FlintFileDialog *dlg, const char *title) {
|
||||
FlintFileDialogInternal *internal = (FlintFileDialogInternal *)dlg->_internal;
|
||||
internal->filename_input[0] = '\0';
|
||||
internal->selected_file[0] = '\0';
|
||||
internal->hover_index = 0;
|
||||
internal->hover_index = -1;
|
||||
internal->last_clicked_index = -1;
|
||||
internal->focus_area = 0;
|
||||
|
||||
if(run_dialog(dlg)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ typedef struct {
|
||||
DirEntry *entries;
|
||||
int scroll_offset;
|
||||
int hover_index;
|
||||
int last_clicked_index;
|
||||
int focus_area;
|
||||
Rectangle breadcrumb_rect;
|
||||
Rectangle file_list_rect;
|
||||
|
||||
+57
-9
@@ -50,6 +50,7 @@ static int g_ui_text_input_codepoints[UI_TEXT_INPUT_QUEUE_MAX];
|
||||
static int g_ui_text_input_codepoint_count = 0;
|
||||
static int g_ui_text_input_backspace_count = 0;
|
||||
static int g_ui_text_input_enter_count = 0;
|
||||
static double g_ui_backspace_next_repeat_at = 0.0;
|
||||
|
||||
#define UI_INPUT_CLIP_STACK_MAX 16
|
||||
static Rectangle g_ui_input_clip_stack[UI_INPUT_CLIP_STACK_MAX];
|
||||
@@ -88,6 +89,32 @@ ui_pointer_dx(void)
|
||||
return (int)mouse.x - g_ui_pointer_start_x;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_backspace_repeat_count(void)
|
||||
{
|
||||
double now;
|
||||
int count = 0;
|
||||
|
||||
if(IsKeyPressed(KEY_BACKSPACE)) {
|
||||
g_ui_backspace_next_repeat_at = GetTime() + 0.34;
|
||||
return 1;
|
||||
}
|
||||
if(!IsKeyDown(KEY_BACKSPACE)) {
|
||||
g_ui_backspace_next_repeat_at = 0.0;
|
||||
return 0;
|
||||
}
|
||||
now = GetTime();
|
||||
if(g_ui_backspace_next_repeat_at <= 0.0) {
|
||||
g_ui_backspace_next_repeat_at = now + 0.34;
|
||||
return 0;
|
||||
}
|
||||
while(now >= g_ui_backspace_next_repeat_at && count < 8) {
|
||||
count++;
|
||||
g_ui_backspace_next_repeat_at += 0.045;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
ui_pointer_dy(void)
|
||||
{
|
||||
@@ -650,8 +677,8 @@ flint_ui_text_edit(FlintUITextEdit edit)
|
||||
changed = 1;
|
||||
}
|
||||
|
||||
if(IsKeyPressed(KEY_BACKSPACE) || g_ui_text_input_backspace_count > 0) {
|
||||
int repeat = g_ui_text_input_backspace_count > 0 ? g_ui_text_input_backspace_count : 1;
|
||||
{
|
||||
int repeat = g_ui_text_input_backspace_count + ui_backspace_repeat_count();
|
||||
for(int i = 0; i < repeat; i++) {
|
||||
int start = ui_utf8_prev_offset(edit.text, *edit.cursor_position);
|
||||
changed |= ui_text_delete_range(edit.text, edit.text_size,
|
||||
@@ -1132,6 +1159,7 @@ ui_draw_text_btn(int x, int y, const char *label, int *hover)
|
||||
Vector2 mouse_world = ui_mouse_world();
|
||||
int mx = (int)mouse_world.x;
|
||||
int my = (int)mouse_world.y;
|
||||
int local_hover = 0;
|
||||
|
||||
int mb = IsMouseButtonDown(MOUSE_BUTTON_LEFT);
|
||||
int released = IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
@@ -1140,6 +1168,8 @@ ui_draw_text_btn(int x, int y, const char *label, int *hover)
|
||||
int h = flint_clamp_px(30, 26, 34);
|
||||
|
||||
x = x - w / 2;
|
||||
if(!hover)
|
||||
hover = &local_hover;
|
||||
|
||||
int pressed = 0;
|
||||
|
||||
@@ -1666,37 +1696,55 @@ ui_draw_toggle_switch(int x, int y, int w, int h, int *value,
|
||||
}
|
||||
|
||||
int
|
||||
ui_draw_checkbox_toggle(int x, int y, const char *label, int *value)
|
||||
ui_draw_checkbox_toggle_disabled(int x, int y, const char *label,
|
||||
int *value, int disabled)
|
||||
{
|
||||
int font = flint_ui_font();
|
||||
int box_size = flint_px(22);
|
||||
int hover = 0;
|
||||
Rectangle bounds = {x, y, box_size, box_size};
|
||||
Vector2 mouse_world = ui_mouse_world();
|
||||
Color box_color = disabled ? flint_darken(c_button, 18) : c_button;
|
||||
Color mark_color = disabled ? flint_darken(c_text, 35) : c_text;
|
||||
Color label_color = disabled ? flint_darken(c_text, 35) : c_text;
|
||||
|
||||
if(CheckCollisionPointRec(mouse_world, bounds) && !ui_input_captures_click(mouse_world)) {
|
||||
hover = 1;
|
||||
ui_mark_clickable();
|
||||
if(disabled)
|
||||
ui_mark_disabled();
|
||||
else {
|
||||
hover = 1;
|
||||
ui_mark_clickable();
|
||||
}
|
||||
}
|
||||
|
||||
int pressed = hover && IsMouseButtonReleased(MOUSE_BUTTON_LEFT);
|
||||
if(pressed)
|
||||
*value = !(*value);
|
||||
|
||||
DrawRectangle(x, y, box_size, box_size, c_button);
|
||||
DrawRectangle(x, y, box_size, box_size, box_color);
|
||||
ui_draw_bevel(x, y, box_size, box_size, flint_darken(c_bg, 30), flint_lighten(c_bg, 20));
|
||||
|
||||
if(*value) {
|
||||
int padding = flint_px(4);
|
||||
DrawLine(x + padding, y + padding, x + box_size / 2, y + box_size - padding, c_text);
|
||||
DrawLine(x + box_size / 2, y + box_size - padding, x + box_size - padding, y + padding, c_text);
|
||||
DrawLine(x + padding, y + padding, x + box_size / 2,
|
||||
y + box_size - padding, mark_color);
|
||||
DrawLine(x + box_size / 2, y + box_size - padding,
|
||||
x + box_size - padding, y + padding, mark_color);
|
||||
}
|
||||
|
||||
flint_text_draw(label, x + box_size + flint_px(10), flint_ui_text_y(label, y, box_size, font), font, c_text);
|
||||
flint_text_draw(label, x + box_size + flint_px(10),
|
||||
flint_ui_text_y(label, y, box_size, font),
|
||||
font, label_color);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
int
|
||||
ui_draw_checkbox_toggle(int x, int y, const char *label, int *value)
|
||||
{
|
||||
return ui_draw_checkbox_toggle_disabled(x, y, label, value, 0);
|
||||
}
|
||||
|
||||
/* Per-dropdown state to track open/closed and click handling */
|
||||
typedef struct UIDropdownState {
|
||||
int id;
|
||||
|
||||
+100
-17
@@ -397,21 +397,20 @@ Nikdy ho nepoužívejte při řízení,
|
||||
vestoje ani ve vodě.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Stačí postupovat ve 4 krocích:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Dýchejte rytmicky.
|
||||
2. Vydechněte a zadržte dech.
|
||||
3. Zhluboka se nadechněte a zadržte dech.
|
||||
4. Vydechněte a opakujte.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Pomocí ikony ozubeného kola %i upravíte kola, nádechy, rychlost a pauzy.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Naplňte plíce úplně a potom nechte dech volně odejít.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Tímto posuvníkem nastavíte tempo dechového kruhu.
|
||||
|
||||
Najděte rytmus, který vám připadá přirozený.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Postupná rychlost usnadňuje vstup do prvního kola.
|
||||
@@ -419,17 +418,14 @@ Postupná rychlost usnadňuje vstup do prvního kola.
|
||||
Když je zapnutá, první kolo začne rychlostí 1 pro prvních 5 nádechů a potom se postupně zvýší na vámi vybranou rychlost.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Po dechovém kole
|
||||
normálně vydechněte a zadržte dech.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Uvolněte se, až si tělo řekne
|
||||
o vzduch. Nenuťte to.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Plně se nadechněte a zadržte dech asi na 15 sekund.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Potom vydechněte a začněte další kolo.
|
||||
Časem může každé kolo působit hlouběji.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
PŘESKOČIT
|
||||
@@ -494,3 +490,90 @@ Na šířku
|
||||
[orientation_sensor]
|
||||
Senzor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -397,21 +397,20 @@ Benutzen Sie sie niemals beim Fahren,
|
||||
Stehen oder im Wasser.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Folgen Sie einfach 4 Schritten:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Atmen Sie rhythmisch.
|
||||
2. Atmen Sie aus und halten Sie.
|
||||
3. Atmen Sie tief ein und halten Sie.
|
||||
4. Atmen Sie aus und wiederholen Sie.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Nutzen Sie das Schraubenschlüssel-Symbol %i, um Runden, Atemzüge, Geschwindigkeit und Pausen anzupassen.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Füllen Sie Ihre Lungen vollständig, dann lassen Sie den Atem herausfließen.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Nutzen Sie diesen Schieberegler, um das Tempo des Atemkreises einzustellen.
|
||||
|
||||
Finden Sie einen Rhythmus, der sich natürlich für Sie anfühlt.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Progressive Geschwindigkeit macht den Einstieg in die erste Runde leichter.
|
||||
@@ -419,17 +418,14 @@ Progressive Geschwindigkeit macht den Einstieg in die erste Runde leichter.
|
||||
Wenn sie aktiviert ist, beginnt die erste Runde bei Geschwindigkeit 1 für die ersten 5 Atemzüge und steigt dann schrittweise auf Ihre gewählte Geschwindigkeit.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Nach der Atemrunde,
|
||||
atmen Sie normal aus und halten Sie.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Lassen Sie los, wenn Ihr Körper
|
||||
nach Luft verlangt. Zwängen Sie es nicht.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Atmen Sie vollständig ein und halten Sie etwa 15 Sekunden.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Dann atmen Sie aus und beginnen die nächste Runde.
|
||||
Mit der Zeit kann sich jede Runde tiefer anfühlen.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -494,3 +490,90 @@ Querformat
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+98
-15
@@ -418,21 +418,20 @@ Never use it while driving,
|
||||
standing, or in water.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Simply follow 4 steps:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Breathe rhythmically.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. Inhale deeply and hold.
|
||||
4. Exhale and repeat.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Fill your lungs fully, then let the breath flow out.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use this slider to set the pace of the breathing circle.
|
||||
|
||||
Find a rhythm that feels natural for you.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Progressive speed makes the first round easier to enter.
|
||||
@@ -440,17 +439,14 @@ Progressive speed makes the first round easier to enter.
|
||||
When it is on, the first round starts slower, then gradually increases to your selected speed.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Exhale normally and hold.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
The center number keeps counting. Circle mode adds layered progress lines.
|
||||
|
||||
Release when your body asks for air.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inhale fully and hold for about 15 seconds.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Then exhale and begin the next round.
|
||||
Over time, each round may feel deeper.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -494,3 +490,90 @@ Delete this round? This cannot be undone.
|
||||
[delete_button]
|
||||
Delete
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -397,21 +397,20 @@ Nunca la use mientras conduce,
|
||||
de pie o en el agua.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Simplemente siga 4 pasos:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respire rítmicamente.
|
||||
2. Exhale y retenga.
|
||||
3. Inhale profundamente y retenga.
|
||||
4. Exhale y repita.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Use el icono de llave %i para ajustar rondas, respiraciones, velocidad y pausas.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Llene sus pulmones completamente, luego deje que el respiración fluya hacia afuera.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use este control deslizante para establecer el ritmo del círculo de respiración.
|
||||
|
||||
Encuentre un ritmo que se sienta natural para usted.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La velocidad progresiva hace que la primera ronda sea más fácil de empezar.
|
||||
@@ -419,17 +418,14 @@ La velocidad progresiva hace que la primera ronda sea más fácil de empezar.
|
||||
Cuando está activada, la primera ronda comienza en velocidad 1 durante las primeras 5 respiraciones y luego aumenta gradualmente hasta la velocidad elegida.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Después de la ronda de respiración,
|
||||
exhale normalmente y retenga.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Suelte cuando su cuerpo pida
|
||||
aire. No lo fuerce.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inhale completamente y retenga unos 15 segundos.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Luego exhale y comience la siguiente ronda.
|
||||
Con el tiempo, cada ronda puede sentirse más profunda.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
OMITIR
|
||||
@@ -494,3 +490,90 @@ Horizontal
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -397,21 +397,20 @@ Ne l'utilisez jamais en conduisant,
|
||||
debout ou dans l'eau.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Suivez simplement 4 étapes :
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respirez en rythme.
|
||||
2. Expirez et retenez.
|
||||
3. Inspirez profondément et retenez.
|
||||
4. Expirez et répétez.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Utilisez l'icône de clé %i pour régler les cycles, respirations, vitesse et pauses.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Remplissez complètement vos poumons, puis laissez le souffle sortir.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Utilisez ce curseur pour régler le rythme du cercle de respiration.
|
||||
|
||||
Trouvez un rythme naturel pour vous.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La vitesse progressive rend le premier cycle plus facile à commencer.
|
||||
@@ -419,17 +418,14 @@ La vitesse progressive rend le premier cycle plus facile à commencer.
|
||||
Quand elle est activée, le premier cycle commence à la vitesse 1 pendant les 5 premières respirations, puis augmente progressivement jusqu'à la vitesse choisie.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Après le cycle de respiration,
|
||||
expirez normalement et retenez.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Relâchez quand votre corps demande
|
||||
de l'air. Ne forcez pas.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspirez complètement et retenez environ 15 secondes.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Puis expirez et commencez le cycle suivant.
|
||||
Avec le temps, chaque cycle peut sembler plus profond.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -494,3 +490,90 @@ Paysage
|
||||
[orientation_sensor]
|
||||
Capteur
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -397,21 +397,20 @@ Jangan gunakan saat mengemudi,
|
||||
berdiri, atau di dalam air.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Ikuti 4 langkah sederhana:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Bernapas secara ritmis.
|
||||
2. Buang napas dan tahan.
|
||||
3. Tarik napas dalam dan tahan.
|
||||
4. Buang napas dan ulangi.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Gunakan ikon kunci pas %i untuk menyesuaikan ronde, nafas, kecepatan, dan jeda.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Isi paru-paru Anda sepenuhnya, lalu biarkan napas keluar.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Gunakan slider ini untuk mengatur kecepatan lingkaran pernapasan.
|
||||
|
||||
Temukan ritme yang terasa alami bagi Anda.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
Kecepatan progresif membuat ronde pertama lebih mudah dimulai.
|
||||
@@ -419,17 +418,14 @@ Kecepatan progresif membuat ronde pertama lebih mudah dimulai.
|
||||
Saat aktif, ronde pertama dimulai pada kecepatan 1 untuk 5 nafas pertama, lalu bertambah hingga kecepatan yang dipilih.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Setelah ronde pernapasan,
|
||||
buang napas secara normal dan tahan.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Lepaskan saat tubuh Anda
|
||||
meminta udara. Jangan dipaksa.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Tarik napas sepenuhnya dan tahan sekitar 15 detik.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Lalu buang napas dan mulai ronde berikutnya.
|
||||
Seiring waktu, setiap ronde mungkin terasa lebih dalam.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
LEWATI
|
||||
@@ -494,3 +490,90 @@ Lanskap
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -413,21 +413,20 @@ Non usarla mai mentre guidi,
|
||||
in piedi o in acqua.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Segui semplicemente 4 passi:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respira ritmicamente.
|
||||
2. Espira e trattieni.
|
||||
3. Inspira profondamente e trattieni.
|
||||
4. Espira e ripeti.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Usa l'icona ingranaggio %i per regolare round, respiri, velocità e pause.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Riempi completamente i polmoni, poi lascia uscire il respiro.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Usa questo slider per impostare il ritmo del cerchio respiratorio.
|
||||
|
||||
Trova un ritmo che ti sembri naturale.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
La velocità progressiva rende il primo round più facile da affrontare.
|
||||
@@ -435,17 +434,14 @@ La velocità progressiva rende il primo round più facile da affrontare.
|
||||
Quando è attiva, il primo round inizia più lentamente, poi aumenta gradualmente fino alla velocità selezionata.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Espira normalmente e trattieni.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Il numero centrale continua a contare. La modalità cerchio aggiunge linee di progresso sovrapposte.
|
||||
|
||||
Rilascia quando il corpo richiede aria.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspira completamente e trattieni per circa 15 secondi.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Poi espira e inizia il prossimo round.
|
||||
Col tempo, ogni round potrebbe sembrare più profondo.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SALTA
|
||||
@@ -492,3 +488,90 @@ Elimina
|
||||
[meditation_music_attribution]
|
||||
Musica di Elijah_K.
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+101
-12
@@ -399,31 +399,33 @@ ON
|
||||
立っているとき、水中では行わないでください。
|
||||
---
|
||||
[tutorial_step_method]
|
||||
次の 4 つの手順に従います。
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. リズミカルに呼吸します。
|
||||
2. 吐いて止めます。
|
||||
3. 深く吸って止めます。
|
||||
4. 吐いて繰り返します。
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
歯車アイコン %i でラウンド数、呼吸数、速度、一時停止を調整できます。
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
肺をいっぱいに満たしてから、息を自然に吐き出します。
|
||||
Breathe in and out 30 times.
|
||||
|
||||
このスライダーで呼吸のテンポを設定します。
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
段階的速度は、最初のラウンドに入りやすくします。
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
呼吸ラウンドの後、
|
||||
息を吐いて止めます。
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
吸う必要を感じるまで止めます。
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
深く吸って、約 15 秒止めます。
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
スキップ
|
||||
@@ -488,3 +490,90 @@ Inner Breeze データ書き出し
|
||||
[orientation_sensor]
|
||||
センサー
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -412,21 +412,20 @@ In / Out
|
||||
운전 중, 서 있거나 물속에서는 사용하지 마세요.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
다음 4단계를 따르세요:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. 리듬적으로 호흡합니다.
|
||||
2. 내뱉고 참습니다.
|
||||
3. 깊게 들이마시고 참습니다.
|
||||
4. 내뱉고 반복합니다.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
톱니바퀴 아이콘 %i을 사용하여 라운드, 호흡, 속도 및 일시정지를 조정할 수 있습니다.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
폐를 완전히 채운 후 자연스럽게 내뱉으세요.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
이 슬라이더로 호흡 원의 속도를 설정합니다.
|
||||
|
||||
자연스러운 리듬을 찾아보세요.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
점진적 속도는 첫 라운드를 쉽게 시작할 수 있게 해줍니다.
|
||||
@@ -434,17 +433,14 @@ In / Out
|
||||
켜면 첫 라운드가 느리게 시작된 후 점차 선택한 속도까지 증가합니다.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
자연스럽게 내뱉고 참습니다.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
중앙 숫자가 계속 카운트됩니다. 원형 모드는 여러 진행 막대를 표시합니다.
|
||||
|
||||
몸이 공기를 필요로 할 때 놓으세요.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
완전히 들이마시고 약 15초간 참으세요.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
그 후 내뱉고 다음 라운드를 시작하세요.
|
||||
시간이 지날수록 각 라운드가 더 깊어질 수 있습니다.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
건너뛰기
|
||||
@@ -491,3 +487,90 @@ Inner Breeze 데이터 내보내기
|
||||
[meditation_music_attribution]
|
||||
음악: Elijah_K.
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+100
-17
@@ -397,21 +397,20 @@ Nunca use enquanto dirige,
|
||||
em pé ou na água.
|
||||
---
|
||||
[tutorial_step_method]
|
||||
Basta seguir 4 passos:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. Respire ritmicamente.
|
||||
2. Expire e segure.
|
||||
3. Inspire profundamente e segure.
|
||||
4. Expire e repita.
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
Use o ícone de chave inglesa %i para ajustar rodadas, respirações, velocidade e pausas.
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
Encha totalmente os pulmões e deixe o ar sair.
|
||||
Breathe in and out 30 times.
|
||||
|
||||
Use este controle para definir o ritmo do círculo de respiração.
|
||||
|
||||
Encontre um ritmo que pareça natural para você.
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
A velocidade progressiva torna a primeira rodada mais fácil de começar.
|
||||
@@ -419,17 +418,14 @@ A velocidade progressiva torna a primeira rodada mais fácil de começar.
|
||||
Quando ativada, a primeira rodada começa na velocidade 1 nas primeiras 5 respirações e depois aumenta gradualmente até a velocidade escolhida.
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
Depois da rodada de respiração,
|
||||
expire normalmente e segure.
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
Solte quando seu corpo pedir
|
||||
ar. Não force.
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
Inspire totalmente e segure por cerca de 15 segundos.
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Depois expire e comece a próxima rodada.
|
||||
Com o tempo, cada rodada pode parecer mais profunda.
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
SKIP
|
||||
@@ -494,3 +490,90 @@ Paisagem
|
||||
[orientation_sensor]
|
||||
Sensor
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+101
-12
@@ -397,31 +397,33 @@ Deleted %lld sessions
|
||||
站立或水中时进行。
|
||||
---
|
||||
[tutorial_step_method]
|
||||
按照 4 个步骤进行:
|
||||
Simply follow 3 steps:
|
||||
|
||||
1. 有节奏地呼吸。
|
||||
2. 呼气并屏息。
|
||||
3. 深吸气并屏息。
|
||||
4. 呼气并重复。
|
||||
1. Breathe in and out 30 times.
|
||||
2. Exhale and hold.
|
||||
3. When you feel the urge to breathe, breathe in and hold for 15 seconds.
|
||||
|
||||
使用齿轮图标 %i 调整轮次、呼吸次数、速度和暂停时间。
|
||||
Exhale, then repeat the process.
|
||||
|
||||
Use the wrench icon %i to adjust rounds, breaths, speed, and pauses.
|
||||
---
|
||||
[tutorial_step_breathe]
|
||||
充分充满肺部,然后让呼吸自然流出。
|
||||
Breathe in and out 30 times.
|
||||
|
||||
使用这个滑块设置呼吸圆的节奏。
|
||||
Find a rhythm that feels natural to you: steady and quick, while still breathing fully.
|
||||
---
|
||||
[tutorial_step_progressive_speed]
|
||||
递进速度会让第一轮更容易进入。
|
||||
---
|
||||
[tutorial_step_exhale_hold]
|
||||
完成一轮呼吸后,
|
||||
呼气并屏住。
|
||||
After 30 breaths, exhale and hold as long as you can.
|
||||
|
||||
屏息到需要吸气为止。
|
||||
When you feel the urge to breathe, press the BREATH button.
|
||||
---
|
||||
[tutorial_step_inhale_hold]
|
||||
充分吸气并屏住约 15 秒。
|
||||
Inhale fully and hold for 15 seconds.
|
||||
|
||||
Exhale, and the next round will begin.
|
||||
---
|
||||
[tutorial_skip_button]
|
||||
跳过
|
||||
@@ -486,3 +488,90 @@ Inner Breeze 数据导出
|
||||
[orientation_sensor]
|
||||
传感器
|
||||
---
|
||||
[back_button]
|
||||
Back
|
||||
---
|
||||
[close_button]
|
||||
Close
|
||||
---
|
||||
[sync_account_title]
|
||||
Sync Account
|
||||
---
|
||||
[sync_configure_account_button]
|
||||
Configure Account
|
||||
---
|
||||
[sync_create_account_button]
|
||||
Create Account
|
||||
---
|
||||
[sync_account_created]
|
||||
Sync account created
|
||||
---
|
||||
[sync_account_create_failed]
|
||||
Could not create sync account
|
||||
---
|
||||
[sync_liboqs_unavailable]
|
||||
liboqs is not built for this target.
|
||||
---
|
||||
[sync_public_id_label]
|
||||
Public ID
|
||||
---
|
||||
[sync_copy_id_button]
|
||||
Copy ID
|
||||
---
|
||||
[sync_public_id_copied]
|
||||
Public ID copied
|
||||
---
|
||||
[sync_backup_key_button]
|
||||
Backup Key
|
||||
---
|
||||
[sync_remote_label]
|
||||
Remote
|
||||
---
|
||||
[sync_connect_button]
|
||||
Connect
|
||||
---
|
||||
[sync_connected_button]
|
||||
Connected
|
||||
---
|
||||
[sync_server_url_invalid]
|
||||
Use https:// or loopback like localhost:8080
|
||||
---
|
||||
[sync_server_saved]
|
||||
Sync server saved
|
||||
---
|
||||
[sync_connected]
|
||||
Remote sync complete
|
||||
---
|
||||
[sync_failed]
|
||||
Remote sync failed
|
||||
---
|
||||
[sync_unavailable]
|
||||
Remote sync is not available on this platform
|
||||
---
|
||||
[sync_no_account]
|
||||
Create an account before syncing
|
||||
---
|
||||
[sync_auth_failed]
|
||||
Remote rejected this sync account
|
||||
---
|
||||
[sync_backup_warning]
|
||||
Save this private key somewhere you control. Anyone with it can claim this sync account.
|
||||
---
|
||||
[sync_backup_title]
|
||||
Backup Sync Key
|
||||
---
|
||||
[sync_save_key_file_button]
|
||||
Save .key File
|
||||
---
|
||||
[sync_save_key_dialog_title]
|
||||
Save Sync Key
|
||||
---
|
||||
[sync_private_key_backup_saved]
|
||||
Private key backup saved
|
||||
---
|
||||
[sync_private_key_backup_failed]
|
||||
Could not save private key backup
|
||||
---
|
||||
[sync_private_key_backup_cancelled]
|
||||
Private key backup cancelled
|
||||
---
|
||||
+32
-4
@@ -8,6 +8,7 @@
|
||||
#include "practices/practice_registry.h"
|
||||
#include "device_preferences.h"
|
||||
#include "storage.h"
|
||||
#include "sync_client.h"
|
||||
#include "theme.h"
|
||||
#include "version.h"
|
||||
#include "flint_clip.h"
|
||||
@@ -36,6 +37,8 @@ void set_global_inbe_app(InbeApp *app);
|
||||
|
||||
#define INBE_DEFAULT_WIDTH 320
|
||||
#define INBE_DEFAULT_HEIGHT 560
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_ENABLED_KEY "sync_enabled"
|
||||
|
||||
InbeConfig config = {
|
||||
.title = "Inner Breeze",
|
||||
@@ -45,6 +48,29 @@ InbeConfig config = {
|
||||
.title_custom = 1
|
||||
};
|
||||
|
||||
int
|
||||
inbe_app_auto_sync(InbeApp *app)
|
||||
{
|
||||
const char *saved_url;
|
||||
char url[256];
|
||||
InbeSyncClientResult result;
|
||||
|
||||
if(app == NULL)
|
||||
return 0;
|
||||
if(inbe_storage_get_setting_int(INBE_SYNC_ENABLED_KEY, 0) == 0)
|
||||
return 0;
|
||||
saved_url = inbe_storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
if(!inbe_sync_client_normalize_url(saved_url, url, sizeof(url)))
|
||||
return 0;
|
||||
result = inbe_sync_client_sync(url);
|
||||
if(result != INBE_SYNC_CLIENT_OK) {
|
||||
TraceLog(LOG_WARNING, "INBE: auto sync failed result=%d", result);
|
||||
return 0;
|
||||
}
|
||||
TraceLog(LOG_INFO, "INBE: auto sync complete");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int view_width = INBE_DEFAULT_WIDTH;
|
||||
int view_height = INBE_DEFAULT_HEIGHT;
|
||||
/* Theme colors are now accessed via theme accessor functions */
|
||||
@@ -669,6 +695,10 @@ inbe_app_init(void *vapp) {
|
||||
app->settings_dirty = 0;
|
||||
app->settings_save_delay_ticks = 0;
|
||||
app->settings_tab = SETTINGS_TAB_DEVICE;
|
||||
app->settings_data_view = 0;
|
||||
app->sync_server_url_cursor = 0;
|
||||
app->sync_server_url_focused = 0;
|
||||
app->sync_server_url[0] = '\0';
|
||||
app->practice_config_tab = 0;
|
||||
app->practice_coming_soon_ticks = 0;
|
||||
app->habit_edit_active = 0;
|
||||
@@ -725,6 +755,7 @@ inbe_app_init(void *vapp) {
|
||||
app->meditation.duration_seconds = 0;
|
||||
app->meditation.remaining_seconds = 0;
|
||||
app->meditation.frame_ticks = 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -845,10 +876,7 @@ updateapp(InbeApp *app)
|
||||
if(app->practice_coming_soon_ticks > 0)
|
||||
app->practice_coming_soon_ticks--;
|
||||
|
||||
if(IsKeyPressed(KEY_BACK) ||
|
||||
(IsKeyPressed(KEY_BACKSPACE) &&
|
||||
!(app->inbe.screen == InbeScreenHabitEdit && app->habit_edit_active) &&
|
||||
!(app->inbe.screen == InbeScreenHabitSessionEdit && app->habit_session_edit_active))) {
|
||||
if(IsKeyPressed(KEY_BACK)) {
|
||||
if(app->modal.active) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
|
||||
@@ -61,6 +61,7 @@ typedef enum {
|
||||
UIModalEditProgressiveStartSpeed,
|
||||
UIModalMeditationNetworkError,
|
||||
UIModalConfirmImportDataSettings,
|
||||
UIModalSyncAccountBackup,
|
||||
} UIModalType;
|
||||
|
||||
typedef struct {
|
||||
@@ -170,6 +171,10 @@ struct InbeApp {
|
||||
int settings_dirty;
|
||||
int settings_save_delay_ticks;
|
||||
int settings_tab;
|
||||
int settings_data_view;
|
||||
int sync_server_url_cursor;
|
||||
int sync_server_url_focused;
|
||||
char sync_server_url[256];
|
||||
int device_picker_open;
|
||||
int device_picker_scroll;
|
||||
int fullscreen_enabled;
|
||||
@@ -213,6 +218,13 @@ struct InbeApp {
|
||||
Color habit_edit_color;
|
||||
int habit_edit_sync_mode;
|
||||
int habit_edit_sync_activity;
|
||||
int habit_edit_counter_enabled;
|
||||
int habit_counter_press_day;
|
||||
int habit_counter_press_index;
|
||||
int habit_counter_press_frames;
|
||||
int habit_counter_press_long_done;
|
||||
int habit_counter_press_start_x;
|
||||
int habit_counter_press_start_y;
|
||||
int advanced_session_controls;
|
||||
int hold_display_mode;
|
||||
int exercise_type;
|
||||
@@ -234,6 +246,7 @@ struct InbeApp {
|
||||
void inbe_app_init(void *app);
|
||||
void inbe_app_update_draw(void *app, Rectangle viewport);
|
||||
void inbe_app_destroy(void *app);
|
||||
int inbe_app_auto_sync(InbeApp *app);
|
||||
void app_play_sound(InbeApp *app, Sound sound, float scale);
|
||||
Texture2D app_load_asset_texture(const char *name);
|
||||
void app_unload_texture(Texture2D texture);
|
||||
|
||||
+3
-3
@@ -2,8 +2,8 @@
|
||||
#define INBE_VERSION_H
|
||||
|
||||
#define INBE_VERSION_MAJOR 1
|
||||
#define INBE_VERSION_MINOR 3
|
||||
#define INBE_VERSION_PATCH 4
|
||||
#define INBE_VERSION_STRING "1.3.4"
|
||||
#define INBE_VERSION_MINOR 4
|
||||
#define INBE_VERSION_PATCH 0
|
||||
#define INBE_VERSION_STRING "1.4.0"
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,93 @@
|
||||
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
|
||||
static jclass
|
||||
android_share_helper_class(JNIEnv *env, jobject activity)
|
||||
{
|
||||
jclass activity_class;
|
||||
jmethodID get_class_loader;
|
||||
jobject class_loader;
|
||||
jclass class_loader_class;
|
||||
jmethodID load_class;
|
||||
jstring class_name;
|
||||
jclass share_helper_class;
|
||||
|
||||
activity_class = (*env)->FindClass(env, "android/app/Activity");
|
||||
if(!activity_class)
|
||||
return NULL;
|
||||
get_class_loader = (*env)->GetMethodID(env, activity_class, "getClassLoader",
|
||||
"()Ljava/lang/ClassLoader;");
|
||||
if(!get_class_loader)
|
||||
return NULL;
|
||||
class_loader = (*env)->CallObjectMethod(env, activity, get_class_loader);
|
||||
if(!class_loader)
|
||||
return NULL;
|
||||
class_loader_class = (*env)->FindClass(env, "java/lang/ClassLoader");
|
||||
if(!class_loader_class)
|
||||
return NULL;
|
||||
load_class = (*env)->GetMethodID(env, class_loader_class, "loadClass",
|
||||
"(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
if(!load_class)
|
||||
return NULL;
|
||||
class_name = (*env)->NewStringUTF(env, "xyz.waozi.inbe.ShareHelper");
|
||||
share_helper_class = (jclass)(*env)->CallObjectMethod(env, class_loader, load_class, class_name);
|
||||
(*env)->DeleteLocalRef(env, class_name);
|
||||
(*env)->DeleteLocalRef(env, class_loader);
|
||||
return share_helper_class;
|
||||
}
|
||||
|
||||
int
|
||||
android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type)
|
||||
{
|
||||
struct android_app *app = GetAndroidApp();
|
||||
ANativeActivity *native_activity;
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jclass share_helper_class;
|
||||
jmethodID method;
|
||||
jbyteArray jarr;
|
||||
jstring jname;
|
||||
jstring jmime;
|
||||
jstring jtitle;
|
||||
|
||||
if(app == NULL || app->activity == NULL || data == NULL || data_size == 0 ||
|
||||
filename == NULL || filename[0] == '\0')
|
||||
return 0;
|
||||
|
||||
native_activity = app->activity;
|
||||
jvm = native_activity->vm;
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK)
|
||||
return 0;
|
||||
|
||||
share_helper_class = android_share_helper_class(env, native_activity->clazz);
|
||||
if(!share_helper_class) {
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 0;
|
||||
}
|
||||
method = (*env)->GetStaticMethodID(env, share_helper_class, "shareFile",
|
||||
"(Landroid/app/Activity;[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
if(!method) {
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
jarr = (*env)->NewByteArray(env, data_size);
|
||||
(*env)->SetByteArrayRegion(env, jarr, 0, data_size, (const jbyte *)data);
|
||||
jname = (*env)->NewStringUTF(env, filename);
|
||||
jmime = (*env)->NewStringUTF(env, mime_type != NULL ? mime_type : "application/octet-stream");
|
||||
jtitle = (*env)->NewStringUTF(env, locale_get("share_sheet_title"));
|
||||
(*env)->CallStaticVoidMethod(env, share_helper_class, method, native_activity->clazz,
|
||||
jarr, jname, jmime, jtitle);
|
||||
|
||||
(*env)->DeleteLocalRef(env, jarr);
|
||||
(*env)->DeleteLocalRef(env, jname);
|
||||
(*env)->DeleteLocalRef(env, jmime);
|
||||
(*env)->DeleteLocalRef(env, jtitle);
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int android_share_export(const char *filename)
|
||||
{
|
||||
struct android_app *app;
|
||||
@@ -163,4 +250,12 @@ int android_share_export(const char *filename) {
|
||||
(void)filename;
|
||||
return 0;
|
||||
}
|
||||
int android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type) {
|
||||
(void)data;
|
||||
(void)data_size;
|
||||
(void)filename;
|
||||
(void)mime_type;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -1,8 +1,12 @@
|
||||
#ifndef ANDROID_SHARE_H
|
||||
#define ANDROID_SHARE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* Export data using Android share sheet
|
||||
* Returns: 1 on success (share sheet shown), 0 on failure */
|
||||
int android_share_export(const char *filename);
|
||||
int android_share_bytes(const unsigned char *data, size_t data_size, const char *filename,
|
||||
const char *mime_type);
|
||||
|
||||
#endif
|
||||
@@ -58,6 +58,7 @@ meditation_finish(InbeApp *app)
|
||||
if(data_save_session_path_for_activity(&session_duration, 1, 0, EXERCISE_MEDITATION,
|
||||
NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
app_play_sound(app, app->bell_sound, 1.0f);
|
||||
@@ -97,6 +98,7 @@ meditation_save_elapsed(InbeApp *app)
|
||||
return 0;
|
||||
if(data_save_session_path_for_activity(&elapsed, 1, 0, EXERCISE_MEDITATION, NULL, 0)) {
|
||||
sync_habits_for_activity(app, EXERCISE_MEDITATION);
|
||||
inbe_app_auto_sync(app);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -18,7 +18,6 @@ extern int view_height;
|
||||
static const char *const TUTORIAL_KEYS[] = {
|
||||
"tutorial_step_intro",
|
||||
"tutorial_step_method",
|
||||
"tutorial_step_progressive_speed",
|
||||
"tutorial_step_breathe",
|
||||
"tutorial_step_exhale_hold",
|
||||
"tutorial_step_inhale_hold"
|
||||
@@ -104,31 +103,27 @@ manual_tutorial_content_height(InbeApp *app, int step, int content_w, int body_f
|
||||
} else if(step == 1) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 1, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(68);
|
||||
if(app->inbe.progressive_speed)
|
||||
actual_content_h += flint_px(66);
|
||||
} else if(step == 3) {
|
||||
int preview_span;
|
||||
int preview_rmax;
|
||||
int slider_h = flint_px(40);
|
||||
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font) + flint_px(20);
|
||||
actual_content_h += tutorial_paragraph_height(app, 2, content_w, body_font) + flint_px(20);
|
||||
preview_span = (content_w < flint_px(132)) ? content_w : flint_px(132);
|
||||
preview_rmax = preview_span / 2;
|
||||
if(preview_rmax < flint_px(60)) preview_rmax = flint_px(60);
|
||||
if(preview_rmax > flint_px(120)) preview_rmax = flint_px(120);
|
||||
actual_content_h += flint_px(40) + (int)((float)preview_rmax * 0.72f) + flint_px(14);
|
||||
actual_content_h += slider_h + flint_px(8);
|
||||
} else if(step == 4) {
|
||||
} else if(step == 3) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
|
||||
actual_content_h += flint_px(26) + flint_px(36) + flint_px(20);
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24);
|
||||
actual_content_h += tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
actual_content_h += hold_preview_extent * 2 + flint_px(24) +
|
||||
flint_px(42) + flint_px(18);
|
||||
actual_content_h += tutorial_paragraph_height(app, 3, content_w, body_font);
|
||||
} else {
|
||||
actual_content_h += flint_px(200) + flint_px(22) +
|
||||
tutorial_paragraph_height(app, 5, content_w, body_font);
|
||||
actual_content_h += flint_px(80) +
|
||||
tutorial_paragraph_height(app, 4, content_w, body_font);
|
||||
}
|
||||
|
||||
return actual_content_h;
|
||||
@@ -195,10 +190,9 @@ whm_manual_draw(InbeApp *app)
|
||||
|
||||
switch(step) {
|
||||
case 1: title = locale_get("tutorial_method_title"); break;
|
||||
case 2: title = locale_get("tutorial_progressive_speed_title"); break;
|
||||
case 3: title = locale_get("tutorial_step1_title"); break;
|
||||
case 4: title = locale_get("tutorial_step2_title"); break;
|
||||
case 5: title = locale_get("tutorial_step3_title"); break;
|
||||
case 2: title = locale_get("tutorial_step1_title"); break;
|
||||
case 3: title = locale_get("tutorial_step2_title"); break;
|
||||
case 4: title = locale_get("tutorial_step3_title"); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -267,27 +261,8 @@ whm_manual_draw(InbeApp *app)
|
||||
} else if(step == 1) {
|
||||
draw_tutorial_paragraph(app, 1, content_x, &y, content_w, body_font);
|
||||
} else if(step == 2) {
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(18);
|
||||
{
|
||||
int progressive_speed = app->inbe.progressive_speed;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
flint_text_draw(locale_get("progressive_speed_label"), content_x, y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
if(ui_draw_toggle_switch(content_x, y, toggle_w, toggle_h,
|
||||
&progressive_speed, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.progressive_speed = progressive_speed;
|
||||
app->settings_preview.progressive_speed = progressive_speed;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += toggle_h + flint_px(20);
|
||||
}
|
||||
} else if(step == 3) {
|
||||
int speed = app->inbe.speed_level;
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
draw_tutorial_paragraph(app, 2, content_x, &y, content_w, body_font);
|
||||
y += flint_px(20); /* Increased spacing between text and circle */
|
||||
|
||||
update_preview_bounds(&app->settings_preview, content_w, flint_px(132));
|
||||
@@ -314,21 +289,19 @@ whm_manual_draw(InbeApp *app)
|
||||
app->settings_preview.progressive_speed = 0;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
} else if(step == 4) {
|
||||
} else if(step == 3) {
|
||||
int hold_preview_radius = flint_px(54);
|
||||
int hold_preview_extent = hold_preview_radius + flint_px(8) + flint_px(5);
|
||||
flint_text_draw(locale_get("hold_display_label"), content_x, y, flint_ui_font(), theme_get_text());
|
||||
y += flint_px(26);
|
||||
draw_hold_display_mode_selector(app, content_x, y, content_w);
|
||||
y += flint_px(36) + flint_px(20) + hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, content_x + content_w / 2, y, hold_preview_radius);
|
||||
int breath_button_hover = 0;
|
||||
int center_x = content_x + content_w / 2;
|
||||
y += hold_preview_extent;
|
||||
draw_tutorial_hold_preview(app, center_x, y, hold_preview_radius);
|
||||
y += hold_preview_extent + flint_px(24);
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
ui_draw_text_btn(center_x, y, locale_get("breath_button"), &breath_button_hover);
|
||||
y += flint_px(42) + flint_px(18);
|
||||
draw_tutorial_paragraph(app, 3, content_x, &y, content_w, body_font);
|
||||
} else {
|
||||
int img_h = flint_px(200);
|
||||
ui_draw_tutorial_image(app->whm.image_2, "practices/whm/2.jpg", content_x, y, content_w, img_h);
|
||||
y += img_h + flint_px(22);
|
||||
draw_tutorial_paragraph(app, 5, content_x, &y, content_w, body_font);
|
||||
draw_tutorial_paragraph(app, 4, content_x, &y, content_w, body_font);
|
||||
}
|
||||
}
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
|
||||
@@ -280,6 +280,7 @@ session_ensure_results_saved(InbeApp *app)
|
||||
app->results_path, sizeof(app->results_path))) {
|
||||
app->results_saved = 1;
|
||||
sync_habits_for_activity(app, app->exercise_type);
|
||||
inbe_app_auto_sync(app);
|
||||
TraceLog(LOG_INFO, "INBE: session saved successfully");
|
||||
return 1;
|
||||
}
|
||||
|
||||
+436
-36
@@ -21,9 +21,11 @@ extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
HABIT_WEEKLY_INITIAL_DAYS = 7,
|
||||
HABIT_WEEKLY_LOAD_DAYS = 7,
|
||||
HABIT_WEEKLY_MAX_DAYS = INBE_HABIT_MAX_DAYS
|
||||
HABIT_WEEKLY_MONTH_DAYS = 31,
|
||||
HABIT_WEEKLY_INITIAL_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_LOAD_DAYS = HABIT_WEEKLY_MONTH_DAYS,
|
||||
HABIT_WEEKLY_MAX_DAYS = 36500,
|
||||
HABIT_COUNTER_LONG_PRESS_FRAMES = 30
|
||||
};
|
||||
|
||||
/* Helper functions */
|
||||
@@ -43,7 +45,7 @@ copy_text(char *dst, size_t dst_size, const char *src)
|
||||
static int
|
||||
habit_find_day(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
if(habit == NULL)
|
||||
if(habit == NULL || habit->days == NULL)
|
||||
return -1;
|
||||
for(int i = 0; i < habit->day_count; i++) {
|
||||
if(habit->days[i].day_index == day_index)
|
||||
@@ -52,6 +54,112 @@ habit_find_day(const InbeHabit *habit, int day_index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_counting_enabled(const InbeHabit *habit)
|
||||
{
|
||||
return habit != NULL &&
|
||||
(habit->counter_enabled ||
|
||||
(habit->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
|
||||
habit->sync_activity != 0));
|
||||
}
|
||||
|
||||
static int
|
||||
habit_counter_day_action(InbeApp *app, int habit_index, int day_index,
|
||||
int x, int y, int w, int h, int disabled,
|
||||
int allow_left_increment)
|
||||
{
|
||||
Vector2 mouse = GetScreenToWorld2D(GetMousePosition(), app->camera);
|
||||
Rectangle bounds = {(float)x, (float)y, (float)w, (float)h};
|
||||
int inside = !disabled && CheckCollisionPointRec(mouse, bounds);
|
||||
int same = app->habit_counter_press_index == habit_index &&
|
||||
app->habit_counter_press_day == day_index;
|
||||
|
||||
if(disabled)
|
||||
return 0;
|
||||
if(inside && IsMouseButtonReleased(MOUSE_BUTTON_RIGHT))
|
||||
return -1;
|
||||
|
||||
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && inside) {
|
||||
app->habit_counter_press_index = habit_index;
|
||||
app->habit_counter_press_day = day_index;
|
||||
app->habit_counter_press_frames = 0;
|
||||
app->habit_counter_press_long_done = 0;
|
||||
app->habit_counter_press_start_x = (int)mouse.x;
|
||||
app->habit_counter_press_start_y = (int)mouse.y;
|
||||
same = 1;
|
||||
}
|
||||
|
||||
if(same && IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
int dx = (int)mouse.x - app->habit_counter_press_start_x;
|
||||
int dy = (int)mouse.y - app->habit_counter_press_start_y;
|
||||
int threshold = flint_px(8);
|
||||
|
||||
if(dx > threshold || dx < -threshold || dy > threshold || dy < -threshold) {
|
||||
app->habit_counter_press_day = 0;
|
||||
app->habit_counter_press_index = -1;
|
||||
return 0;
|
||||
}
|
||||
app->habit_counter_press_frames++;
|
||||
if(inside && !app->habit_counter_press_long_done &&
|
||||
app->habit_counter_press_frames >= HABIT_COUNTER_LONG_PRESS_FRAMES) {
|
||||
app->habit_counter_press_long_done = 1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(same && IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
int action;
|
||||
if(inside && app->habit_counter_press_long_done)
|
||||
action = -2;
|
||||
else
|
||||
action = inside && allow_left_increment ? 1 : 0;
|
||||
app->habit_counter_press_day = 0;
|
||||
app->habit_counter_press_index = -1;
|
||||
app->habit_counter_press_frames = 0;
|
||||
app->habit_counter_press_long_done = 0;
|
||||
return action;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_habit_reserve_days(InbeHabit *habit, int capacity)
|
||||
{
|
||||
InbeHabitDay *days;
|
||||
int new_capacity;
|
||||
|
||||
if(habit == NULL || capacity <= habit->day_capacity)
|
||||
return habit != NULL;
|
||||
new_capacity = habit->day_capacity > 0 ? habit->day_capacity : 16;
|
||||
while(new_capacity < capacity) {
|
||||
if(new_capacity > 1073741823 / 2)
|
||||
return 0;
|
||||
new_capacity *= 2;
|
||||
}
|
||||
days = realloc(habit->days, (size_t)new_capacity * sizeof(*days));
|
||||
if(days == NULL)
|
||||
return 0;
|
||||
memset(days + habit->day_capacity, 0,
|
||||
(size_t)(new_capacity - habit->day_capacity) * sizeof(*days));
|
||||
habit->days = days;
|
||||
habit->day_capacity = new_capacity;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habits_free(InbeHabits *habits)
|
||||
{
|
||||
if(habits == NULL)
|
||||
return;
|
||||
for(int i = 0; i < INBE_HABIT_MAX; i++) {
|
||||
free(habits->items[i].days);
|
||||
habits->items[i].days = NULL;
|
||||
habits->items[i].day_count = 0;
|
||||
habits->items[i].day_capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Core habits functions from habits.c */
|
||||
int
|
||||
inbe_habits_today_index(void)
|
||||
@@ -67,7 +175,19 @@ int
|
||||
inbe_habit_completed_day(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
int index = habit_find_day(habit, day_index);
|
||||
return index >= 0 && habit->days[index].completed;
|
||||
return index >= 0 &&
|
||||
(habit->days[index].completed || habit->days[index].count > 0);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_habit_day_count(const InbeHabit *habit, int day_index)
|
||||
{
|
||||
int index = habit_find_day(habit, day_index);
|
||||
if(index < 0)
|
||||
return 0;
|
||||
if(habit->days[index].count > 0)
|
||||
return habit->days[index].count;
|
||||
return habit->days[index].completed ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -93,10 +213,10 @@ inbe_habits_clear_days(InbeHabits *habits)
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
InbeHabit *habit = &habits->items[i];
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
if(habit->days[d].day_index > 0 || habit->days[d].completed)
|
||||
if(habit->days[d].day_index > 0 || habit->days[d].completed ||
|
||||
habit->days[d].count > 0)
|
||||
cleared++;
|
||||
}
|
||||
memset(habit->days, 0, sizeof(habit->days));
|
||||
habit->day_count = 0;
|
||||
}
|
||||
return cleared;
|
||||
@@ -123,6 +243,7 @@ inbe_habits_add_default_set(InbeHabits *habits)
|
||||
if(habits == NULL)
|
||||
return;
|
||||
|
||||
inbe_habits_free(habits);
|
||||
memset(habits, 0, sizeof(*habits));
|
||||
inbe_habits_add_seed(habits, "meditation", "Meditation", (Color){126, 183, 230, 255},
|
||||
habit_activity_mask_for(EXERCISE_WIM_HOF) |
|
||||
@@ -138,6 +259,7 @@ inbe_habits_delete(InbeHabits *habits, int index)
|
||||
if(habits == NULL || index < 0 || index >= habits->count)
|
||||
return;
|
||||
|
||||
free(habits->items[index].days);
|
||||
for(int i = index; i < habits->count - 1; i++)
|
||||
habits->items[i] = habits->items[i + 1];
|
||||
habits->count--;
|
||||
@@ -173,6 +295,7 @@ inbe_habits_add_custom(InbeHabits *habits, const char *name, Color color,
|
||||
habit->color.a = 255;
|
||||
habit->sync_mode = sync_mode;
|
||||
habit->sync_activity = sync_activity;
|
||||
habit->counter_enabled = sync_activity != 0;
|
||||
habits->selected = habits->count;
|
||||
habits->count++;
|
||||
inbe_habits_save(habits);
|
||||
@@ -195,6 +318,7 @@ inbe_habits_add_seed(InbeHabits *habits, const char *id, const char *name,
|
||||
habit->color = color;
|
||||
habit->sync_mode = INBE_HABIT_SYNC_ACTIVITIES;
|
||||
habit->sync_activity = activity_mask;
|
||||
habit->counter_enabled = 1;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -232,9 +356,37 @@ inbe_habit_set_day(InbeHabits *habits, int index, int day_index, int completed)
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].completed = completed != 0;
|
||||
} else if(completed && habit->day_count < INBE_HABIT_MAX_DAYS) {
|
||||
habit->days[existing_index].count = completed ? 1 : 0;
|
||||
} else if(completed && inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->days[habit->day_count].count = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_set_day_count(InbeHabits *habits, int index, int day_index, int count)
|
||||
{
|
||||
InbeHabit *habit;
|
||||
int existing_index;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
if(count < 0)
|
||||
count = 0;
|
||||
|
||||
habit = &habits->items[index];
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].count = count;
|
||||
habit->days[existing_index].completed = count > 0;
|
||||
} else if(count > 0 && inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].count = count;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
@@ -253,16 +405,31 @@ inbe_habit_toggle_day(InbeHabits *habits, int index, int day_index)
|
||||
habit = &habits->items[index];
|
||||
existing_index = habit_find_day(habit, day_index);
|
||||
if(existing_index >= 0) {
|
||||
habit->days[existing_index].completed = !habit->days[existing_index].completed;
|
||||
} else if(habit->day_count < INBE_HABIT_MAX_DAYS) {
|
||||
int completed = !(habit->days[existing_index].completed ||
|
||||
habit->days[existing_index].count > 0);
|
||||
habit->days[existing_index].completed = completed;
|
||||
habit->days[existing_index].count = completed ? 1 : 0;
|
||||
} else if(inbe_habit_reserve_days(habit, habit->day_count + 1)) {
|
||||
habit->days[habit->day_count].day_index = day_index;
|
||||
habit->days[habit->day_count].completed = 1;
|
||||
habit->days[habit->day_count].count = 1;
|
||||
habit->day_count++;
|
||||
}
|
||||
habits->selected = index;
|
||||
inbe_habits_save(habits);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_increment_day(InbeHabits *habits, int index, int day_index, int delta)
|
||||
{
|
||||
int count;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
count = inbe_habit_day_count(&habits->items[index], day_index) + delta;
|
||||
inbe_habit_set_day_count(habits, index, day_index, count);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_habit_toggle_today(InbeHabits *habits, int index)
|
||||
{
|
||||
@@ -367,6 +534,7 @@ habit_edit_begin_new(InbeApp *app)
|
||||
app->habit_edit_color = (Color){99, 196, 165, 255};
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_NONE;
|
||||
app->habit_edit_sync_activity = 0;
|
||||
app->habit_edit_counter_enabled = 0;
|
||||
app->inbe.screen = InbeScreenHabitEdit;
|
||||
}
|
||||
|
||||
@@ -386,6 +554,7 @@ habit_edit_begin(InbeApp *app, int index)
|
||||
app->habit_edit_color = app->habits.items[index].color;
|
||||
app->habit_edit_sync_mode = app->habits.items[index].sync_mode;
|
||||
app->habit_edit_sync_activity = app->habits.items[index].sync_activity;
|
||||
app->habit_edit_counter_enabled = habit_counting_enabled(&app->habits.items[index]);
|
||||
app->inbe.screen = InbeScreenHabitEdit;
|
||||
}
|
||||
|
||||
@@ -401,6 +570,7 @@ habit_edit_cancel(InbeApp *app)
|
||||
app->habit_edit_cursor = 0;
|
||||
app->habit_edit_focused = 0;
|
||||
app->habit_edit_text[0] = '\0';
|
||||
app->habit_edit_counter_enabled = 0;
|
||||
ui_focus_set_text_input_active(0);
|
||||
}
|
||||
|
||||
@@ -444,10 +614,16 @@ habit_edit_commit(InbeApp *app)
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_ACTIVITIES;
|
||||
else
|
||||
app->habit_edit_sync_mode = INBE_HABIT_SYNC_NONE;
|
||||
if(app->habit_edit_sync_activity != 0)
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
if(app->habit_edit_is_new) {
|
||||
inbe_habits_add_custom(&app->habits, text, app->habit_edit_color,
|
||||
app->habit_edit_sync_mode,
|
||||
app->habit_edit_sync_activity);
|
||||
int created = inbe_habits_add_custom(&app->habits, text, app->habit_edit_color,
|
||||
app->habit_edit_sync_mode,
|
||||
app->habit_edit_sync_activity);
|
||||
if(created >= 0 && created < app->habits.count) {
|
||||
app->habits.items[created].counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
inbe_habits_save(&app->habits);
|
||||
}
|
||||
} else {
|
||||
snprintf(app->habits.items[index].name,
|
||||
sizeof(app->habits.items[index].name), "%s", text);
|
||||
@@ -455,9 +631,11 @@ habit_edit_commit(InbeApp *app)
|
||||
app->habits.items[index].color.a = 255;
|
||||
app->habits.items[index].sync_mode = app->habit_edit_sync_mode;
|
||||
app->habits.items[index].sync_activity = app->habit_edit_sync_activity;
|
||||
app->habits.items[index].counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
app->habits.selected = index;
|
||||
inbe_habits_save(&app->habits);
|
||||
}
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
habit_edit_cancel(app);
|
||||
app->inbe.screen = InbeScreenHabits;
|
||||
@@ -610,6 +788,7 @@ habit_refresh_detail_day_completion(InbeApp *app)
|
||||
inbe_habit_set_day(&app->habits, index, day, 0);
|
||||
app->habits.selected = selected;
|
||||
inbe_habits_save(&app->habits);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -638,6 +817,46 @@ habit_linked_has_day(const HabitLinkedContext *ctx, int day_index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_linked_session_count_for_day(const HabitLinkedContext *ctx, int day_index)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
if(ctx == NULL)
|
||||
return 0;
|
||||
for(int i = 0; i < ctx->count; i++) {
|
||||
int entry_day = ctx->entries[i].year * 10000 +
|
||||
ctx->entries[i].month * 100 +
|
||||
ctx->entries[i].day;
|
||||
if(entry_day == day_index)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int
|
||||
habit_effective_day_count(const InbeHabit *habit, int day_index,
|
||||
const HabitLinkedContext *linked_ctx)
|
||||
{
|
||||
int manual_count = inbe_habit_day_count(habit, day_index);
|
||||
int session_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
return manual_count > session_count ? manual_count : session_count;
|
||||
}
|
||||
|
||||
static void
|
||||
habit_apply_count_action(InbeHabits *habits, int index, int day_index,
|
||||
int delta, int minimum_count)
|
||||
{
|
||||
int count;
|
||||
|
||||
if(habits == NULL || index < 0 || index >= habits->count || day_index <= 0)
|
||||
return;
|
||||
count = inbe_habit_day_count(&habits->items[index], day_index) + delta;
|
||||
if(count < minimum_count)
|
||||
count = minimum_count;
|
||||
inbe_habit_set_day_count(habits, index, day_index, count);
|
||||
}
|
||||
|
||||
static void
|
||||
habit_open_linked_edit_page(InbeApp *app, int habit_index, int day_index)
|
||||
{
|
||||
@@ -771,6 +990,26 @@ draw_habit_link_dot(int x, int y, int w, Color color)
|
||||
flint_px(3), color);
|
||||
}
|
||||
|
||||
static Color
|
||||
habit_text_color_for_background(Color background)
|
||||
{
|
||||
int luma = background.r * 299 + background.g * 587 + background.b * 114;
|
||||
|
||||
return luma >= 128000 ? BLACK : WHITE;
|
||||
}
|
||||
|
||||
static void
|
||||
habit_weekly_draw_text_line(const char *text, int x, int y, int w, int h,
|
||||
int text_size, Color color)
|
||||
{
|
||||
int font_size;
|
||||
|
||||
if(text == NULL || text[0] == '\0' || w <= 0 || h <= 0)
|
||||
return;
|
||||
font_size = flint_px(text_size);
|
||||
flint_text_draw(text, x, flint_text_y(text, y, h, font_size), font_size, color);
|
||||
}
|
||||
|
||||
static int
|
||||
habit_weekly_summary(const HabitLinkedContext *ctx, int day_index,
|
||||
char *primary, size_t primary_size,
|
||||
@@ -821,8 +1060,9 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
int hovered;
|
||||
Color fill = completed ? theme_get_button() : flint_darken(theme_get_bg(), 10);
|
||||
Color text = disabled ? flint_darken(theme_get_text(), 35) : theme_get_text();
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_px(FLINT_TEXT_8);
|
||||
int pad = flint_px(9);
|
||||
int text_x;
|
||||
int text_w;
|
||||
const char *line1 = primary != NULL ? primary : "";
|
||||
const char *line2 = secondary != NULL ? secondary : "";
|
||||
|
||||
@@ -841,25 +1081,28 @@ habit_weekly_summary_button(InbeApp *app, int x, int y, int w, int h, int comple
|
||||
|
||||
if(hovered)
|
||||
fill = theme_get_button_hover();
|
||||
if(!disabled && completed)
|
||||
text = habit_text_color_for_background(fill);
|
||||
DrawRectangle(x, y, w, h, fill);
|
||||
ui_draw_bevel(x, y, w, h, flint_lighten(fill, 36), flint_darken(fill, 42));
|
||||
|
||||
text_x = x + pad;
|
||||
text_w = w - pad * 2;
|
||||
|
||||
if(line1[0] != '\0') {
|
||||
if(line2[0] != '\0') {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(5),
|
||||
w - flint_px(16), flint_px(18)},
|
||||
font, FLINT_TEXT_12, text);
|
||||
flint_text_draw_fitted_in_rect(line2,
|
||||
(Rectangle){x + flint_px(8), y + flint_px(24),
|
||||
w - flint_px(16), flint_px(12)},
|
||||
small_font, FLINT_TEXT_8,
|
||||
flint_darken(text, 16));
|
||||
int line1_h = flint_px(24);
|
||||
int line2_h = flint_px(16);
|
||||
int block_h = line1_h + line2_h;
|
||||
int block_y = y + (h - block_h) / 2;
|
||||
habit_weekly_draw_text_line(line1, text_x, block_y, text_w, line1_h,
|
||||
FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line2, text_x, block_y + line1_h, text_w, line2_h,
|
||||
FLINT_TEXT_8, flint_darken(text, 16));
|
||||
} else {
|
||||
flint_text_draw_fitted_in_rect(line1,
|
||||
(Rectangle){x + flint_px(8), y,
|
||||
w - flint_px(16), h},
|
||||
font, FLINT_TEXT_16, text);
|
||||
habit_weekly_draw_text_line(line1, text_x, y + flint_px(3),
|
||||
text_w, h - flint_px(6),
|
||||
FLINT_TEXT_16, text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -883,7 +1126,7 @@ habit_weekly_visible_days(InbeHabits *habits)
|
||||
static int
|
||||
habit_weekly_content_height(int visible_days)
|
||||
{
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int load_h = flint_px(38);
|
||||
|
||||
@@ -908,7 +1151,7 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
int gap = flint_px(8);
|
||||
int button_x;
|
||||
int button_w;
|
||||
int row_h = flint_px(40);
|
||||
int row_h = flint_px(44);
|
||||
int row_gap = flint_px(6);
|
||||
int day_font = flint_px(16);
|
||||
int date_font = flint_px(FLINT_TEXT_8);
|
||||
@@ -947,6 +1190,10 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
int completed;
|
||||
int has_linked_day;
|
||||
int future_day;
|
||||
int count = 0;
|
||||
int action = 0;
|
||||
int counting_enabled;
|
||||
int minimum_count;
|
||||
char primary[64] = "";
|
||||
char secondary[64] = "";
|
||||
int session_count;
|
||||
@@ -956,12 +1203,22 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
day_index = habit_tm_date_index(&row_tm);
|
||||
future_day = day_index > today_index;
|
||||
has_linked_day = linked_ctx != NULL && habit_linked_has_day(linked_ctx, day_index);
|
||||
counting_enabled = habit_counting_enabled(active);
|
||||
minimum_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
session_count = habit_weekly_summary(linked_ctx, day_index,
|
||||
primary, sizeof(primary),
|
||||
secondary, sizeof(secondary));
|
||||
if(counting_enabled)
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = inbe_habit_completed_day(active, day_index);
|
||||
if(!completed && !future_day && has_linked_day)
|
||||
if(!completed && !future_day && (has_linked_day || count > 0))
|
||||
completed = 1;
|
||||
if(counting_enabled && count > 0 && session_count > 0 &&
|
||||
secondary[0] != '\0') {
|
||||
size_t len = strlen(secondary);
|
||||
snprintf(secondary + len, sizeof(secondary) - len,
|
||||
" / total %d", count);
|
||||
}
|
||||
if(session_count <= 0 && completed) {
|
||||
snprintf(primary, sizeof(primary), "Completed");
|
||||
secondary[0] = '\0';
|
||||
@@ -983,17 +1240,49 @@ draw_habits_weekly_view(InbeApp *app, InbeHabit *active, int selected,
|
||||
date_font, flint_darken(theme_get_text(), 18));
|
||||
}
|
||||
|
||||
if(habit_weekly_summary_button(app, button_x, y, button_w, row_h, completed, future_day,
|
||||
primary, secondary)) {
|
||||
if(counting_enabled) {
|
||||
(void)habit_weekly_summary_button(app, button_x, y, button_w, row_h,
|
||||
completed, future_day, primary, secondary);
|
||||
action = habit_counter_day_action(app, selected, day_index,
|
||||
button_x, y, button_w, row_h,
|
||||
future_day, !has_linked_day);
|
||||
if(action == 0 && has_linked_day &&
|
||||
!future_day && CheckCollisionPointRec(GetScreenToWorld2D(GetMousePosition(), app->camera),
|
||||
(Rectangle){(float)button_x, (float)y, (float)button_w, (float)row_h}) &&
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
}
|
||||
} else if(habit_weekly_summary_button(app, button_x, y, button_w, row_h, completed, future_day,
|
||||
primary, secondary)) {
|
||||
if(has_linked_day) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
} else {
|
||||
inbe_habit_toggle_day(&app->habits, selected, day_index);
|
||||
active = &app->habits.items[selected];
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
if(action == 1 || action == -1) {
|
||||
habit_apply_count_action(&app->habits, selected, day_index, action,
|
||||
minimum_count);
|
||||
active = &app->habits.items[selected];
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = count > 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
if(completed && !future_day)
|
||||
draw_habit_completion_underline(button_x, y, button_w, row_h, active->color);
|
||||
if(counting_enabled && count > 0 && !future_day) {
|
||||
char count_label[16];
|
||||
int count_font = flint_px(8);
|
||||
int count_w;
|
||||
snprintf(count_label, sizeof(count_label), "%d", count);
|
||||
count_w = flint_text_measure(count_label, count_font);
|
||||
flint_text_draw(count_label,
|
||||
button_x + button_w - count_w - flint_px(6),
|
||||
y + flint_px(5),
|
||||
count_font, theme_get_text());
|
||||
}
|
||||
if(!future_day && has_linked_day)
|
||||
draw_habit_link_dot(button_x, y, button_w, active->color);
|
||||
|
||||
@@ -1277,6 +1566,10 @@ draw_habits_screen(InbeApp *app)
|
||||
int completed;
|
||||
int future_day;
|
||||
int has_linked_day;
|
||||
int count = 0;
|
||||
int action = 0;
|
||||
int counting_enabled;
|
||||
int minimum_count;
|
||||
|
||||
if(day < 1 || day > days_in_month) {
|
||||
DrawRectangle(cell_x, cell_y, cell_w, cell_h, flint_darken(theme_get_bg(), 5));
|
||||
@@ -1287,10 +1580,28 @@ draw_habits_screen(InbeApp *app)
|
||||
day_index = year * 10000 + mon * 100 + day;
|
||||
future_day = day_index > today_index;
|
||||
has_linked_day = linked_ctx != NULL && habit_linked_has_day(linked_ctx, day_index);
|
||||
counting_enabled = habit_counting_enabled(active);
|
||||
minimum_count = habit_linked_session_count_for_day(linked_ctx, day_index);
|
||||
if(counting_enabled)
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = inbe_habit_completed_day(active, day_index);
|
||||
if(!completed && !future_day && has_linked_day)
|
||||
if(!completed && !future_day && (has_linked_day || count > 0))
|
||||
completed = 1;
|
||||
if(ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
if(counting_enabled) {
|
||||
(void)ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
completed ? UI_BUTTON_STYLE_PRIMARY : UI_BUTTON_STYLE_SECONDARY,
|
||||
future_day, &hover);
|
||||
action = habit_counter_day_action(app, selected, day_index,
|
||||
cell_x, cell_y, cell_w, cell_h,
|
||||
future_day, !has_linked_day);
|
||||
if(action == 0 && has_linked_day && !future_day &&
|
||||
CheckCollisionPointRec(GetScreenToWorld2D(GetMousePosition(), app->camera),
|
||||
(Rectangle){(float)cell_x, (float)cell_y,
|
||||
(float)cell_w, (float)cell_h}) &&
|
||||
IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
habit_open_linked_edit_page(app, selected, day_index);
|
||||
}
|
||||
} else if(ui_draw_generic_button(cell_x, cell_y, cell_w, cell_h, day_label,
|
||||
completed ? UI_BUTTON_STYLE_PRIMARY : UI_BUTTON_STYLE_SECONDARY,
|
||||
future_day, &hover)) {
|
||||
if(has_linked_day) {
|
||||
@@ -1298,11 +1609,31 @@ draw_habits_screen(InbeApp *app)
|
||||
} else {
|
||||
inbe_habit_toggle_day(&app->habits, selected, day_index);
|
||||
active = &app->habits.items[selected];
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
}
|
||||
if(action == 1 || action == -1) {
|
||||
habit_apply_count_action(&app->habits, selected, day_index, action,
|
||||
minimum_count);
|
||||
active = &app->habits.items[selected];
|
||||
count = habit_effective_day_count(active, day_index, linked_ctx);
|
||||
completed = count > 0;
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
if(completed && !future_day) {
|
||||
draw_habit_completion_underline(cell_x, cell_y, cell_w, cell_h, active->color);
|
||||
}
|
||||
if(counting_enabled && count > 0 && !future_day) {
|
||||
char count_label[16];
|
||||
int count_font = flint_px(8);
|
||||
int count_w;
|
||||
snprintf(count_label, sizeof(count_label), "%d", count);
|
||||
count_w = flint_text_measure(count_label, count_font);
|
||||
flint_text_draw(count_label,
|
||||
cell_x + cell_w - count_w - flint_px(4),
|
||||
cell_y + flint_px(4),
|
||||
count_font, theme_get_text());
|
||||
}
|
||||
if(!future_day && has_linked_day) {
|
||||
draw_habit_link_dot(cell_x, cell_y, cell_w, active->color);
|
||||
}
|
||||
@@ -1416,8 +1747,10 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
habit_edit_cancel(app);
|
||||
if(index >= 0 && index < app->habits.count)
|
||||
if(index >= 0 && index < app->habits.count) {
|
||||
inbe_habits_delete(&app->habits, index);
|
||||
inbe_app_auto_sync(app);
|
||||
}
|
||||
app->inbe.screen = InbeScreenHabits;
|
||||
}
|
||||
return;
|
||||
@@ -1468,10 +1801,30 @@ draw_habit_edit_screen(InbeApp *app)
|
||||
app->habit_edit_sync_mode = app->habit_edit_sync_activity != 0
|
||||
? INBE_HABIT_SYNC_ACTIVITIES
|
||||
: INBE_HABIT_SYNC_NONE;
|
||||
if(app->habit_edit_sync_activity != 0)
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
}
|
||||
y += flint_px(42);
|
||||
}
|
||||
|
||||
y += flint_px(4);
|
||||
flint_text_draw("Counting", content_x, y, label_font, flint_darken(theme_get_text(), 34));
|
||||
y += flint_px(24);
|
||||
if(app->habit_edit_sync_activity != 0) {
|
||||
int forced_counter = 1;
|
||||
ui_draw_checkbox_toggle_disabled(content_x, y, "Allow multiple counts",
|
||||
&forced_counter, 1);
|
||||
app->habit_edit_counter_enabled = 1;
|
||||
y += flint_px(30);
|
||||
flint_text_draw("Required for practice-linked habits", content_x, y,
|
||||
label_font, flint_darken(theme_get_text(), 42));
|
||||
y += flint_px(12);
|
||||
} else if(ui_draw_checkbox_toggle(content_x, y, "Allow multiple counts",
|
||||
&app->habit_edit_counter_enabled)) {
|
||||
app->habit_edit_counter_enabled = app->habit_edit_counter_enabled != 0;
|
||||
}
|
||||
y += flint_px(42);
|
||||
|
||||
if(!app->habit_edit_is_new) {
|
||||
int delete_w = flint_px(160);
|
||||
int delete_h = flint_px(38);
|
||||
@@ -1704,6 +2057,53 @@ draw_habit_session_edit_content(InbeApp *app, HabitLinkedContext *ctx, int conte
|
||||
y += section_gap;
|
||||
}
|
||||
|
||||
if(ctx->day_filter > 0 &&
|
||||
app->habit_detail_index >= 0 &&
|
||||
app->habit_detail_index < app->habits.count) {
|
||||
InbeHabit *habit = &app->habits.items[app->habit_detail_index];
|
||||
int minimum_count = ctx->count;
|
||||
int total_count = habit_effective_day_count(habit, ctx->day_filter, ctx);
|
||||
int button_h = flint_px(34);
|
||||
int step_w = flint_px(42);
|
||||
int gap = flint_px(8);
|
||||
int minus_x = content_x;
|
||||
int plus_x = content_x + content_w - step_w;
|
||||
int label_x = minus_x + step_w + gap;
|
||||
int label_w = plus_x - label_x - gap;
|
||||
int hover = 0;
|
||||
char total_text[64];
|
||||
char min_text[64];
|
||||
|
||||
y += flint_px(6);
|
||||
if(draw) {
|
||||
snprintf(total_text, sizeof(total_text), "Total count %d", total_count);
|
||||
snprintf(min_text, sizeof(min_text), "Minimum %d from session%s",
|
||||
minimum_count, minimum_count == 1 ? "" : "s");
|
||||
if(ui_draw_generic_button(minus_x, y, step_w, button_h, "-",
|
||||
UI_BUTTON_STYLE_SECONDARY,
|
||||
total_count <= minimum_count, &hover)) {
|
||||
habit_apply_count_action(&app->habits, app->habit_detail_index,
|
||||
ctx->day_filter, -1, minimum_count);
|
||||
inbe_app_auto_sync(app);
|
||||
return y;
|
||||
}
|
||||
DrawRectangle(label_x, y, label_w, button_h, flint_darken(theme_get_bg(), 5));
|
||||
flint_text_draw(total_text, label_x + flint_px(8),
|
||||
y + flint_px(4), flint_ui_font_small(), theme_get_text());
|
||||
flint_text_draw(min_text, label_x + flint_px(8),
|
||||
y + flint_px(20), flint_px(FLINT_TEXT_8),
|
||||
flint_darken(theme_get_text(), 18));
|
||||
if(ui_draw_generic_button(plus_x, y, step_w, button_h, "+",
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
habit_apply_count_action(&app->habits, app->habit_detail_index,
|
||||
ctx->day_filter, 1, minimum_count);
|
||||
inbe_app_auto_sync(app);
|
||||
return y;
|
||||
}
|
||||
}
|
||||
y += button_h + flint_px(8);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ enum {
|
||||
INBE_HABIT_MAX = 10,
|
||||
INBE_HABIT_ID_SIZE = 32,
|
||||
INBE_HABIT_NAME_SIZE = 40,
|
||||
INBE_HABIT_MAX_DAYS = 366,
|
||||
HABIT_LINKED_ENTRY_MAX = 128,
|
||||
HABIT_LINKED_PATH_SIZE = 80
|
||||
};
|
||||
@@ -37,6 +36,7 @@ typedef enum InbeHabitSyncMode {
|
||||
typedef struct InbeHabitDay {
|
||||
int day_index;
|
||||
int completed;
|
||||
int count;
|
||||
} InbeHabitDay;
|
||||
|
||||
typedef struct InbeHabit {
|
||||
@@ -45,8 +45,10 @@ typedef struct InbeHabit {
|
||||
Color color;
|
||||
int sync_mode;
|
||||
int sync_activity;
|
||||
InbeHabitDay days[INBE_HABIT_MAX_DAYS];
|
||||
int counter_enabled;
|
||||
InbeHabitDay *days;
|
||||
int day_count;
|
||||
int day_capacity;
|
||||
} InbeHabit;
|
||||
|
||||
typedef struct InbeHabits {
|
||||
@@ -89,13 +91,18 @@ typedef struct HabitLinkedContext {
|
||||
|
||||
/* Core habits functions */
|
||||
void inbe_habits_init(InbeHabits *habits);
|
||||
void inbe_habits_free(InbeHabits *habits);
|
||||
void inbe_habits_save(const InbeHabits *habits);
|
||||
int inbe_habits_clear_days(InbeHabits *habits);
|
||||
int inbe_habit_reserve_days(InbeHabit *habit, int capacity);
|
||||
int inbe_habits_today_index(void);
|
||||
int inbe_habit_completed_day(const InbeHabit *habit, int day_index);
|
||||
int inbe_habit_completed_today(const InbeHabit *habit);
|
||||
void inbe_habit_set_day(InbeHabits *habits, int index, int day_index, int completed);
|
||||
void inbe_habit_set_day_count(InbeHabits *habits, int index, int day_index, int count);
|
||||
int inbe_habit_day_count(const InbeHabit *habit, int day_index);
|
||||
void inbe_habit_toggle_day(InbeHabits *habits, int index, int day_index);
|
||||
void inbe_habit_increment_day(InbeHabits *habits, int index, int day_index, int delta);
|
||||
void inbe_habit_toggle_today(InbeHabits *habits, int index);
|
||||
void inbe_habits_add_default(InbeHabits *habits);
|
||||
void inbe_habits_add_default_set(InbeHabits *habits);
|
||||
|
||||
@@ -0,0 +1,679 @@
|
||||
#include "settings_data.h"
|
||||
|
||||
#include "settings_screen.h"
|
||||
#include "settings_sync_account.h"
|
||||
#include "app.h"
|
||||
#include "data.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "theme.h"
|
||||
#include "version.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "flint_ui.h"
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(_WIN32) && !defined(PLATFORM_WEB)
|
||||
#define INBE_HAS_FLINT_FILE_DIALOG 1
|
||||
#include "flint_file_dialog.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_import.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
enum {
|
||||
SETTINGS_DATA_ACTION_NONE = 0,
|
||||
SETTINGS_DATA_ACTION_IMPORT,
|
||||
SETTINGS_DATA_ACTION_EXPORT,
|
||||
SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT
|
||||
};
|
||||
|
||||
enum {
|
||||
SETTINGS_DATA_VIEW_MAIN = 0,
|
||||
SETTINGS_DATA_VIEW_SYNC_ACCOUNT = 1
|
||||
};
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_SERVER_URL_DEFAULT "https://api.waozi.xyz"
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static FlintFileDialog export_dlg;
|
||||
static FlintFileDialog import_dlg;
|
||||
static int data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
#endif
|
||||
|
||||
static char pending_import_path[FS_PATH_MAX] = "";
|
||||
static DataImportInfo pending_import_info;
|
||||
|
||||
static void settings_import_data(InbeApp *app);
|
||||
static void settings_export_data(InbeApp *app);
|
||||
static void settings_request_delete_all_data(InbeApp *app);
|
||||
static void settings_sync_server_load(InbeApp *app);
|
||||
|
||||
static void
|
||||
settings_clear_pending_import(void)
|
||||
{
|
||||
pending_import_path[0] = '\0';
|
||||
memset(&pending_import_info, 0, sizeof(pending_import_info));
|
||||
}
|
||||
|
||||
static void
|
||||
settings_import_success(InbeApp *app, int imported_settings)
|
||||
{
|
||||
app_reload_after_import(app, imported_settings);
|
||||
settings_screen_set_status_success(locale_get("imported_data"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Import successful");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_perform_import(InbeApp *app, const char *path, DataImportMode mode)
|
||||
{
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data_import_with_mode(path, mode)) {
|
||||
settings_import_success(app, mode == DATA_IMPORT_DATA_AND_SETTINGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Import failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_begin_import_for_path(InbeApp *app, const char *path)
|
||||
{
|
||||
DataImportInfo info;
|
||||
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if(!data_inspect_import(path, &info) || !info.valid) {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: Invalid import file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
if((info.has_sessions || info.has_habits) && info.has_settings) {
|
||||
snprintf(pending_import_path, sizeof(pending_import_path), "%s", path);
|
||||
pending_import_info = info;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmImportDataSettings;
|
||||
app->modal.selected_button = 0;
|
||||
settings_screen_clear_status();
|
||||
return;
|
||||
}
|
||||
|
||||
settings_perform_import(app, path, DATA_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_draw_import_choice_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
int font = flint_ui_font();
|
||||
int msg_y;
|
||||
int msg_x;
|
||||
const char *message = locale_get("import_choice_message");
|
||||
int row_gap = flint_px(10);
|
||||
int btn_h = flint_px(36);
|
||||
int btn_y;
|
||||
int btn_w;
|
||||
int hover = 0;
|
||||
|
||||
(void)app;
|
||||
frame = ui_draw_modal_frame(flint_px(320), flint_px(232),
|
||||
locale_get("import_choice_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
msg_x = frame.content_x;
|
||||
msg_y = frame.content_y;
|
||||
flint_text_draw(message, msg_x, msg_y, font, theme_get_text());
|
||||
|
||||
btn_y = frame.y + frame.h - flint_px(24) - btn_h * 2 - row_gap;
|
||||
btn_w = (frame.content_w - row_gap) / 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y, btn_w, btn_h,
|
||||
locale_get("cancel_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
if(ui_draw_generic_button(frame.content_x + btn_w + row_gap, btn_y, btn_w, btn_h,
|
||||
locale_get("import_data_only_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y + btn_h + row_gap,
|
||||
frame.content_w, btn_h,
|
||||
locale_get("import_data_settings_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icon_columns(int content_w)
|
||||
{
|
||||
int max_columns = 5;
|
||||
int min_columns = 2;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
|
||||
for(int columns = max_columns; columns > min_columns; columns--) {
|
||||
int total_w = icon_btn_w * columns + icon_spacing * (columns - 1);
|
||||
if(total_w <= content_w)
|
||||
return columns;
|
||||
}
|
||||
|
||||
return min_columns;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icons_height(int content_w)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int row_spacing = flint_px(16);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int rows = (link_count + columns - 1) / columns;
|
||||
|
||||
return flint_px(8) + rows * icon_btn_w + (rows - 1) * row_spacing;
|
||||
}
|
||||
|
||||
int
|
||||
settings_data_content_height(int content_w)
|
||||
{
|
||||
int data_button_h = flint_px(36);
|
||||
|
||||
return data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
flint_px(42) +
|
||||
settings_link_icons_height(content_w) +
|
||||
flint_px(8) + flint_px(22) +
|
||||
flint_px(40);
|
||||
}
|
||||
|
||||
int
|
||||
settings_data_is_configuring(const InbeApp *app)
|
||||
{
|
||||
return app != NULL && app->settings_tab == SETTINGS_TAB_DATA &&
|
||||
app->settings_data_view == SETTINGS_DATA_VIEW_SYNC_ACCOUNT;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_server_load(InbeApp *app)
|
||||
{
|
||||
const char *saved;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
saved = inbe_storage_get_setting_text(INBE_SYNC_SERVER_URL_KEY);
|
||||
snprintf(app->sync_server_url, sizeof(app->sync_server_url), "%s",
|
||||
saved != NULL && saved[0] != '\0'
|
||||
? saved
|
||||
: INBE_SYNC_SERVER_URL_DEFAULT);
|
||||
app->sync_server_url_cursor = (int)strlen(app->sync_server_url);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_open_sync_account_config(InbeApp *app)
|
||||
{
|
||||
if(app == NULL)
|
||||
return;
|
||||
settings_sync_server_load(app);
|
||||
app->settings_data_view = SETTINGS_DATA_VIEW_SYNC_ACCOUNT;
|
||||
app->settings_scroll = 0;
|
||||
app->sync_server_url_focused = 0;
|
||||
settings_screen_clear_status();
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static void
|
||||
settings_apply_file_dialog_theme(InbeApp *app)
|
||||
{
|
||||
int theme_id = app != NULL ? app->theme_id : FLINT_THEME_SKY;
|
||||
int dark_mode = app != NULL && app->dark_mode != 0;
|
||||
|
||||
if(theme_id < 0 || theme_id >= FLINT_THEME_COUNT)
|
||||
theme_id = FLINT_THEME_SKY;
|
||||
flint_file_dialog_set_theme_scope(flint_theme_scope_for((FlintThemeId)theme_id,
|
||||
dark_mode != 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
settings_start_sync_key_export_dialog(InbeApp *app, const char *filename)
|
||||
{
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_save(&export_dlg, locale_get("sync_save_key_dialog_title"), filename);
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT;
|
||||
return 4;
|
||||
#else
|
||||
(void)app;
|
||||
(void)filename;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_link_icons(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int grid_w = icon_btn_w * columns + icon_spacing * (columns - 1);
|
||||
int links_start_x = content_x + (content_w - grid_w) / 2;
|
||||
int row_spacing = flint_px(16);
|
||||
Texture2D icons[5] = {
|
||||
app->icons[UI_ICON_TYPE_DISCORD],
|
||||
app->icons[UI_ICON_TYPE_TELEGRAM],
|
||||
app->icons[UI_ICON_TYPE_GITHUB],
|
||||
app->icons[UI_ICON_TYPE_BTC],
|
||||
app->icons[UI_ICON_TYPE_MONERO]
|
||||
};
|
||||
const char *urls[5] = {
|
||||
"https://discord.com/invite/JbGZ4yENDt",
|
||||
"https://t.me/lotusinbe",
|
||||
"https://github.com/waozixyz/inbe",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=btc&network_to=Mainnet&address=bc1qxzcetg50f6epgddc09n82xqn3zswlmk44235y5&donation=True&simple_mode=True&amount=0.001&name=Inner+Breeze&[email protected]&ticker_from=btc&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=xmr&network_to=Mainnet&address=86CbC3d4a2GhT9auh6X99JhmhTMFKVVk8Q9cLrKTHkBu8LLkoNWgkBeAT3YZrvDM6NczYe8brUJNsTiFmwpWDZYnFG5kzSH&donation=True&simple_mode=True&amount=0.1&name=Inner+Breeze&[email protected]&ticker_from=xmr&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff"
|
||||
};
|
||||
|
||||
*y += flint_px(8);
|
||||
for(int i = 0; i < link_count; i++) {
|
||||
int col = i % columns;
|
||||
int row = i / columns;
|
||||
int icon_x = links_start_x + col * (icon_btn_w + icon_spacing) + icon_padding;
|
||||
int icon_y = *y + row * (icon_btn_w + row_spacing);
|
||||
ui_draw_icon_link(icon_x, icon_y, icon_size, icons[i], urls[i]);
|
||||
}
|
||||
*y += settings_link_icons_height(content_w) - flint_px(8);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_version_centered(int x, int w, int *y)
|
||||
{
|
||||
char version_text[32];
|
||||
int font = flint_ui_font_small();
|
||||
int text_w;
|
||||
|
||||
snprintf(version_text, sizeof(version_text), "v%s", INBE_VERSION_STRING);
|
||||
text_w = flint_text_measure(version_text, font);
|
||||
flint_text_draw(version_text, x + (w - text_w) / 2, *y, font,
|
||||
flint_darken(theme_get_text(), 40));
|
||||
*y += flint_px(22);
|
||||
}
|
||||
|
||||
void
|
||||
settings_data_draw(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
int data_button_h = flint_px(36);
|
||||
InbeSyncAccount account;
|
||||
int has_account;
|
||||
int hover_account = 0;
|
||||
int hover_import = 0;
|
||||
int hover_export = 0;
|
||||
int hover_delete = 0;
|
||||
|
||||
settings_sync_account_set_save_dialog(settings_start_sync_key_export_dialog);
|
||||
if(app != NULL && app->settings_data_view == SETTINGS_DATA_VIEW_SYNC_ACCOUNT) {
|
||||
settings_sync_account_draw_config(app, x, w, y);
|
||||
return;
|
||||
}
|
||||
|
||||
has_account = inbe_sync_account_load(&account);
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
has_account ? locale_get("sync_configure_account_button")
|
||||
: locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_account)) {
|
||||
if(has_account) {
|
||||
settings_open_sync_account_config(app);
|
||||
} else if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("import_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_import))
|
||||
settings_import_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("export_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_export))
|
||||
settings_export_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, data_button_h,
|
||||
locale_get("delete_all_data_button"),
|
||||
UI_BUTTON_STYLE_DANGER, 0, &hover_delete))
|
||||
settings_request_delete_all_data(app);
|
||||
*y += data_button_h + flint_px(12);
|
||||
settings_screen_draw_status_reserved(x, y, flint_px(42));
|
||||
settings_draw_link_icons(app, x, w, y);
|
||||
*y += flint_px(8);
|
||||
settings_draw_version_centered(x, w, y);
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
void
|
||||
settings_data_handle_android_import(InbeApp *app)
|
||||
{
|
||||
char import_path[FS_PATH_MAX];
|
||||
int import_result = android_import_poll_result(import_path, sizeof(import_path));
|
||||
|
||||
if(import_result == ANDROID_IMPORT_RESULT_NONE)
|
||||
return;
|
||||
if(import_result == ANDROID_IMPORT_RESULT_CANCELLED) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
settings_begin_import_for_path(app, import_path);
|
||||
}
|
||||
#else
|
||||
void settings_data_handle_android_import(InbeApp *app) { (void)app; }
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#define SETTINGS_WEB_IMPORT_PATH "/tmp/inbe-web-import.zip"
|
||||
|
||||
static void
|
||||
settings_web_import_open_picker(void)
|
||||
{
|
||||
EM_ASM({
|
||||
const importPath = UTF8ToString($0);
|
||||
Module.__inbeImportResult = 0;
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".zip,.db,application/zip,application/x-sqlite3,application/octet-stream";
|
||||
input.style.display = "none";
|
||||
|
||||
input.onchange = async function() {
|
||||
try {
|
||||
if(!input.files || input.files.length === 0) {
|
||||
Module.__inbeImportResult = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
const file = input.files[0];
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
try {
|
||||
FS.mkdir("/tmp");
|
||||
} catch(e) {}
|
||||
FS.writeFile(importPath, bytes);
|
||||
Module.__inbeImportResult = 1;
|
||||
} catch(e) {
|
||||
console.error("Inbe web import failed:", e);
|
||||
Module.__inbeImportResult = 3;
|
||||
} finally {
|
||||
input.remove();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
}, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
|
||||
void
|
||||
settings_data_handle_web_import(InbeApp *app)
|
||||
{
|
||||
int import_result = EM_ASM_INT({
|
||||
const result = Module.__inbeImportResult || 0;
|
||||
if(result !== 0)
|
||||
Module.__inbeImportResult = 0;
|
||||
return result;
|
||||
});
|
||||
|
||||
if(import_result == 0)
|
||||
return;
|
||||
if(import_result == 2) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_result != 1) {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
return;
|
||||
}
|
||||
settings_begin_import_for_path(app, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
#else
|
||||
void settings_data_handle_web_import(InbeApp *app) { (void)app; }
|
||||
#endif
|
||||
|
||||
static void
|
||||
settings_import_data(InbeApp *app)
|
||||
{
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
if(android_import_open_picker())
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
else
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#elif defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
settings_web_import_open_picker();
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_load(&import_dlg, locale_get("import_data_dialog_title"));
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_IMPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_export_data(InbeApp *app)
|
||||
{
|
||||
char export_filename[64];
|
||||
data_default_export_filename(export_filename, sizeof(export_filename));
|
||||
|
||||
if(!data_has_any()) {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_export"));
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
(void)app;
|
||||
if(data_export(export_filename)) {
|
||||
settings_screen_set_status_success(locale_get("exported_label"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful (share sheet shown)");
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_save(&export_dlg, locale_get("export_data_dialog_title"), export_filename);
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_EXPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_request_delete_all_data(InbeApp *app)
|
||||
{
|
||||
if(data_has_any()) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmDeleteData;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
int
|
||||
settings_data_draw_pending_file_dialog(InbeApp *app)
|
||||
{
|
||||
FlintFileDialog *dlg;
|
||||
int result;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_NONE)
|
||||
return 0;
|
||||
|
||||
settings_apply_file_dialog_theme(app);
|
||||
dlg = data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT ? &import_dlg : &export_dlg;
|
||||
result = flint_file_dialog_update(dlg);
|
||||
if(result < 0)
|
||||
return 1;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT) {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&import_dlg);
|
||||
if(path != NULL && path[0] != '\0') {
|
||||
settings_begin_import_for_path(app, path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: No file selected for import");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
}
|
||||
} else if(data_file_dialog_action == SETTINGS_DATA_ACTION_EXPORT) {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&export_dlg);
|
||||
if(path != NULL && data_export(path)) {
|
||||
const char *filename = GetFileName(path);
|
||||
settings_screen_set_status_success(locale_get("exported_label"), filename);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful to %s", path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_cancelled"));
|
||||
}
|
||||
} else if(data_file_dialog_action == SETTINGS_DATA_ACTION_SYNC_KEY_EXPORT) {
|
||||
if(result == 1) {
|
||||
InbeSyncAccount account;
|
||||
const char *path = flint_file_dialog_get_path(&export_dlg);
|
||||
if(path != NULL && path[0] != '\0' &&
|
||||
inbe_sync_account_load(&account) &&
|
||||
inbe_sync_account_export_private_key(&account, path)) {
|
||||
settings_screen_set_status_success(locale_get("sync_private_key_backup_saved"), GetFileName(path));
|
||||
TraceLog(LOG_INFO, "SYNC: Private key backup saved to %s", path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_failed"));
|
||||
TraceLog(LOG_ERROR, "SYNC: Private key backup failed");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_cancelled"));
|
||||
}
|
||||
}
|
||||
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
int settings_data_draw_pending_file_dialog(InbeApp *app) { (void)app; return 0; }
|
||||
#endif
|
||||
|
||||
int
|
||||
settings_data_draw_modals(InbeApp *app)
|
||||
{
|
||||
if(app == NULL || !app->modal.active)
|
||||
return 0;
|
||||
|
||||
if(app->modal.type == UIModalConfirmImportDataSettings) {
|
||||
int modal_result = settings_draw_import_choice_modal(app);
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
} else if(modal_result == 2 || modal_result == 3) {
|
||||
char import_path[FS_PATH_MAX];
|
||||
DataImportMode mode = modal_result == 3
|
||||
? DATA_IMPORT_DATA_AND_SETTINGS
|
||||
: DATA_IMPORT_DATA_ONLY;
|
||||
snprintf(import_path, sizeof(import_path), "%s", pending_import_path);
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_perform_import(app, import_path, mode);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(app->modal.type == UIModalConfirmDeleteData) {
|
||||
int modal_result = ui_draw_modal(locale_get("delete_all_data_title"),
|
||||
locale_get("delete_all_data_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("delete_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_screen_set_status_error(locale_get("delete_cancelled"));
|
||||
} else if(modal_result == 2) {
|
||||
long long deleted = data_delete_all();
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
if(deleted > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_add_default_set(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message),
|
||||
"deleted_sessions", deleted);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
int cleared = inbe_habits_clear_days(&app->habits);
|
||||
if(cleared > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_save(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message),
|
||||
"deleted_sessions", cleared);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(app->modal.type == UIModalSyncAccountBackup) {
|
||||
int modal_result = settings_sync_account_draw_backup_modal(app);
|
||||
if(modal_result == 1 || modal_result == 2 || modal_result == 3 || modal_result == 4) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
if(modal_result == 2)
|
||||
settings_screen_set_status_success(locale_get("sync_private_key_backup_saved"), NULL);
|
||||
else if(modal_result == 3)
|
||||
settings_screen_set_status_error(locale_get("sync_private_key_backup_failed"));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_SETTINGS_DATA_H
|
||||
#define INBE_SETTINGS_DATA_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
int settings_data_content_height(int content_w);
|
||||
int settings_data_is_configuring(const InbeApp *app);
|
||||
void settings_data_draw(InbeApp *app, int x, int w, int *y);
|
||||
int settings_data_draw_pending_file_dialog(InbeApp *app);
|
||||
int settings_data_draw_modals(InbeApp *app);
|
||||
void settings_data_handle_android_import(InbeApp *app);
|
||||
void settings_data_handle_web_import(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "settings_device.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_settings.h"
|
||||
#include "device_preferences.h"
|
||||
#include "language_screen.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
static int
|
||||
settings_device_orientation_option_count(void)
|
||||
{
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
return 4;
|
||||
#else
|
||||
return 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
settings_device_content_height(void)
|
||||
{
|
||||
int height = flint_px(74) + flint_px(74) + flint_px(76) + flint_px(40);
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
height += flint_px(76);
|
||||
#endif
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
height += flint_px(50);
|
||||
#endif
|
||||
height += flint_px(72);
|
||||
return height;
|
||||
}
|
||||
|
||||
void
|
||||
settings_device_draw(InbeApp *app, int x, int w, int *y, SettingsDeviceState *state)
|
||||
{
|
||||
int sound_volume;
|
||||
int keyboard_toggle;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
const char *orientation_options[] = {
|
||||
locale_get("orientation_system"),
|
||||
locale_get("orientation_portrait"),
|
||||
locale_get("orientation_landscape"),
|
||||
locale_get("orientation_sensor")
|
||||
};
|
||||
int orientation_option_count = settings_device_orientation_option_count();
|
||||
|
||||
if(app == NULL || y == NULL || state == NULL)
|
||||
return;
|
||||
|
||||
sound_volume = app->sound_volume;
|
||||
keyboard_toggle = app->on_screen_keyboard_enabled;
|
||||
|
||||
if(language_dropdown_button(app, 101, x, *y, w, flint_px(36), &app->language_index))
|
||||
state->language_menu_changed = 1;
|
||||
state->draw_language_menu = 1;
|
||||
*y += flint_px(74);
|
||||
|
||||
if(ui_draw_slider(6, x, *y, w, locale_get("volume_label"),
|
||||
SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX, &sound_volume, "")) {
|
||||
app->sound_volume = sound_volume;
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
*y += flint_px(74);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
{
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
flint_text_draw(locale_get("play_in_background_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&play_in_background, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->inbe.play_in_background = play_in_background;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(76);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode,
|
||||
APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
flint_text_draw(locale_get("orientation_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(103, x, *y + flint_px(26), w, flint_px(36),
|
||||
orientation_options, orientation_option_count,
|
||||
&app->orientation_mode);
|
||||
state->draw_orientation_menu = 1;
|
||||
*y += flint_px(76);
|
||||
}
|
||||
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
if(ui_draw_checkbox_toggle(x, *y, locale_get("fullscreen_label"), &app->fullscreen_enabled)) {
|
||||
if(app->fullscreen_enabled && !IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
else if(!app->fullscreen_enabled && IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(50);
|
||||
#endif
|
||||
|
||||
flint_text_draw(locale_get("on_screen_keyboard_label"), x, *y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(x, *y + flint_px(26), toggle_w, toggle_h,
|
||||
&keyboard_toggle, locale_get("toggle_off"),
|
||||
locale_get("toggle_on"))) {
|
||||
app->on_screen_keyboard_enabled = keyboard_toggle;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
*y += flint_px(76);
|
||||
}
|
||||
|
||||
void
|
||||
settings_device_handle_overlays(InbeApp *app, SettingsDeviceState *state)
|
||||
{
|
||||
int orientation_option_count = settings_device_orientation_option_count();
|
||||
|
||||
if(app == NULL || state == NULL)
|
||||
return;
|
||||
if(state->draw_language_menu && language_dropdown_menu(app, 101))
|
||||
state->language_menu_changed = 1;
|
||||
if(state->draw_orientation_menu && ui_draw_dropdown_menu(103))
|
||||
state->orientation_changed = 1;
|
||||
if(state->language_menu_changed)
|
||||
apply_language_selection(app, app->language_index, 1);
|
||||
if(state->orientation_changed) {
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode, APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
app_apply_orientation_preference(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef INBE_SETTINGS_DEVICE_H
|
||||
#define INBE_SETTINGS_DEVICE_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef struct SettingsDeviceState {
|
||||
int draw_language_menu;
|
||||
int language_menu_changed;
|
||||
int draw_orientation_menu;
|
||||
int orientation_changed;
|
||||
} SettingsDeviceState;
|
||||
|
||||
int settings_device_content_height(void);
|
||||
void settings_device_draw(InbeApp *app, int x, int w, int *y, SettingsDeviceState *state);
|
||||
void settings_device_handle_overlays(InbeApp *app, SettingsDeviceState *state);
|
||||
|
||||
#endif
|
||||
@@ -1,24 +1,13 @@
|
||||
#include "settings_screen.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "device_preferences.h"
|
||||
#include "language_screen.h"
|
||||
#include "app_settings.h"
|
||||
#include "locale.h"
|
||||
#include "settings_data.h"
|
||||
#include "settings_device.h"
|
||||
#include "settings_theme.h"
|
||||
#include "theme.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "flint_clip.h"
|
||||
#include "flint_ui.h"
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(_WIN32) && !defined(PLATFORM_WEB)
|
||||
#define INBE_HAS_FLINT_FILE_DIALOG 1
|
||||
#include "flint_file_dialog.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_import.h"
|
||||
#endif
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
#include "version.h"
|
||||
#include "data.h"
|
||||
#include "raylib.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -26,17 +15,9 @@
|
||||
extern int view_width;
|
||||
extern int view_height;
|
||||
|
||||
enum {
|
||||
SETTINGS_DATA_ACTION_NONE = 0,
|
||||
SETTINGS_DATA_ACTION_IMPORT,
|
||||
SETTINGS_DATA_ACTION_EXPORT
|
||||
};
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static FlintFileDialog export_dlg;
|
||||
static FlintFileDialog import_dlg;
|
||||
static int data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
#endif
|
||||
static char unified_status[256] = "";
|
||||
static char unified_detail[256] = "";
|
||||
static int unified_status_type = 0;
|
||||
|
||||
static int
|
||||
settings_draw_subtab_bar(int y, int h, const char **tab_names, int tab_count,
|
||||
@@ -62,22 +43,16 @@ settings_draw_subtab_bar(int y, int h, const char **tab_names, int tab_count,
|
||||
});
|
||||
}
|
||||
|
||||
/* Unified status system variables */
|
||||
static char unified_status[256] = "";
|
||||
static char unified_detail[256] = "";
|
||||
static int unified_status_type = 0;
|
||||
static char pending_import_path[FS_PATH_MAX] = "";
|
||||
static DataImportInfo pending_import_info;
|
||||
|
||||
/* Helper functions for unified status system */
|
||||
void settings_screen_set_status_success(const char *message, const char *detail) {
|
||||
if(message) {
|
||||
void
|
||||
settings_screen_set_status_success(const char *message, const char *detail)
|
||||
{
|
||||
if(message != NULL) {
|
||||
strncpy(unified_status, message, sizeof(unified_status) - 1);
|
||||
unified_status[sizeof(unified_status) - 1] = '\0';
|
||||
} else {
|
||||
unified_status[0] = '\0';
|
||||
}
|
||||
if(detail) {
|
||||
if(detail != NULL) {
|
||||
strncpy(unified_detail, detail, sizeof(unified_detail) - 1);
|
||||
unified_detail[sizeof(unified_detail) - 1] = '\0';
|
||||
} else {
|
||||
@@ -86,8 +61,10 @@ void settings_screen_set_status_success(const char *message, const char *detail)
|
||||
unified_status_type = 1;
|
||||
}
|
||||
|
||||
void settings_screen_set_status_error(const char *message) {
|
||||
if(message) {
|
||||
void
|
||||
settings_screen_set_status_error(const char *message)
|
||||
{
|
||||
if(message != NULL) {
|
||||
strncpy(unified_status, message, sizeof(unified_status) - 1);
|
||||
unified_status[sizeof(unified_status) - 1] = '\0';
|
||||
} else {
|
||||
@@ -105,129 +82,30 @@ settings_screen_clear_status(void)
|
||||
unified_status_type = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_clear_pending_import(void)
|
||||
{
|
||||
pending_import_path[0] = '\0';
|
||||
memset(&pending_import_info, 0, sizeof(pending_import_info));
|
||||
}
|
||||
|
||||
static void
|
||||
settings_import_success(InbeApp *app, int imported_settings)
|
||||
{
|
||||
app_reload_after_import(app, imported_settings);
|
||||
settings_screen_set_status_success(locale_get("imported_data"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Import successful");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_perform_import(InbeApp *app, const char *path, DataImportMode mode)
|
||||
{
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(data_import_with_mode(path, mode)) {
|
||||
settings_import_success(app, mode == DATA_IMPORT_DATA_AND_SETTINGS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Import failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_begin_import_for_path(InbeApp *app, const char *path)
|
||||
{
|
||||
DataImportInfo info;
|
||||
|
||||
if(app == NULL || path == NULL || path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&info, 0, sizeof(info));
|
||||
if(!data_inspect_import(path, &info) || !info.valid) {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: Invalid import file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
if((info.has_sessions || info.has_habits) && info.has_settings) {
|
||||
snprintf(pending_import_path, sizeof(pending_import_path), "%s", path);
|
||||
pending_import_info = info;
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmImportDataSettings;
|
||||
app->modal.selected_button = 0;
|
||||
settings_screen_clear_status();
|
||||
return;
|
||||
}
|
||||
|
||||
settings_perform_import(app, path, DATA_IMPORT_DATA_ONLY);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_draw_import_choice_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
int font = flint_ui_font();
|
||||
int msg_y;
|
||||
int msg_x;
|
||||
const char *message = locale_get("import_choice_message");
|
||||
int row_gap = flint_px(10);
|
||||
int btn_h = flint_px(36);
|
||||
int btn_y;
|
||||
int btn_w;
|
||||
int hover = 0;
|
||||
|
||||
(void)app;
|
||||
frame = ui_draw_modal_frame(flint_px(320), flint_px(232),
|
||||
locale_get("import_choice_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
msg_x = frame.content_x;
|
||||
msg_y = frame.content_y;
|
||||
flint_text_draw(message, msg_x, msg_y, font, theme_get_text());
|
||||
|
||||
btn_y = frame.y + frame.h - flint_px(24) - btn_h * 2 - row_gap;
|
||||
btn_w = (frame.content_w - row_gap) / 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y, btn_w, btn_h,
|
||||
locale_get("cancel_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
if(ui_draw_generic_button(frame.content_x + btn_w + row_gap, btn_y, btn_w, btn_h,
|
||||
locale_get("import_data_only_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 2;
|
||||
if(ui_draw_generic_button(frame.content_x, btn_y + btn_h + row_gap,
|
||||
frame.content_w, btn_h,
|
||||
locale_get("import_data_settings_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_status(int x, int *y)
|
||||
{
|
||||
int status_font;
|
||||
Color status_color;
|
||||
|
||||
if(unified_status[0] == '\0')
|
||||
return;
|
||||
|
||||
int status_font = flint_ui_font_small();
|
||||
Color status_color = (unified_status_type == 2) ? RED : theme_get_text();
|
||||
status_font = flint_ui_font_small();
|
||||
status_color = (unified_status_type == 2) ? RED : theme_get_text();
|
||||
|
||||
flint_text_draw(unified_status, x, *y, status_font, status_color);
|
||||
*y += flint_px(18);
|
||||
|
||||
if(unified_detail[0] != '\0') {
|
||||
flint_text_draw(unified_detail, x, *y, status_font, flint_darken(theme_get_text(), 40));
|
||||
flint_text_draw(unified_detail, x, *y, status_font,
|
||||
flint_darken(theme_get_text(), 40));
|
||||
*y += flint_px(18);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_status_reserved(int x, int *y, int reserved_h)
|
||||
void
|
||||
settings_screen_draw_status_reserved(int x, int *y, int reserved_h)
|
||||
{
|
||||
int status_y = *y;
|
||||
|
||||
@@ -235,368 +113,49 @@ settings_draw_status_reserved(int x, int *y, int reserved_h)
|
||||
*y += reserved_h;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_version_centered(int x, int w, int *y)
|
||||
{
|
||||
char version_text[32];
|
||||
int font = flint_ui_font_small();
|
||||
int text_w;
|
||||
|
||||
snprintf(version_text, sizeof(version_text), "v%s", INBE_VERSION_STRING);
|
||||
text_w = flint_text_measure(version_text, font);
|
||||
flint_text_draw(version_text, x + (w - text_w) / 2, *y, font, flint_darken(theme_get_text(), 40));
|
||||
*y += flint_px(22);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icon_columns(int content_w)
|
||||
settings_tab_content_height(InbeApp *app, int tab, int content_w)
|
||||
{
|
||||
int max_columns = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int total_w = icon_btn_w * max_columns + icon_spacing * (max_columns - 1);
|
||||
|
||||
return total_w <= content_w ? max_columns : 2;
|
||||
if(tab == SETTINGS_TAB_THEME)
|
||||
return settings_theme_content_height(content_w);
|
||||
if(tab == SETTINGS_TAB_DEVICE)
|
||||
return settings_device_content_height();
|
||||
if(settings_data_is_configuring(app))
|
||||
return flint_px(430);
|
||||
return settings_data_content_height(content_w);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_link_icons_height(int content_w)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int row_spacing = flint_px(16);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int rows = (link_count + columns - 1) / columns;
|
||||
|
||||
return flint_px(8) + rows * icon_btn_w + (rows - 1) * row_spacing;
|
||||
}
|
||||
|
||||
static int
|
||||
settings_data_content_height(int content_w)
|
||||
{
|
||||
int data_button_h = flint_px(36);
|
||||
|
||||
return flint_px(98) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
data_button_h + flint_px(12) +
|
||||
flint_px(42) +
|
||||
settings_link_icons_height(content_w) +
|
||||
flint_px(8) + flint_px(22) +
|
||||
flint_px(40);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_link_icons(InbeApp *app, int content_x, int content_w, int *y)
|
||||
{
|
||||
int link_count = 5;
|
||||
int icon_size = flint_px(32);
|
||||
int icon_padding = flint_px(4);
|
||||
int icon_spacing = flint_px(20);
|
||||
int icon_btn_w = icon_size + icon_padding * 2;
|
||||
int columns = settings_link_icon_columns(content_w);
|
||||
int grid_w = icon_btn_w * columns + icon_spacing * (columns - 1);
|
||||
int links_start_x = content_x + (content_w - grid_w) / 2;
|
||||
int row_spacing = flint_px(16);
|
||||
Texture2D icons[5] = {
|
||||
app->icons[UI_ICON_TYPE_DISCORD],
|
||||
app->icons[UI_ICON_TYPE_TELEGRAM],
|
||||
app->icons[UI_ICON_TYPE_GITHUB],
|
||||
app->icons[UI_ICON_TYPE_BTC],
|
||||
app->icons[UI_ICON_TYPE_MONERO]
|
||||
};
|
||||
const char *urls[5] = {
|
||||
"https://discord.com/invite/JbGZ4yENDt",
|
||||
"https://t.me/lotusinbe",
|
||||
"https://github.com/waozixyz/inbe",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=btc&network_to=Mainnet&address=bc1qxzcetg50f6epgddc09n82xqn3zswlmk44235y5&donation=True&simple_mode=True&amount=0.001&name=Inner+Breeze&[email protected]&ticker_from=btc&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff",
|
||||
"https://trocador.app/en/anonpay/?ticker_to=xmr&network_to=Mainnet&address=86CbC3d4a2GhT9auh6X99JhmhTMFKVVk8Q9cLrKTHkBu8LLkoNWgkBeAT3YZrvDM6NczYe8brUJNsTiFmwpWDZYnFG5kzSH&donation=True&simple_mode=True&amount=0.1&name=Inner+Breeze&[email protected]&ticker_from=xmr&network_from=Mainnet&buttonbgcolor=445588&textcolor=ffffff&bgcolor=eaeaffff"
|
||||
};
|
||||
|
||||
*y += flint_px(8);
|
||||
for(int i = 0; i < link_count; i++) {
|
||||
int col = i % columns;
|
||||
int row = i / columns;
|
||||
int icon_x = links_start_x + col * (icon_btn_w + icon_spacing) + icon_padding;
|
||||
int icon_y = *y + row * (icon_btn_w + row_spacing);
|
||||
ui_draw_icon_link(icon_x, icon_y, icon_size, icons[i], urls[i]);
|
||||
}
|
||||
*y += settings_link_icons_height(content_w) - flint_px(8);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_format_data_size(char *dst, size_t dst_size, long long data_size)
|
||||
{
|
||||
if(data_size < 1024)
|
||||
snprintf(dst, dst_size, "%lld B", data_size);
|
||||
else if(data_size < 1024 * 1024)
|
||||
snprintf(dst, dst_size, "%.1f KB", (float)data_size / 1024);
|
||||
else
|
||||
snprintf(dst, dst_size, "%.1f MB", (float)data_size / (1024 * 1024));
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_data_stats(int x, int y, int w)
|
||||
{
|
||||
int font = flint_ui_font();
|
||||
int session_count = data_get_session_count();
|
||||
long long data_size = data_get_total_size();
|
||||
char size_str[32];
|
||||
char stat_text[64];
|
||||
int stats_box_h = flint_px(66);
|
||||
int stat_x = x + flint_px(16);
|
||||
int stat_y = y + flint_px(16);
|
||||
|
||||
settings_format_data_size(size_str, sizeof(size_str), data_size);
|
||||
|
||||
DrawRectangle(x, y, w, stats_box_h, flint_darken(theme_get_bg(), 8));
|
||||
ui_draw_bevel(x, y, w, stats_box_h, flint_lighten(theme_get_bg(), 35), flint_darken(theme_get_bg(), 45));
|
||||
|
||||
locale_format(stat_text, sizeof(stat_text), "total_sessions_label", session_count);
|
||||
flint_text_draw(stat_text, stat_x, stat_y, font, theme_get_text());
|
||||
stat_y += flint_px(22);
|
||||
|
||||
locale_format(stat_text, sizeof(stat_text), "data_size_label", size_str);
|
||||
flint_text_draw(stat_text, stat_x, stat_y, font, theme_get_text());
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static void
|
||||
settings_apply_file_dialog_theme(InbeApp *app)
|
||||
{
|
||||
int theme_id = app != NULL ? app->theme_id : FLINT_THEME_SKY;
|
||||
int dark_mode = app != NULL && app->dark_mode != 0;
|
||||
|
||||
if(theme_id < 0 || theme_id >= FLINT_THEME_COUNT)
|
||||
theme_id = FLINT_THEME_SKY;
|
||||
flint_file_dialog_set_theme_scope(flint_theme_scope_for((FlintThemeId)theme_id,
|
||||
dark_mode != 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
static void
|
||||
settings_screen_handle_android_import(InbeApp *app)
|
||||
{
|
||||
char import_path[FS_PATH_MAX];
|
||||
int import_result = android_import_poll_result(import_path, sizeof(import_path));
|
||||
|
||||
if(import_result == ANDROID_IMPORT_RESULT_NONE)
|
||||
return;
|
||||
|
||||
if(import_result == ANDROID_IMPORT_RESULT_CANCELLED) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(import_path[0] == '\0') {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
return;
|
||||
}
|
||||
|
||||
settings_begin_import_for_path(app, import_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#define SETTINGS_WEB_IMPORT_PATH "/tmp/inbe-web-import.zip"
|
||||
|
||||
static void
|
||||
settings_web_import_open_picker(void)
|
||||
{
|
||||
EM_ASM({
|
||||
const importPath = UTF8ToString($0);
|
||||
Module.__inbeImportResult = 0;
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.accept = ".zip,.db,application/zip,application/x-sqlite3,application/octet-stream";
|
||||
input.style.display = "none";
|
||||
|
||||
input.onchange = async function() {
|
||||
try {
|
||||
if(!input.files || input.files.length === 0) {
|
||||
Module.__inbeImportResult = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
const file = input.files[0];
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
try {
|
||||
FS.mkdir("/tmp");
|
||||
} catch(e) {}
|
||||
FS.writeFile(importPath, bytes);
|
||||
Module.__inbeImportResult = 1;
|
||||
} catch(e) {
|
||||
console.error("Inbe web import failed:", e);
|
||||
Module.__inbeImportResult = 3;
|
||||
} finally {
|
||||
input.remove();
|
||||
}
|
||||
};
|
||||
|
||||
document.body.appendChild(input);
|
||||
input.click();
|
||||
}, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
|
||||
static void
|
||||
settings_screen_handle_web_import(InbeApp *app)
|
||||
{
|
||||
int import_result = EM_ASM_INT({
|
||||
const result = Module.__inbeImportResult || 0;
|
||||
if(result !== 0)
|
||||
Module.__inbeImportResult = 0;
|
||||
return result;
|
||||
});
|
||||
|
||||
if(import_result == 0)
|
||||
return;
|
||||
if(import_result == 2) {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
return;
|
||||
}
|
||||
if(import_result != 1) {
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
return;
|
||||
}
|
||||
|
||||
settings_begin_import_for_path(app, SETTINGS_WEB_IMPORT_PATH);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
settings_import_data(InbeApp *app)
|
||||
{
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
if(android_import_open_picker())
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
else
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#elif defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
settings_web_import_open_picker();
|
||||
settings_screen_set_status_success(locale_get("import_data_dialog_title"), NULL);
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_load(&import_dlg, locale_get("import_data_dialog_title"));
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_IMPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("import_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_export_data(InbeApp *app)
|
||||
{
|
||||
char export_filename[64];
|
||||
data_default_export_filename(export_filename, sizeof(export_filename));
|
||||
|
||||
if(!data_has_any()) {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_export"));
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
(void)app;
|
||||
if(data_export(export_filename)) {
|
||||
settings_screen_set_status_success(locale_get("exported_label"), NULL);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful (share sheet shown)");
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
#elif defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
settings_apply_file_dialog_theme(app);
|
||||
flint_file_dialog_begin_save(&export_dlg, locale_get("export_data_dialog_title"), export_filename);
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_EXPORT;
|
||||
#else
|
||||
(void)app;
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
settings_request_delete_all_data(InbeApp *app)
|
||||
{
|
||||
if(data_has_any()) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalConfirmDeleteData;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
static int
|
||||
settings_draw_pending_file_dialog(InbeApp *app)
|
||||
{
|
||||
FlintFileDialog *dlg;
|
||||
int result;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_NONE)
|
||||
return 0;
|
||||
|
||||
settings_apply_file_dialog_theme(app);
|
||||
dlg = data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT ? &import_dlg : &export_dlg;
|
||||
result = flint_file_dialog_update(dlg);
|
||||
if(result < 0)
|
||||
return 1;
|
||||
|
||||
if(data_file_dialog_action == SETTINGS_DATA_ACTION_IMPORT) {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&import_dlg);
|
||||
if(path != NULL && path[0] != '\0') {
|
||||
settings_begin_import_for_path(app, path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_invalid_file"));
|
||||
TraceLog(LOG_WARNING, "DATA: No file selected for import");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
}
|
||||
} else {
|
||||
if(result == 1) {
|
||||
const char *path = flint_file_dialog_get_path(&export_dlg);
|
||||
if(path != NULL && data_export(path)) {
|
||||
const char *filename = GetFileName(path);
|
||||
settings_screen_set_status_success(locale_get("exported_label"), filename);
|
||||
TraceLog(LOG_INFO, "DATA: Export successful to %s", path);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_failed"));
|
||||
TraceLog(LOG_ERROR, "DATA: Export failed");
|
||||
}
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("export_cancelled"));
|
||||
}
|
||||
}
|
||||
|
||||
data_file_dialog_action = SETTINGS_DATA_ACTION_NONE;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
settings_screen_draw(InbeApp *app)
|
||||
{
|
||||
int top_margin = 0;
|
||||
int content_x;
|
||||
int content_w;
|
||||
|
||||
int responsive_max_w = (int)(view_width * 0.96f);
|
||||
int max_content_w = flint_px(CONTENT_MAX_W);
|
||||
int min_content_w = flint_px(320);
|
||||
int side_padding;
|
||||
int detail_header_h;
|
||||
int top_tab_h;
|
||||
int top_tab_y;
|
||||
int tab_gap;
|
||||
int tab_content_start_y;
|
||||
int content_viewport_h;
|
||||
int clicked_top_tab = -1;
|
||||
const char *settings_tabs[] = {
|
||||
locale_get("settings_tab_device"),
|
||||
locale_get("settings_tab_theme"),
|
||||
locale_get("settings_tab_data"),
|
||||
};
|
||||
SettingsThemeState theme_state = {0};
|
||||
SettingsDeviceState device_state = {0};
|
||||
|
||||
if(responsive_max_w > max_content_w)
|
||||
responsive_max_w = max_content_w;
|
||||
if(responsive_max_w < min_content_w)
|
||||
responsive_max_w = min_content_w;
|
||||
int side_padding = flint_page_side_padding();
|
||||
|
||||
side_padding = flint_page_side_padding();
|
||||
flint_centered_column(responsive_max_w, side_padding, &content_x, &content_w);
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT))
|
||||
@@ -605,60 +164,47 @@ settings_screen_draw(InbeApp *app)
|
||||
if(app->settings_tab < SETTINGS_TAB_DEVICE || app->settings_tab >= SETTINGS_TAB_COUNT)
|
||||
app->settings_tab = SETTINGS_TAB_DEVICE;
|
||||
|
||||
#if defined(INBE_HAS_FLINT_FILE_DIALOG)
|
||||
if(settings_draw_pending_file_dialog(app))
|
||||
if(settings_data_draw_pending_file_dialog(app))
|
||||
return 1;
|
||||
#endif
|
||||
|
||||
int top_tab_h = flint_px(40);
|
||||
int top_tab_y = top_margin;
|
||||
int tab_gap = flint_px(14);
|
||||
int tab_content_start_y = top_tab_y + top_tab_h + tab_gap;
|
||||
int content_viewport_h = view_height - tab_content_start_y - flint_px(TAB_BAR_H);
|
||||
int clicked_top_tab = -1;
|
||||
const char *settings_tabs[] = {
|
||||
locale_get("settings_tab_device"),
|
||||
locale_get("settings_tab_theme"),
|
||||
locale_get("settings_tab_data"),
|
||||
};
|
||||
int language_menu_changed = 0;
|
||||
int draw_language_menu = 0;
|
||||
int draw_theme_mode_menu = 0;
|
||||
int draw_orientation_menu = 0;
|
||||
int theme_mode_changed = 0;
|
||||
int orientation_changed = 0;
|
||||
const char *theme_mode_options[] = {
|
||||
locale_get("theme_system"),
|
||||
locale_get("theme_light"),
|
||||
locale_get("theme_dark")
|
||||
};
|
||||
const char *orientation_options[] = {
|
||||
locale_get("orientation_system"),
|
||||
locale_get("orientation_portrait"),
|
||||
locale_get("orientation_landscape"),
|
||||
locale_get("orientation_sensor")
|
||||
};
|
||||
int orientation_option_count =
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
4;
|
||||
#else
|
||||
3;
|
||||
#endif
|
||||
detail_header_h = settings_data_is_configuring(app) ? flint_px(58) : 0;
|
||||
if(detail_header_h > 0) {
|
||||
FlintUIHeader header = ui_draw_title_header(detail_header_h,
|
||||
locale_get("sync_configure_account_button"),
|
||||
app->icons[UI_ICON_TYPE_RETURN],
|
||||
(Texture2D){0});
|
||||
if(header.left_clicked) {
|
||||
app->settings_data_view = 0;
|
||||
app->settings_scroll = 0;
|
||||
app->sync_server_url_focused = 0;
|
||||
settings_screen_clear_status();
|
||||
}
|
||||
}
|
||||
|
||||
top_tab_h = detail_header_h > 0 ? 0 : flint_px(40);
|
||||
top_tab_y = top_margin + detail_header_h;
|
||||
tab_gap = top_tab_h > 0 ? flint_px(14) : 0;
|
||||
tab_content_start_y = top_tab_y + top_tab_h + tab_gap;
|
||||
content_viewport_h = view_height - tab_content_start_y - flint_px(TAB_BAR_H);
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
settings_screen_handle_android_import(app);
|
||||
settings_data_handle_android_import(app);
|
||||
#elif defined(PLATFORM_WEB)
|
||||
settings_screen_handle_web_import(app);
|
||||
settings_data_handle_web_import(app);
|
||||
#endif
|
||||
|
||||
ui_set_input_blocked(app->modal.active);
|
||||
|
||||
if(content_viewport_h < 0)
|
||||
content_viewport_h = 0;
|
||||
|
||||
clicked_top_tab = settings_draw_subtab_bar(top_tab_y, top_tab_h, settings_tabs,
|
||||
SETTINGS_TAB_COUNT, app->settings_tab);
|
||||
if(top_tab_h > 0)
|
||||
clicked_top_tab = settings_draw_subtab_bar(top_tab_y, top_tab_h, settings_tabs,
|
||||
SETTINGS_TAB_COUNT, app->settings_tab);
|
||||
if(clicked_top_tab != -1) {
|
||||
app->settings_tab = clicked_top_tab;
|
||||
app->settings_scroll = 0;
|
||||
app->settings_data_view = 0;
|
||||
settings_screen_clear_status();
|
||||
}
|
||||
|
||||
@@ -673,20 +219,7 @@ settings_screen_draw(InbeApp *app)
|
||||
|
||||
if(planned_content_w < flint_px(160))
|
||||
planned_content_w = draw_w;
|
||||
if(app->settings_tab == SETTINGS_TAB_THEME) {
|
||||
app_content_h = flint_px(76) + ui_theme_picker_height(planned_content_w) + flint_px(60);
|
||||
} else if(app->settings_tab == SETTINGS_TAB_DEVICE) {
|
||||
app_content_h = flint_px(74) + flint_px(74) + flint_px(76) + flint_px(40);
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
app_content_h += flint_px(76);
|
||||
#endif
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
app_content_h += flint_px(50);
|
||||
#endif
|
||||
app_content_h += flint_px(72);
|
||||
} else {
|
||||
app_content_h = settings_data_content_height(draw_w);
|
||||
}
|
||||
app_content_h = settings_tab_content_height(app, app->settings_tab, planned_content_w);
|
||||
scroll_area = (FlintUIScrollArea){
|
||||
.bounds = {0.0f, (float)tab_content_start_y,
|
||||
(float)view_width, (float)content_viewport_h},
|
||||
@@ -702,209 +235,39 @@ settings_screen_draw(InbeApp *app)
|
||||
break;
|
||||
draw_w = measured.content_w;
|
||||
}
|
||||
int y;
|
||||
FlintUIScrollView scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
int draw_x = scroll_view.content_x;
|
||||
draw_w = scroll_view.content_w;
|
||||
y = scroll_view.content_y;
|
||||
|
||||
if(app->settings_tab == SETTINGS_TAB_THEME) {
|
||||
{
|
||||
int y;
|
||||
FlintUIScrollView scroll_view = ui_scroll_container_begin(scroll_area);
|
||||
int draw_x = scroll_view.content_x;
|
||||
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
flint_text_draw(locale_get("theme_mode_label"), draw_x, y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(102, draw_x, y + flint_px(26), draw_w,
|
||||
flint_px(36), theme_mode_options, 3, &app->theme_mode);
|
||||
draw_theme_mode_menu = 1;
|
||||
y += flint_px(76);
|
||||
if(ui_draw_theme_picker(draw_x, y, draw_w, locale_get("theme_label"),
|
||||
app->dark_mode, &app->theme_id)) {
|
||||
app->theme_id = clampi(app->theme_id, 0, FLINT_THEME_COUNT - 1);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
y += ui_theme_picker_height(draw_w) + flint_px(20);
|
||||
draw_w = scroll_view.content_w;
|
||||
y = scroll_view.content_y;
|
||||
|
||||
} else if(app->settings_tab == SETTINGS_TAB_DEVICE) {
|
||||
if(app->settings_tab == SETTINGS_TAB_THEME)
|
||||
settings_theme_draw(app, draw_x, draw_w, &y, &theme_state);
|
||||
else if(app->settings_tab == SETTINGS_TAB_DEVICE)
|
||||
settings_device_draw(app, draw_x, draw_w, &y, &device_state);
|
||||
else
|
||||
settings_data_draw(app, draw_x, draw_w, &y);
|
||||
|
||||
int sound_volume = app->sound_volume;
|
||||
int keyboard_toggle = app->on_screen_keyboard_enabled;
|
||||
int toggle_w = flint_px(56);
|
||||
int toggle_h = flint_px(30);
|
||||
|
||||
if(language_dropdown_button(app, 101, draw_x, y, draw_w, flint_px(36), &app->language_index))
|
||||
language_menu_changed = 1;
|
||||
draw_language_menu = 1;
|
||||
y += flint_px(74);
|
||||
|
||||
if(ui_draw_slider(6, draw_x, y, draw_w, locale_get("volume_label"),
|
||||
SETTINGS_VOLUME_MIN, SETTINGS_VOLUME_MAX, &sound_volume, "")) {
|
||||
app->sound_volume = sound_volume;
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
y += flint_px(74);
|
||||
#ifdef __ANDROID__
|
||||
{
|
||||
int play_in_background = app->inbe.play_in_background;
|
||||
flint_text_draw(locale_get("play_in_background_label"), draw_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(draw_x, y + flint_px(26), toggle_w, toggle_h,
|
||||
&play_in_background, locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->inbe.play_in_background = play_in_background;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(76);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode,
|
||||
APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
flint_text_draw(locale_get("orientation_label"), draw_x, y,
|
||||
flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(103, draw_x, y + flint_px(26), draw_w,
|
||||
flint_px(36), orientation_options, orientation_option_count,
|
||||
&app->orientation_mode);
|
||||
draw_orientation_menu = 1;
|
||||
y += flint_px(76);
|
||||
}
|
||||
#if !defined(PLATFORM_ANDROID) && !defined(__ANDROID__) && !defined(ANDROID) && !defined(PLATFORM_WEB)
|
||||
if(ui_draw_checkbox_toggle(draw_x, y, locale_get("fullscreen_label"), &app->fullscreen_enabled)) {
|
||||
if(app->fullscreen_enabled && !IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
else if(!app->fullscreen_enabled && IsWindowFullscreen())
|
||||
ToggleFullscreen();
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(50);
|
||||
#endif
|
||||
flint_text_draw(locale_get("on_screen_keyboard_label"), draw_x, y, flint_ui_font(), theme_get_text());
|
||||
if(ui_draw_toggle_switch(draw_x, y + flint_px(26), toggle_w, toggle_h,
|
||||
&keyboard_toggle, locale_get("toggle_off"), locale_get("toggle_on"))) {
|
||||
app->on_screen_keyboard_enabled = keyboard_toggle;
|
||||
app->settings_dirty = 1;
|
||||
}
|
||||
y += flint_px(76);
|
||||
|
||||
} else {
|
||||
|
||||
int data_button_h = flint_px(36);
|
||||
int hover_import = 0;
|
||||
int hover_export = 0;
|
||||
int hover_delete = 0;
|
||||
|
||||
settings_draw_data_stats(draw_x, y, draw_w);
|
||||
y += flint_px(98);
|
||||
|
||||
if(ui_draw_generic_button(draw_x, y, draw_w, data_button_h,
|
||||
locale_get("import_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_import))
|
||||
settings_import_data(app);
|
||||
y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(draw_x, y, draw_w, data_button_h,
|
||||
locale_get("export_data_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover_export))
|
||||
settings_export_data(app);
|
||||
y += data_button_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(draw_x, y, draw_w, data_button_h,
|
||||
locale_get("delete_all_data_button"),
|
||||
UI_BUTTON_STYLE_DANGER, 0, &hover_delete))
|
||||
settings_request_delete_all_data(app);
|
||||
y += data_button_h + flint_px(12);
|
||||
settings_draw_status_reserved(draw_x, &y, flint_px(42));
|
||||
settings_draw_link_icons(app, draw_x, draw_w, &y);
|
||||
y += flint_px(8);
|
||||
settings_draw_version_centered(draw_x, draw_w, &y);
|
||||
y += flint_px(40);
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
}
|
||||
y += flint_px(40);
|
||||
ui_scroll_container_end(scroll_area, scroll_view);
|
||||
}
|
||||
|
||||
ui_set_dropdown_clip_top(tab_content_start_y);
|
||||
if(draw_language_menu && language_dropdown_menu(app, 101))
|
||||
language_menu_changed = 1;
|
||||
if(draw_theme_mode_menu && ui_draw_dropdown_menu(102))
|
||||
theme_mode_changed = 1;
|
||||
if(draw_orientation_menu && ui_draw_dropdown_menu(103))
|
||||
orientation_changed = 1;
|
||||
if(language_menu_changed)
|
||||
apply_language_selection(app, app->language_index, 1);
|
||||
if(theme_mode_changed) {
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
if(orientation_changed) {
|
||||
int orientation_max = orientation_option_count - 1;
|
||||
app->orientation_mode = clampi(app->orientation_mode, APP_ORIENTATION_SYSTEM,
|
||||
orientation_max);
|
||||
app_apply_orientation_preference(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
if(app->settings_tab == SETTINGS_TAB_THEME)
|
||||
settings_theme_handle_overlays(app, &theme_state);
|
||||
else if(app->settings_tab == SETTINGS_TAB_DEVICE)
|
||||
settings_device_handle_overlays(app, &device_state);
|
||||
ui_set_dropdown_clip_top(0);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmImportDataSettings) {
|
||||
int modal_result = settings_draw_import_choice_modal(app);
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_screen_set_status_error(locale_get("import_cancelled"));
|
||||
} else if(modal_result == 2 || modal_result == 3) {
|
||||
char import_path[FS_PATH_MAX];
|
||||
DataImportMode mode = modal_result == 3
|
||||
? DATA_IMPORT_DATA_AND_SETTINGS
|
||||
: DATA_IMPORT_DATA_ONLY;
|
||||
snprintf(import_path, sizeof(import_path), "%s", pending_import_path);
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_clear_pending_import();
|
||||
settings_perform_import(app, import_path, mode);
|
||||
}
|
||||
}
|
||||
ui_set_input_blocked(0);
|
||||
settings_data_draw_modals(app);
|
||||
|
||||
if(app->modal.active && app->modal.type == UIModalConfirmDeleteData) {
|
||||
int modal_result = ui_draw_modal(locale_get("delete_all_data_title"),
|
||||
locale_get("delete_all_data_message"),
|
||||
locale_get("cancel_button"),
|
||||
locale_get("delete_button"));
|
||||
if(modal_result == 1) {
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
settings_screen_set_status_error(locale_get("delete_cancelled"));
|
||||
} else if(modal_result == 2) {
|
||||
long long deleted = data_delete_all();
|
||||
app->modal.active = 0;
|
||||
app->modal.type = UIModalNone;
|
||||
if(deleted > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_clear_days(&app->habits);
|
||||
inbe_habits_save(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message), "deleted_sessions", deleted);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
int cleared = inbe_habits_clear_days(&app->habits);
|
||||
if(cleared > 0) {
|
||||
char deleted_message[128];
|
||||
inbe_habits_save(&app->habits);
|
||||
locale_format(deleted_message, sizeof(deleted_message), "deleted_sessions", cleared);
|
||||
settings_screen_set_status_success(deleted_message, NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("no_data_to_delete"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) {
|
||||
if(app->settings_dirty)
|
||||
save_settings(app);
|
||||
}
|
||||
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT) && app->settings_dirty)
|
||||
save_settings(app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -9,5 +9,6 @@ int settings_screen_draw(InbeApp *app);
|
||||
void settings_screen_clear_status(void);
|
||||
void settings_screen_set_status_success(const char *message, const char *detail);
|
||||
void settings_screen_set_status_error(const char *message);
|
||||
void settings_screen_draw_status_reserved(int x, int *y, int reserved_h);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,382 @@
|
||||
#include "settings_sync_account.h"
|
||||
|
||||
#include "settings_screen.h"
|
||||
#include "app.h"
|
||||
#include "locale.h"
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
#include "sync_client.h"
|
||||
#include "theme.h"
|
||||
#include "flint_ui.h"
|
||||
#include "raylib.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define INBE_SYNC_SERVER_URL_KEY "sync_server_url"
|
||||
#define INBE_SYNC_SERVER_URL_DEFAULT "https://api.waozi.xyz"
|
||||
#define INBE_SYNC_ENABLED_KEY "sync_enabled"
|
||||
#define INBE_SYNC_CONNECTED_URL_KEY "sync_connected_url"
|
||||
|
||||
static SettingsSyncKeySaveDialog save_dialog_callback = NULL;
|
||||
|
||||
void
|
||||
settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback)
|
||||
{
|
||||
save_dialog_callback = callback;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_draw_hex_groups(const char *text, int x, int *y, int font, Color color,
|
||||
int groups, int group_chars)
|
||||
{
|
||||
char line[128];
|
||||
int offset = 0;
|
||||
|
||||
if(text == NULL || y == NULL)
|
||||
return;
|
||||
for(int i = 0; i < groups && text[offset] != '\0'; i++) {
|
||||
int len = group_chars;
|
||||
if((int)strlen(text + offset) < len)
|
||||
len = (int)strlen(text + offset);
|
||||
snprintf(line, sizeof(line), "%.*s", len, text + offset);
|
||||
flint_text_draw(line, x, *y, font, color);
|
||||
*y += flint_px(17);
|
||||
offset += len;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_backup_filename(char *out, size_t out_size)
|
||||
{
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
snprintf(out, out_size, "inbe-sync.key");
|
||||
}
|
||||
|
||||
static int
|
||||
settings_start_sync_key_export(InbeApp *app, const InbeSyncAccount *account)
|
||||
{
|
||||
char filename[64];
|
||||
|
||||
settings_backup_filename(filename, sizeof(filename));
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID) || defined(PLATFORM_WEB)
|
||||
(void)app;
|
||||
return inbe_sync_account_export_private_key(account, filename) ? 2 : 3;
|
||||
#else
|
||||
if(save_dialog_callback != NULL)
|
||||
return save_dialog_callback(app, filename);
|
||||
return inbe_sync_account_export_private_key(account, filename) ? 2 : 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_url_filter(int codepoint, void *user_data)
|
||||
{
|
||||
(void)user_data;
|
||||
return codepoint >= 33 && codepoint <= 126 && !isspace(codepoint);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_server_normalize(InbeApp *app, char *out, size_t out_size)
|
||||
{
|
||||
if(app == NULL || out == NULL || out_size == 0)
|
||||
return 0;
|
||||
if(!inbe_sync_client_normalize_url(app->sync_server_url, out, out_size))
|
||||
return 0;
|
||||
snprintf(app->sync_server_url, sizeof(app->sync_server_url), "%s", out);
|
||||
app->sync_server_url_cursor = (int)strlen(app->sync_server_url);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_server_save(InbeApp *app)
|
||||
{
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
const char *connected_url;
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!settings_sync_server_normalize(app, url, sizeof(url))) {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
return;
|
||||
}
|
||||
inbe_storage_set_setting_text(INBE_SYNC_SERVER_URL_KEY, url);
|
||||
connected_url = inbe_storage_get_setting_text(INBE_SYNC_CONNECTED_URL_KEY);
|
||||
if(connected_url == NULL || strcmp(connected_url, url) != 0)
|
||||
inbe_storage_set_setting_int(INBE_SYNC_ENABLED_KEY, 0);
|
||||
settings_screen_set_status_success(locale_get("sync_server_saved"), url);
|
||||
}
|
||||
|
||||
static int
|
||||
settings_sync_server_connected(InbeApp *app)
|
||||
{
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
const char *connected_url;
|
||||
|
||||
if(app == NULL || inbe_storage_get_setting_int(INBE_SYNC_ENABLED_KEY, 0) == 0)
|
||||
return 0;
|
||||
if(!inbe_sync_client_normalize_url(app->sync_server_url, url, sizeof(url)))
|
||||
return 0;
|
||||
connected_url = inbe_storage_get_setting_text(INBE_SYNC_CONNECTED_URL_KEY);
|
||||
return connected_url != NULL && strcmp(connected_url, url) == 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
settings_sync_result_key(InbeSyncClientResult result)
|
||||
{
|
||||
switch(result) {
|
||||
case INBE_SYNC_CLIENT_OK:
|
||||
return "sync_connected";
|
||||
case INBE_SYNC_CLIENT_UNAVAILABLE:
|
||||
return "sync_unavailable";
|
||||
case INBE_SYNC_CLIENT_INVALID_URL:
|
||||
return "sync_server_url_invalid";
|
||||
case INBE_SYNC_CLIENT_NO_ACCOUNT:
|
||||
return "sync_no_account";
|
||||
case INBE_SYNC_CLIENT_AUTH_FAILED:
|
||||
return "sync_auth_failed";
|
||||
case INBE_SYNC_CLIENT_PAYLOAD_FAILED:
|
||||
case INBE_SYNC_CLIENT_CHALLENGE_FAILED:
|
||||
case INBE_SYNC_CLIENT_SIGN_FAILED:
|
||||
case INBE_SYNC_CLIENT_REQUEST_FAILED:
|
||||
default:
|
||||
return "sync_failed";
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_sync_run_connect(InbeApp *app)
|
||||
{
|
||||
InbeSyncClientResult result;
|
||||
char url[sizeof(app->sync_server_url)];
|
||||
|
||||
if(app == NULL)
|
||||
return;
|
||||
if(!settings_sync_server_normalize(app, url, sizeof(url))) {
|
||||
settings_screen_set_status_error(locale_get("sync_server_url_invalid"));
|
||||
return;
|
||||
}
|
||||
inbe_storage_set_setting_text(INBE_SYNC_SERVER_URL_KEY, url);
|
||||
result = inbe_sync_client_sync(url);
|
||||
if(result == INBE_SYNC_CLIENT_OK) {
|
||||
inbe_storage_set_setting_int(INBE_SYNC_ENABLED_KEY, 1);
|
||||
inbe_storage_set_setting_text(INBE_SYNC_CONNECTED_URL_KEY, url);
|
||||
settings_screen_set_status_success(locale_get(settings_sync_result_key(result)), NULL);
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get(settings_sync_result_key(result)));
|
||||
}
|
||||
}
|
||||
|
||||
static FlintUITextInputStyle
|
||||
settings_sync_text_style(void)
|
||||
{
|
||||
return (FlintUITextInputStyle){
|
||||
.background = flint_darken(theme_get_bg(), 4),
|
||||
.border = theme_get_button(),
|
||||
.focus_border = theme_get_button_hover(),
|
||||
.text = theme_get_text(),
|
||||
.cursor = theme_get_text(),
|
||||
.radius = 0.08f,
|
||||
.padding_x = flint_px(10)
|
||||
};
|
||||
}
|
||||
|
||||
void
|
||||
settings_sync_account_draw(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
int has_account = inbe_sync_account_load(&account);
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int half_w = (w - gap) / 2;
|
||||
int hover = 0;
|
||||
|
||||
flint_text_draw(locale_get("sync_account_title"), x, *y, font, theme_get_text());
|
||||
*y += flint_px(26);
|
||||
|
||||
if(!inbe_sync_account_available()) {
|
||||
flint_text_draw(locale_get("sync_liboqs_unavailable"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 35));
|
||||
*y += flint_px(32);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!has_account) {
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h, locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(18);
|
||||
return;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("sync_public_id_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
settings_draw_hex_groups(account.public_id, x, y, small_font, theme_get_text(), 2, 32);
|
||||
*y += flint_px(4);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, half_w, btn_h, locale_get("sync_copy_id_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
SetClipboardText(account.public_id);
|
||||
settings_screen_set_status_success(locale_get("sync_public_id_copied"), NULL);
|
||||
}
|
||||
if(ui_draw_generic_button(x + half_w + gap, *y, half_w, btn_h,
|
||||
locale_get("sync_backup_key_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
*y += btn_h + flint_px(16);
|
||||
}
|
||||
|
||||
void
|
||||
settings_sync_account_draw_config(InbeApp *app, int x, int w, int *y)
|
||||
{
|
||||
InbeSyncAccount account;
|
||||
int has_account = inbe_sync_account_load(&account);
|
||||
int font = flint_ui_font();
|
||||
int small_font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int half_w = (w - gap) / 2;
|
||||
int hover = 0;
|
||||
int commit = 0;
|
||||
FlintUITextInputStyle input_style = settings_sync_text_style();
|
||||
|
||||
if(!inbe_sync_account_available()) {
|
||||
flint_text_draw(locale_get("sync_liboqs_unavailable"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 35));
|
||||
*y += flint_px(32);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!has_account) {
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h, locale_get("sync_create_account_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover)) {
|
||||
if(inbe_sync_account_create(&account)) {
|
||||
settings_screen_set_status_success(locale_get("sync_account_created"), NULL);
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
} else {
|
||||
settings_screen_set_status_error(locale_get("sync_account_create_failed"));
|
||||
}
|
||||
}
|
||||
*y += btn_h + flint_px(18);
|
||||
return;
|
||||
}
|
||||
|
||||
flint_text_draw(locale_get("sync_public_id_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
settings_draw_hex_groups(account.public_id, x, y, small_font, theme_get_text(), 2, 32);
|
||||
*y += flint_px(8);
|
||||
|
||||
flint_text_draw(locale_get("sync_remote_label"), x, *y, small_font,
|
||||
flint_darken(theme_get_text(), 30));
|
||||
*y += flint_px(18);
|
||||
flint_ui_text_field((FlintUITextField){
|
||||
.bounds = {(float)x, (float)*y, (float)w, (float)btn_h},
|
||||
.text = app->sync_server_url,
|
||||
.text_size = sizeof(app->sync_server_url),
|
||||
.cursor_position = &app->sync_server_url_cursor,
|
||||
.focused = &app->sync_server_url_focused,
|
||||
.max_codepoints = 255,
|
||||
.font = small_font,
|
||||
.style = input_style,
|
||||
.filter = settings_sync_url_filter,
|
||||
.commit_pressed = &commit
|
||||
});
|
||||
if(commit)
|
||||
settings_sync_server_save(app);
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, w, btn_h,
|
||||
settings_sync_server_connected(app)
|
||||
? locale_get("sync_connected_button")
|
||||
: locale_get("sync_connect_button"),
|
||||
UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
settings_sync_run_connect(app);
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
if(ui_draw_generic_button(x, *y, half_w, btn_h, locale_get("sync_copy_id_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
SetClipboardText(account.public_id);
|
||||
settings_screen_set_status_success(locale_get("sync_public_id_copied"), NULL);
|
||||
}
|
||||
if(ui_draw_generic_button(x + half_w + gap, *y, half_w, btn_h,
|
||||
locale_get("sync_backup_key_button"),
|
||||
UI_BUTTON_STYLE_SECONDARY, 0, &hover)) {
|
||||
app->modal.active = 1;
|
||||
app->modal.type = UIModalSyncAccountBackup;
|
||||
app->modal.selected_button = 0;
|
||||
}
|
||||
*y += btn_h + flint_px(12);
|
||||
|
||||
settings_screen_draw_status_reserved(x, y, flint_px(42));
|
||||
(void)font;
|
||||
}
|
||||
|
||||
int
|
||||
settings_sync_account_draw_backup_modal(InbeApp *app)
|
||||
{
|
||||
FlintUIPanelFrame frame;
|
||||
InbeSyncAccount account;
|
||||
int font = flint_ui_font_small();
|
||||
int btn_h = flint_px(36);
|
||||
int gap = flint_px(10);
|
||||
int pad_bottom = flint_px(24);
|
||||
int text_button_gap = flint_px(40);
|
||||
int hover = 0;
|
||||
int y;
|
||||
int modal_h;
|
||||
int button_y;
|
||||
FlintUIParagraph warning;
|
||||
|
||||
memset(&account, 0, sizeof(account));
|
||||
inbe_sync_account_load(&account);
|
||||
|
||||
warning = (FlintUIParagraph){
|
||||
.text = locale_get("sync_backup_warning"),
|
||||
.width = flint_px(336) - flint_px(36),
|
||||
.font = font,
|
||||
.line_gap = flint_px(4),
|
||||
.color = theme_get_text()
|
||||
};
|
||||
modal_h = flint_px(58) +
|
||||
flint_ui_paragraph_height(warning) +
|
||||
text_button_gap +
|
||||
btn_h * 2 + gap +
|
||||
pad_bottom;
|
||||
if(modal_h < flint_px(224))
|
||||
modal_h = flint_px(224);
|
||||
|
||||
frame = ui_draw_modal_frame(flint_px(336), modal_h, locale_get("sync_backup_title"),
|
||||
(Texture2D){0}, (Texture2D){0});
|
||||
y = frame.content_y;
|
||||
warning.width = frame.content_w;
|
||||
flint_ui_paragraph_draw(warning, frame.content_x, &y);
|
||||
|
||||
button_y = y + text_button_gap;
|
||||
if(button_y + btn_h * 2 + gap + pad_bottom > frame.y + frame.h)
|
||||
button_y = frame.y + frame.h - pad_bottom - btn_h * 2 - gap;
|
||||
if(ui_draw_generic_button(frame.content_x, button_y, frame.content_w, btn_h,
|
||||
locale_get("sync_save_key_file_button"), UI_BUTTON_STYLE_PRIMARY, 0, &hover))
|
||||
return settings_start_sync_key_export(app, &account);
|
||||
if(ui_draw_generic_button(frame.content_x, button_y + btn_h + gap, frame.content_w,
|
||||
btn_h, locale_get("close_button"), UI_BUTTON_STYLE_SECONDARY, 0, &hover))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef INBE_SETTINGS_SYNC_ACCOUNT_H
|
||||
#define INBE_SETTINGS_SYNC_ACCOUNT_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef int (*SettingsSyncKeySaveDialog)(InbeApp *app, const char *filename);
|
||||
|
||||
void settings_sync_account_set_save_dialog(SettingsSyncKeySaveDialog callback);
|
||||
void settings_sync_account_draw(InbeApp *app, int x, int w, int *y);
|
||||
void settings_sync_account_draw_config(InbeApp *app, int x, int w, int *y);
|
||||
int settings_sync_account_draw_backup_modal(InbeApp *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "settings_theme.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "app_settings.h"
|
||||
#include "device_preferences.h"
|
||||
#include "locale.h"
|
||||
#include "theme.h"
|
||||
#include "flint_theme_meta.h"
|
||||
#include "flint_ui.h"
|
||||
|
||||
int
|
||||
settings_theme_content_height(int content_w)
|
||||
{
|
||||
return flint_px(76) + ui_theme_picker_height(content_w) + flint_px(60);
|
||||
}
|
||||
|
||||
void
|
||||
settings_theme_draw(InbeApp *app, int x, int w, int *y, SettingsThemeState *state)
|
||||
{
|
||||
const char *theme_mode_options[] = {
|
||||
locale_get("theme_system"),
|
||||
locale_get("theme_light"),
|
||||
locale_get("theme_dark")
|
||||
};
|
||||
|
||||
if(app == NULL || y == NULL || state == NULL)
|
||||
return;
|
||||
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
flint_text_draw(locale_get("theme_mode_label"), x, *y, flint_ui_font(), theme_get_text());
|
||||
ui_draw_dropdown_button(102, x, *y + flint_px(26), w, flint_px(36),
|
||||
theme_mode_options, 3, &app->theme_mode);
|
||||
state->draw_theme_mode_menu = 1;
|
||||
*y += flint_px(76);
|
||||
|
||||
if(ui_draw_theme_picker(x, *y, w, locale_get("theme_label"),
|
||||
app->dark_mode, &app->theme_id)) {
|
||||
app->theme_id = clampi(app->theme_id, 0, FLINT_THEME_COUNT - 1);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
*y += ui_theme_picker_height(w) + flint_px(20);
|
||||
}
|
||||
|
||||
void
|
||||
settings_theme_handle_overlays(InbeApp *app, const SettingsThemeState *state)
|
||||
{
|
||||
int theme_mode_changed = 0;
|
||||
|
||||
if(app == NULL || state == NULL)
|
||||
return;
|
||||
if(state->draw_theme_mode_menu && ui_draw_dropdown_menu(102))
|
||||
theme_mode_changed = 1;
|
||||
if(theme_mode_changed) {
|
||||
app->theme_mode = clampi(app->theme_mode, APP_THEME_SYSTEM, APP_THEME_DARK);
|
||||
app_refresh_theme(app);
|
||||
app->settings_dirty = 1;
|
||||
save_settings(app);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef INBE_SETTINGS_THEME_H
|
||||
#define INBE_SETTINGS_THEME_H
|
||||
|
||||
#include "app_fwd.h"
|
||||
|
||||
typedef struct SettingsThemeState {
|
||||
int draw_theme_mode_menu;
|
||||
} SettingsThemeState;
|
||||
|
||||
int settings_theme_content_height(int content_w);
|
||||
void settings_theme_draw(InbeApp *app, int x, int w, int *y, SettingsThemeState *state);
|
||||
void settings_theme_handle_overlays(InbeApp *app, const SettingsThemeState *state);
|
||||
|
||||
#endif
|
||||
+501
-66
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "raylib.h"
|
||||
#include <sqlite3.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -35,11 +36,144 @@ typedef struct StorageState {
|
||||
char root[INBE_STORAGE_PATH_SIZE];
|
||||
char db_path[INBE_STORAGE_PATH_SIZE];
|
||||
char user_id[INBE_STORAGE_ID_SIZE];
|
||||
char text_value[256];
|
||||
char text_value[8192];
|
||||
} StorageState;
|
||||
|
||||
static StorageState g_storage;
|
||||
|
||||
typedef struct JsonBuilder {
|
||||
char *data;
|
||||
size_t len;
|
||||
size_t cap;
|
||||
int ok;
|
||||
} JsonBuilder;
|
||||
|
||||
static int
|
||||
json_reserve(JsonBuilder *json, size_t extra)
|
||||
{
|
||||
char *next;
|
||||
size_t next_cap;
|
||||
|
||||
if(json == NULL || !json->ok)
|
||||
return 0;
|
||||
if(extra <= json->cap - json->len)
|
||||
return 1;
|
||||
next_cap = json->cap > 0 ? json->cap : 1024;
|
||||
while(extra > next_cap - json->len)
|
||||
next_cap *= 2;
|
||||
next = (char *)realloc(json->data, next_cap);
|
||||
if(next == NULL) {
|
||||
json->ok = 0;
|
||||
return 0;
|
||||
}
|
||||
json->data = next;
|
||||
json->cap = next_cap;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_len(JsonBuilder *json, const char *text, size_t len)
|
||||
{
|
||||
if(text == NULL || len == 0)
|
||||
return;
|
||||
if(!json_reserve(json, len + 1))
|
||||
return;
|
||||
memcpy(json->data + json->len, text, len);
|
||||
json->len += len;
|
||||
json->data[json->len] = '\0';
|
||||
}
|
||||
|
||||
static void
|
||||
json_append(JsonBuilder *json, const char *text)
|
||||
{
|
||||
if(text != NULL)
|
||||
json_append_len(json, text, strlen(text));
|
||||
}
|
||||
|
||||
static void
|
||||
json_appendf(JsonBuilder *json, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_list copy;
|
||||
int needed;
|
||||
|
||||
if(json == NULL || fmt == NULL || !json->ok)
|
||||
return;
|
||||
va_start(args, fmt);
|
||||
va_copy(copy, args);
|
||||
needed = vsnprintf(NULL, 0, fmt, copy);
|
||||
va_end(copy);
|
||||
if(needed < 0) {
|
||||
json->ok = 0;
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
if(json_reserve(json, (size_t)needed + 1)) {
|
||||
vsnprintf(json->data + json->len, json->cap - json->len, fmt, args);
|
||||
json->len += (size_t)needed;
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_string(JsonBuilder *json, const char *text)
|
||||
{
|
||||
const unsigned char *p = (const unsigned char *)(text != NULL ? text : "");
|
||||
|
||||
json_append(json, "\"");
|
||||
while(*p != '\0') {
|
||||
char escaped[8];
|
||||
if(*p == '"' || *p == '\\') {
|
||||
escaped[0] = '\\';
|
||||
escaped[1] = (char)*p;
|
||||
json_append_len(json, escaped, 2);
|
||||
} else if(*p == '\b') {
|
||||
json_append(json, "\\b");
|
||||
} else if(*p == '\f') {
|
||||
json_append(json, "\\f");
|
||||
} else if(*p == '\n') {
|
||||
json_append(json, "\\n");
|
||||
} else if(*p == '\r') {
|
||||
json_append(json, "\\r");
|
||||
} else if(*p == '\t') {
|
||||
json_append(json, "\\t");
|
||||
} else if(*p < 0x20) {
|
||||
snprintf(escaped, sizeof(escaped), "\\u%04x", *p);
|
||||
json_append(json, escaped);
|
||||
} else {
|
||||
json_append_len(json, (const char *)p, 1);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
json_append(json, "\"");
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_key_string(JsonBuilder *json, const char *key, const char *value)
|
||||
{
|
||||
json_append_string(json, key);
|
||||
json_append(json, ":");
|
||||
json_append_string(json, value);
|
||||
}
|
||||
|
||||
static void
|
||||
json_append_epoch(JsonBuilder *json, long long seconds)
|
||||
{
|
||||
char formatted[32];
|
||||
struct tm tm_value;
|
||||
time_t value = (time_t)seconds;
|
||||
|
||||
if(seconds <= 0)
|
||||
value = time(NULL);
|
||||
#if defined(_WIN32)
|
||||
gmtime_s(&tm_value, &value);
|
||||
#else
|
||||
gmtime_r(&value, &tm_value);
|
||||
#endif
|
||||
strftime(formatted, sizeof(formatted), "%Y-%m-%dT%H:%M:%SZ", &tm_value);
|
||||
json_append_string(json, formatted);
|
||||
}
|
||||
|
||||
static void
|
||||
storage_schedule_persist(void)
|
||||
{
|
||||
@@ -150,29 +284,37 @@ table_has_column(const char *table, const char *column)
|
||||
static int
|
||||
migrate_schema(void)
|
||||
{
|
||||
if(!table_has_column("habits", "sync_topic"))
|
||||
return 1;
|
||||
|
||||
return exec_sql(
|
||||
"BEGIN IMMEDIATE;"
|
||||
"ALTER TABLE habits RENAME TO habits_with_sync_topic;"
|
||||
"CREATE TABLE habits("
|
||||
" id TEXT PRIMARY KEY,"
|
||||
" user_id TEXT NOT NULL,"
|
||||
" name TEXT NOT NULL,"
|
||||
" color_r INTEGER NOT NULL,"
|
||||
" color_g INTEGER NOT NULL,"
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at)"
|
||||
" SELECT id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at"
|
||||
" FROM habits_with_sync_topic;"
|
||||
"DROP TABLE habits_with_sync_topic;"
|
||||
"COMMIT;");
|
||||
if(table_has_column("habits", "sync_topic")) {
|
||||
if(!exec_sql(
|
||||
"BEGIN IMMEDIATE;"
|
||||
"ALTER TABLE habits RENAME TO habits_with_sync_topic;"
|
||||
"CREATE TABLE habits("
|
||||
" id TEXT PRIMARY KEY,"
|
||||
" user_id TEXT NOT NULL,"
|
||||
" name TEXT NOT NULL,"
|
||||
" color_r INTEGER NOT NULL,"
|
||||
" color_g INTEGER NOT NULL,"
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at)"
|
||||
" SELECT id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at"
|
||||
" FROM habits_with_sync_topic;"
|
||||
"DROP TABLE habits_with_sync_topic;"
|
||||
"COMMIT;"))
|
||||
return 0;
|
||||
}
|
||||
if(!table_has_column("habits", "counter_enabled") &&
|
||||
!exec_sql("ALTER TABLE habits ADD COLUMN counter_enabled INTEGER NOT NULL DEFAULT 0"))
|
||||
return 0;
|
||||
if(!table_has_column("habit_days", "count") &&
|
||||
!exec_sql("ALTER TABLE habit_days ADD COLUMN count INTEGER NOT NULL DEFAULT 0;"
|
||||
"UPDATE habit_days SET count=CASE WHEN completed!=0 THEN 1 ELSE 0 END WHERE count=0"))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -472,6 +614,7 @@ schema_create(void)
|
||||
" color_b INTEGER NOT NULL,"
|
||||
" sync_mode INTEGER NOT NULL,"
|
||||
" sync_activity INTEGER NOT NULL,"
|
||||
" counter_enabled INTEGER NOT NULL DEFAULT 0,"
|
||||
" sort_order INTEGER NOT NULL,"
|
||||
" deleted_at INTEGER NOT NULL DEFAULT 0"
|
||||
");"
|
||||
@@ -479,6 +622,7 @@ schema_create(void)
|
||||
" habit_id TEXT NOT NULL,"
|
||||
" local_date INTEGER NOT NULL,"
|
||||
" completed INTEGER NOT NULL,"
|
||||
" count INTEGER NOT NULL DEFAULT 0,"
|
||||
" updated_at INTEGER NOT NULL,"
|
||||
" PRIMARY KEY(habit_id,local_date)"
|
||||
");"
|
||||
@@ -892,6 +1036,224 @@ inbe_storage_delete_session(const char *path_or_id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_preferences_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"preferences\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT key,value,updated_at FROM settings "
|
||||
"WHERE user_id=?1 AND key NOT LIKE 'sync_%' ORDER BY key",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *key = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *value = (const char *)sqlite3_column_text(stmt, 1);
|
||||
long long updated_at = sqlite3_column_int64(stmt, 2);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "key", key);
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "value", value);
|
||||
json_append(json, ",\"updated_at\":");
|
||||
json_append_epoch(json, updated_at);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_habits_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
long long exported_at = now_seconds();
|
||||
|
||||
json_append(json, "\"habits\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at "
|
||||
"FROM habits WHERE user_id=?1 ORDER BY sort_order,id",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "id", (const char *)sqlite3_column_text(stmt, 0));
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "name", (const char *)sqlite3_column_text(stmt, 1));
|
||||
json_appendf(json, ",\"color_r\":%d,\"color_g\":%d,\"color_b\":%d",
|
||||
sqlite3_column_int(stmt, 2),
|
||||
sqlite3_column_int(stmt, 3),
|
||||
sqlite3_column_int(stmt, 4));
|
||||
json_appendf(json, ",\"sync_mode\":%d,\"sync_activity\":%d,\"counter_enabled\":%d,\"sort_order\":%d,\"deleted_at\":%lld",
|
||||
sqlite3_column_int(stmt, 5),
|
||||
sqlite3_column_int(stmt, 6),
|
||||
(sqlite3_column_int(stmt, 7) != 0 ||
|
||||
sqlite3_column_int(stmt, 6) != 0) ? 1 : 0,
|
||||
sqlite3_column_int(stmt, 8),
|
||||
sqlite3_column_int64(stmt, 9));
|
||||
json_append(json, ",\"updated_at\":");
|
||||
json_append_epoch(json, exported_at);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_habit_days_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"habit_days\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT hd.habit_id,hd.local_date,hd.completed,hd.count,hd.updated_at "
|
||||
"FROM habit_days hd JOIN habits h ON h.id=hd.habit_id "
|
||||
"WHERE h.user_id=?1 ORDER BY hd.habit_id,hd.local_date",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "habit_id", (const char *)sqlite3_column_text(stmt, 0));
|
||||
json_appendf(json, ",\"local_date\":%d,\"completed\":%s,\"count\":%d,\"updated_at\":",
|
||||
sqlite3_column_int(stmt, 1),
|
||||
sqlite3_column_int(stmt, 2) != 0 ? "true" : "false",
|
||||
sqlite3_column_int(stmt, 3));
|
||||
json_append_epoch(json, sqlite3_column_int64(stmt, 4));
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_session_rounds_json(JsonBuilder *json, const char *session_id)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"rounds\":[");
|
||||
if(g_storage.db != NULL && session_id != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT round_index,seconds FROM session_rounds "
|
||||
"WHERE session_id=?1 ORDER BY round_index",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, session_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int seconds = sqlite3_column_int(stmt, 1);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_appendf(json, "{\"round_index\":%d,\"breaths\":0,\"hold_seconds\":%d}",
|
||||
sqlite3_column_int(stmt, 0), seconds);
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
static void
|
||||
storage_append_sessions_json(JsonBuilder *json)
|
||||
{
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int first = 1;
|
||||
|
||||
json_append(json, "\"sessions\":[");
|
||||
if(g_storage.db != NULL &&
|
||||
sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,started_at,local_date,topic,activity,source,rounds_hash,deleted_at,imported_at "
|
||||
"FROM sessions WHERE user_id=?1 ORDER BY started_at,id",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
bind_text(stmt, 1, g_storage.user_id);
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const char *id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
long long started_at = sqlite3_column_int64(stmt, 1);
|
||||
long long imported_at = sqlite3_column_int64(stmt, 8);
|
||||
if(!first)
|
||||
json_append(json, ",");
|
||||
first = 0;
|
||||
json_append(json, "{");
|
||||
json_append_key_string(json, "id", id);
|
||||
json_append(json, ",\"started_at\":");
|
||||
json_append_epoch(json, started_at);
|
||||
json_appendf(json, ",\"local_date\":%d,\"topic\":\"%d\",\"activity\":%d,",
|
||||
sqlite3_column_int(stmt, 2),
|
||||
sqlite3_column_int(stmt, 3),
|
||||
sqlite3_column_int(stmt, 4));
|
||||
json_append_key_string(json, "source", (const char *)sqlite3_column_text(stmt, 5));
|
||||
json_append(json, ",");
|
||||
json_append_key_string(json, "rounds_hash", (const char *)sqlite3_column_text(stmt, 6));
|
||||
json_appendf(json, ",\"deleted_at\":%lld,\"updated_at\":",
|
||||
sqlite3_column_int64(stmt, 7));
|
||||
json_append_epoch(json, imported_at > started_at ? imported_at : started_at);
|
||||
json_append(json, ",");
|
||||
storage_append_session_rounds_json(json, id);
|
||||
json_append(json, "}");
|
||||
}
|
||||
}
|
||||
if(stmt != NULL)
|
||||
sqlite3_finalize(stmt);
|
||||
json_append(json, "]");
|
||||
}
|
||||
|
||||
char *
|
||||
inbe_storage_build_sync_payload_json(const char *user_id_hash, const char *public_key_hex)
|
||||
{
|
||||
JsonBuilder json = {0};
|
||||
|
||||
if(g_storage.db == NULL || user_id_hash == NULL || user_id_hash[0] == '\0')
|
||||
return NULL;
|
||||
json.ok = 1;
|
||||
json_append(&json, "{");
|
||||
json_append_key_string(&json, "user_id_hash", user_id_hash);
|
||||
if(public_key_hex != NULL && public_key_hex[0] != '\0') {
|
||||
json_append(&json, ",");
|
||||
json_append_key_string(&json, "public_key", public_key_hex);
|
||||
}
|
||||
json_append(&json, ",");
|
||||
storage_append_preferences_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_habits_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_habit_days_json(&json);
|
||||
json_append(&json, ",");
|
||||
storage_append_sessions_json(&json);
|
||||
json_append(&json, "}");
|
||||
|
||||
if(!json.ok || json.data == NULL) {
|
||||
free(json.data);
|
||||
return NULL;
|
||||
}
|
||||
return json.data;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_storage_free_sync_payload_json(char *payload)
|
||||
{
|
||||
free(payload);
|
||||
}
|
||||
|
||||
void
|
||||
inbe_storage_list_session_records(InbeStorageSessionRecordCallback callback, void *user)
|
||||
{
|
||||
@@ -940,6 +1302,9 @@ inbe_storage_has_any(void)
|
||||
return 1;
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
count = inbe_storage_habit_count();
|
||||
if(count > 0)
|
||||
return 1;
|
||||
if(sqlite3_prepare_v2(g_storage.db, "SELECT COUNT(*) FROM habit_days", -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
if(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
@@ -980,6 +1345,7 @@ inbe_storage_delete_all_sessions(void)
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
int count = inbe_storage_session_count();
|
||||
int habit_day_count = 0;
|
||||
int habit_count = inbe_storage_habit_count();
|
||||
|
||||
if(g_storage.db == NULL)
|
||||
return 0;
|
||||
@@ -989,7 +1355,7 @@ inbe_storage_delete_all_sessions(void)
|
||||
habit_day_count = sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if(count <= 0 && habit_day_count <= 0)
|
||||
if(count <= 0 && habit_day_count <= 0 && habit_count <= 0)
|
||||
return 0;
|
||||
|
||||
if(!exec_sql("BEGIN IMMEDIATE"))
|
||||
@@ -1006,13 +1372,17 @@ inbe_storage_delete_all_sessions(void)
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
if(!exec_sql("DELETE FROM habits")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
if(!exec_sql("COMMIT")) {
|
||||
exec_sql("ROLLBACK");
|
||||
return 0;
|
||||
}
|
||||
exec_sql("VACUUM");
|
||||
storage_schedule_persist();
|
||||
return count + habit_day_count;
|
||||
return count + habit_day_count + habit_count;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -1045,9 +1415,10 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
|
||||
if(habits == NULL || g_storage.db == NULL)
|
||||
return 0;
|
||||
inbe_habits_free(habits);
|
||||
memset(habits, 0, sizeof(*habits));
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity "
|
||||
"SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled "
|
||||
"FROM habits WHERE deleted_at=0 ORDER BY sort_order,id LIMIT 10",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
@@ -1060,6 +1431,9 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
(unsigned char)sqlite3_column_int(stmt, 4), 255};
|
||||
habit->sync_mode = sqlite3_column_int(stmt, 5);
|
||||
habit->sync_activity = sqlite3_column_int(stmt, 6);
|
||||
habit->counter_enabled = sqlite3_column_int(stmt, 7) != 0 ||
|
||||
(habit->sync_mode == INBE_HABIT_SYNC_ACTIVITIES &&
|
||||
habit->sync_activity != 0);
|
||||
index++;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
@@ -1067,14 +1441,22 @@ inbe_storage_habits_load(void *habits_ptr)
|
||||
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"SELECT local_date,completed FROM habit_days WHERE habit_id=?1 ORDER BY local_date LIMIT 366",
|
||||
"SELECT local_date,completed,count FROM habit_days WHERE habit_id=?1 ORDER BY local_date",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habits->items[i].id);
|
||||
while(habits->items[i].day_count < INBE_HABIT_MAX_DAYS && sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int d = habits->items[i].day_count++;
|
||||
if(!inbe_habit_reserve_days(&habits->items[i], habits->items[i].day_count)) {
|
||||
habits->items[i].day_count--;
|
||||
break;
|
||||
}
|
||||
habits->items[i].days[d].day_index = sqlite3_column_int(stmt, 0);
|
||||
habits->items[i].days[d].completed = sqlite3_column_int(stmt, 1) != 0;
|
||||
habits->items[i].days[d].count = sqlite3_column_int(stmt, 2);
|
||||
if(habits->items[i].days[d].count <= 0 &&
|
||||
habits->items[i].days[d].completed)
|
||||
habits->items[i].days[d].count = 1;
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
@@ -1102,8 +1484,8 @@ inbe_storage_habits_save(const void *habits_ptr)
|
||||
for(int i = 0; i < habits->count; i++) {
|
||||
const InbeHabit *habit = &habits->items[i];
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,0)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habit->id);
|
||||
@@ -1114,19 +1496,24 @@ inbe_storage_habits_save(const void *habits_ptr)
|
||||
sqlite3_bind_int(stmt, 6, habit->color.b);
|
||||
sqlite3_bind_int(stmt, 7, habit->sync_mode);
|
||||
sqlite3_bind_int(stmt, 8, habit->sync_activity);
|
||||
sqlite3_bind_int(stmt, 9, i);
|
||||
sqlite3_bind_int(stmt, 9, habit->counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(stmt, 10, i);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
for(int d = 0; d < habit->day_count; d++) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,updated_at) VALUES(?1,?2,?3,?4)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) VALUES(?1,?2,?3,?4,?5)",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(stmt, 1, habit->id);
|
||||
sqlite3_bind_int(stmt, 2, habit->days[d].day_index);
|
||||
sqlite3_bind_int(stmt, 3, habit->days[d].completed ? 1 : 0);
|
||||
sqlite3_bind_int64(stmt, 4, now_seconds());
|
||||
sqlite3_bind_int(stmt, 3, habit->days[d].count > 0 ||
|
||||
habit->days[d].completed ? 1 : 0);
|
||||
sqlite3_bind_int(stmt, 4, habit->days[d].count > 0
|
||||
? habit->days[d].count
|
||||
: (habit->days[d].completed ? 1 : 0));
|
||||
sqlite3_bind_int64(stmt, 5, now_seconds());
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
@@ -1448,6 +1835,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
sqlite3_stmt *write_stmt = NULL;
|
||||
int ok = 0;
|
||||
int has_multiple_entries;
|
||||
const char *track_sql;
|
||||
long long imported_at = now_seconds();
|
||||
|
||||
if(src == NULL || g_storage.db == NULL)
|
||||
@@ -1456,9 +1845,18 @@ import_tickmate_db(sqlite3 *src)
|
||||
!source_table_has_column(src, "ticks", "_track_id"))
|
||||
return 0;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT _id,name,color,\"order\" FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id",
|
||||
-1, &stmt, NULL) != SQLITE_OK)
|
||||
has_multiple_entries = source_table_has_column(src, "tracks", "multiple_entries_per_day");
|
||||
track_sql = has_multiple_entries
|
||||
? "SELECT _id,name,color,\"order\",multiple_entries_per_day,"
|
||||
"EXISTS(SELECT 1 FROM ticks WHERE ticks._track_id=tracks._id "
|
||||
"GROUP BY year,month,day HAVING COUNT(*)>1 LIMIT 1) "
|
||||
"FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id"
|
||||
: "SELECT _id,name,color,\"order\",0,"
|
||||
"EXISTS(SELECT 1 FROM ticks WHERE ticks._track_id=tracks._id "
|
||||
"GROUP BY year,month,day HAVING COUNT(*)>1 LIMIT 1) "
|
||||
"FROM tracks WHERE enabled!=0 ORDER BY \"order\",_id";
|
||||
|
||||
if(sqlite3_prepare_v2(src, track_sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
return 0;
|
||||
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
@@ -1468,6 +1866,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
const char *name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
int track_id = sqlite3_column_int(stmt, 0);
|
||||
int sort_order = sqlite3_column_int(stmt, 3);
|
||||
int counter_enabled = sqlite3_column_int(stmt, 4) != 0 ||
|
||||
sqlite3_column_int(stmt, 5) != 0;
|
||||
Color color = tickmate_color_from_int(sqlite3_column_int(stmt, 2), track_id);
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
@@ -1477,8 +1877,9 @@ import_tickmate_db(sqlite3 *src)
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,"
|
||||
"CASE WHEN ?9!=0 THEN 1 ELSE COALESCE((SELECT counter_enabled FROM habits WHERE id=?1),0) END,?10,0)",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, local_habit_id);
|
||||
@@ -1489,7 +1890,8 @@ import_tickmate_db(sqlite3 *src)
|
||||
sqlite3_bind_int(write_stmt, 6, color.b);
|
||||
sqlite3_bind_int(write_stmt, 7, INBE_HABIT_SYNC_NONE);
|
||||
sqlite3_bind_int(write_stmt, 8, 0);
|
||||
sqlite3_bind_int(write_stmt, 9, sort_order);
|
||||
sqlite3_bind_int(write_stmt, 9, counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(write_stmt, 10, sort_order);
|
||||
if(sqlite3_step(write_stmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(write_stmt);
|
||||
@@ -1499,9 +1901,23 @@ import_tickmate_db(sqlite3 *src)
|
||||
stmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT ticks._track_id,tracks.name,ticks.year,ticks.month,ticks.day "
|
||||
"FROM ticks JOIN tracks ON tracks._id=ticks._track_id",
|
||||
"SELECT ticks._track_id,tracks.name,ticks.year,ticks.month,ticks.day,COUNT(*) "
|
||||
"FROM ticks JOIN tracks ON tracks._id=ticks._track_id "
|
||||
"WHERE tracks.enabled!=0 "
|
||||
"GROUP BY ticks._track_id,ticks.year,ticks.month,ticks.day",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) "
|
||||
"VALUES(?1,?2,1,?3,?4) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"count=CASE WHEN habit_days.count>excluded.count THEN habit_days.count ELSE excluded.count END,"
|
||||
"completed=CASE WHEN habit_days.count>0 OR excluded.count>0 OR habit_days.completed!=0 THEN 1 ELSE 0 END,"
|
||||
"updated_at=CASE WHEN excluded.count>habit_days.count THEN excluded.updated_at ELSE habit_days.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK) {
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
goto finish;
|
||||
}
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
char import_habit_id[64];
|
||||
char local_habit_id[INBE_STORAGE_ID_SIZE];
|
||||
@@ -1510,31 +1926,30 @@ import_tickmate_db(sqlite3 *src)
|
||||
int year = sqlite3_column_int(stmt, 2);
|
||||
int month = sqlite3_column_int(stmt, 3);
|
||||
int day = sqlite3_column_int(stmt, 4);
|
||||
int count = sqlite3_column_int(stmt, 5);
|
||||
int local_date;
|
||||
|
||||
if(name == NULL || name[0] == '\0')
|
||||
continue;
|
||||
if(year <= 0 || month <= 0 || month > 12 || day <= 0 || day > 31)
|
||||
/* Tickmate stores Android Calendar.MONTH values: January is 0. */
|
||||
if(year <= 0 || month < 0 || month > 11 || day <= 0 || day > 31)
|
||||
continue;
|
||||
local_date = year * 10000 + month * 100 + day;
|
||||
local_date = year * 10000 + (month + 1) * 100 + day;
|
||||
snprintf(import_habit_id, sizeof(import_habit_id), "tickmate-%d", track_id);
|
||||
if(!resolve_import_habit_id(import_habit_id, name, local_habit_id,
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,1,?3)",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
sqlite3_reset(write_stmt);
|
||||
sqlite3_clear_bindings(write_stmt);
|
||||
bind_text(write_stmt, 1, local_habit_id);
|
||||
sqlite3_bind_int(write_stmt, 2, local_date);
|
||||
sqlite3_bind_int64(write_stmt, 3, imported_at);
|
||||
sqlite3_bind_int(write_stmt, 3, count > 0 ? count : 1);
|
||||
sqlite3_bind_int64(write_stmt, 4, imported_at);
|
||||
if(sqlite3_step(write_stmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(write_stmt);
|
||||
write_stmt = NULL;
|
||||
}
|
||||
}
|
||||
finish:
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_finalize(write_stmt);
|
||||
exec_sql("COMMIT");
|
||||
@@ -1563,7 +1978,9 @@ import_settings_from_source(sqlite3 *src)
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT INTO settings(user_id,key,value,updated_at) VALUES(?1,?2,?3,?4) "
|
||||
"ON CONFLICT(user_id,key) DO UPDATE SET value=excluded.value,updated_at=excluded.updated_at",
|
||||
"ON CONFLICT(user_id,key) DO UPDATE SET "
|
||||
"value=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.value ELSE settings.value END,"
|
||||
"updated_at=CASE WHEN excluded.value!='' OR settings.value='' THEN excluded.updated_at ELSE settings.updated_at END",
|
||||
-1, &write_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(write_stmt, 1, g_storage.user_id);
|
||||
@@ -1672,10 +2089,16 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
|
||||
if(source_table_exists(src, "habits")) {
|
||||
int has_sync_activity = source_table_has_column(src, "habits", "sync_activity");
|
||||
int has_counter_enabled = source_table_has_column(src, "habits", "counter_enabled");
|
||||
int has_day_count = source_table_has_column(src, "habit_days", "count");
|
||||
const char *habit_sql =
|
||||
has_sync_activity
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: "SELECT id,name,color_r,color_g,color_b,sync_mode,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
|
||||
has_sync_activity && has_counter_enabled
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: has_sync_activity
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,sync_activity,0,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: has_counter_enabled
|
||||
? "SELECT id,name,color_r,color_g,color_b,sync_mode,0,counter_enabled,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id"
|
||||
: "SELECT id,name,color_r,color_g,color_b,sync_mode,0,0,sort_order FROM habits WHERE deleted_at=0 ORDER BY sort_order,id";
|
||||
if(sqlite3_prepare_v2(src, habit_sql, -1, &stmt, NULL) != SQLITE_OK)
|
||||
goto after_habits;
|
||||
exec_sql("BEGIN IMMEDIATE");
|
||||
@@ -1683,8 +2106,11 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
const char *import_habit_id = (const char *)sqlite3_column_text(stmt, 0);
|
||||
const char *name = (const char *)sqlite3_column_text(stmt, 1);
|
||||
char local_habit_id[INBE_STORAGE_ID_SIZE];
|
||||
int sync_activity = has_sync_activity ? sqlite3_column_int(stmt, 6) : 0;
|
||||
int sort_order = has_sync_activity ? sqlite3_column_int(stmt, 7) : sqlite3_column_int(stmt, 6);
|
||||
int sync_activity = sqlite3_column_int(stmt, 6);
|
||||
int counter_enabled = sqlite3_column_int(stmt, 7) != 0;
|
||||
int sort_order = sqlite3_column_int(stmt, 8);
|
||||
if(sync_activity != 0)
|
||||
counter_enabled = 1;
|
||||
|
||||
if(import_habit_id == NULL || import_habit_id[0] == '\0' ||
|
||||
name == NULL || name[0] == '\0')
|
||||
@@ -1693,8 +2119,9 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
sizeof(local_habit_id)))
|
||||
continue;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,?9,0)",
|
||||
"INSERT OR REPLACE INTO habits(id,user_id,name,color_r,color_g,color_b,sync_mode,sync_activity,counter_enabled,sort_order,deleted_at) "
|
||||
"VALUES(?1,?2,COALESCE((SELECT name FROM habits WHERE id=?1),?3),?4,?5,?6,?7,?8,"
|
||||
"CASE WHEN ?9!=0 THEN 1 ELSE COALESCE((SELECT counter_enabled FROM habits WHERE id=?1),0) END,?10,0)",
|
||||
-1, &hstmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(hstmt, 1, local_habit_id);
|
||||
@@ -1705,27 +2132,35 @@ import_sqlite_db_file(const char *db_path, InbeStorageImportMode mode)
|
||||
sqlite3_bind_int(hstmt, 6, sqlite3_column_int(stmt, 4));
|
||||
sqlite3_bind_int(hstmt, 7, sqlite3_column_int(stmt, 5));
|
||||
sqlite3_bind_int(hstmt, 8, sync_activity);
|
||||
sqlite3_bind_int(hstmt, 9, sort_order);
|
||||
sqlite3_bind_int(hstmt, 9, counter_enabled ? 1 : 0);
|
||||
sqlite3_bind_int(hstmt, 10, sort_order);
|
||||
if(sqlite3_step(hstmt) == SQLITE_DONE)
|
||||
ok = 1;
|
||||
sqlite3_finalize(hstmt);
|
||||
hstmt = NULL;
|
||||
|
||||
if(sqlite3_prepare_v2(src,
|
||||
"SELECT local_date,completed FROM habit_days WHERE habit_id=?1",
|
||||
has_day_count
|
||||
? "SELECT local_date,completed,count FROM habit_days WHERE habit_id=?1"
|
||||
: "SELECT local_date,completed,CASE WHEN completed!=0 THEN 1 ELSE 0 END FROM habit_days WHERE habit_id=?1",
|
||||
-1, &hstmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(hstmt, 1, import_habit_id, -1, SQLITE_TRANSIENT);
|
||||
while(sqlite3_step(hstmt) == SQLITE_ROW) {
|
||||
sqlite3_stmt *day_stmt = NULL;
|
||||
if(sqlite3_prepare_v2(g_storage.db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4)",
|
||||
"INSERT INTO habit_days(habit_id,local_date,completed,count,updated_at) "
|
||||
"VALUES(?1,?2,?3,?4,?5) "
|
||||
"ON CONFLICT(habit_id,local_date) DO UPDATE SET "
|
||||
"count=CASE WHEN habit_days.count>excluded.count THEN habit_days.count ELSE excluded.count END,"
|
||||
"completed=CASE WHEN habit_days.count>0 OR excluded.count>0 OR habit_days.completed!=0 OR excluded.completed!=0 THEN 1 ELSE 0 END,"
|
||||
"updated_at=CASE WHEN excluded.count>habit_days.count THEN excluded.updated_at ELSE habit_days.updated_at END",
|
||||
-1, &day_stmt, NULL) != SQLITE_OK)
|
||||
continue;
|
||||
bind_text(day_stmt, 1, local_habit_id);
|
||||
sqlite3_bind_int(day_stmt, 2, sqlite3_column_int(hstmt, 0));
|
||||
sqlite3_bind_int(day_stmt, 3, sqlite3_column_int(hstmt, 1) != 0);
|
||||
sqlite3_bind_int64(day_stmt, 4, now_seconds());
|
||||
sqlite3_bind_int(day_stmt, 4, sqlite3_column_int(hstmt, 2));
|
||||
sqlite3_bind_int64(day_stmt, 5, now_seconds());
|
||||
sqlite3_step(day_stmt);
|
||||
sqlite3_finalize(day_stmt);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ int inbe_storage_session_count(void);
|
||||
int inbe_storage_habit_count(void);
|
||||
long long inbe_storage_total_size(void);
|
||||
long long inbe_storage_delete_all_sessions(void);
|
||||
char *inbe_storage_build_sync_payload_json(const char *user_id_hash,
|
||||
const char *public_key_hex);
|
||||
void inbe_storage_free_sync_payload_json(char *payload);
|
||||
|
||||
int inbe_storage_habits_empty(void);
|
||||
int inbe_storage_habits_load(void *habits);
|
||||
|
||||
@@ -0,0 +1,381 @@
|
||||
#include "sync_account.h"
|
||||
|
||||
#include "data.h"
|
||||
#include "storage.h"
|
||||
#include "raylib.h"
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#include "android_share.h"
|
||||
#endif
|
||||
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
#include <oqs/oqs.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define SYNC_PUBLIC_ID_KEY "sync_public_id"
|
||||
#define SYNC_PUBLIC_KEY_KEY "sync_public_key"
|
||||
#define SYNC_PRIVATE_KEY_KEY "sync_private_key"
|
||||
|
||||
typedef struct Sha256Ctx {
|
||||
uint32_t state[8];
|
||||
uint64_t bit_len;
|
||||
uint8_t data[64];
|
||||
size_t data_len;
|
||||
} Sha256Ctx;
|
||||
|
||||
static const uint32_t sha256_k[64] = {
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U,
|
||||
0x923f82a4U, 0xab1c5ed5U, 0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U,
|
||||
0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U, 0xe49b69c1U, 0xefbe4786U,
|
||||
0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U,
|
||||
0x06ca6351U, 0x14292967U, 0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U,
|
||||
0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U, 0xa2bfe8a1U, 0xa81a664bU,
|
||||
0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU,
|
||||
0x5b9cca4fU, 0x682e6ff3U, 0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U,
|
||||
0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
};
|
||||
|
||||
static uint32_t
|
||||
rotr32(uint32_t value, uint32_t bits)
|
||||
{
|
||||
return (value >> bits) | (value << (32U - bits));
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_transform(Sha256Ctx *ctx, const uint8_t data[64])
|
||||
{
|
||||
uint32_t m[64];
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
|
||||
for(int i = 0; i < 16; i++) {
|
||||
m[i] = ((uint32_t)data[i * 4] << 24) |
|
||||
((uint32_t)data[i * 4 + 1] << 16) |
|
||||
((uint32_t)data[i * 4 + 2] << 8) |
|
||||
(uint32_t)data[i * 4 + 3];
|
||||
}
|
||||
for(int i = 16; i < 64; i++) {
|
||||
uint32_t s0 = rotr32(m[i - 15], 7) ^ rotr32(m[i - 15], 18) ^ (m[i - 15] >> 3);
|
||||
uint32_t s1 = rotr32(m[i - 2], 17) ^ rotr32(m[i - 2], 19) ^ (m[i - 2] >> 10);
|
||||
m[i] = m[i - 16] + s0 + m[i - 7] + s1;
|
||||
}
|
||||
|
||||
a = ctx->state[0];
|
||||
b = ctx->state[1];
|
||||
c = ctx->state[2];
|
||||
d = ctx->state[3];
|
||||
e = ctx->state[4];
|
||||
f = ctx->state[5];
|
||||
g = ctx->state[6];
|
||||
h = ctx->state[7];
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
uint32_t s1 = rotr32(e, 6) ^ rotr32(e, 11) ^ rotr32(e, 25);
|
||||
uint32_t ch = (e & f) ^ ((~e) & g);
|
||||
uint32_t temp1 = h + s1 + ch + sha256_k[i] + m[i];
|
||||
uint32_t s0 = rotr32(a, 2) ^ rotr32(a, 13) ^ rotr32(a, 22);
|
||||
uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
uint32_t temp2 = s0 + maj;
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + temp1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = temp1 + temp2;
|
||||
}
|
||||
|
||||
ctx->state[0] += a;
|
||||
ctx->state[1] += b;
|
||||
ctx->state[2] += c;
|
||||
ctx->state[3] += d;
|
||||
ctx->state[4] += e;
|
||||
ctx->state[5] += f;
|
||||
ctx->state[6] += g;
|
||||
ctx->state[7] += h;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_init(Sha256Ctx *ctx)
|
||||
{
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->state[0] = 0x6a09e667U;
|
||||
ctx->state[1] = 0xbb67ae85U;
|
||||
ctx->state[2] = 0x3c6ef372U;
|
||||
ctx->state[3] = 0xa54ff53aU;
|
||||
ctx->state[4] = 0x510e527fU;
|
||||
ctx->state[5] = 0x9b05688cU;
|
||||
ctx->state[6] = 0x1f83d9abU;
|
||||
ctx->state[7] = 0x5be0cd19U;
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_update(Sha256Ctx *ctx, const uint8_t *data, size_t len)
|
||||
{
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
ctx->data[ctx->data_len++] = data[i];
|
||||
if(ctx->data_len == 64) {
|
||||
sha256_transform(ctx, ctx->data);
|
||||
ctx->bit_len += 512;
|
||||
ctx->data_len = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
sha256_final(Sha256Ctx *ctx, uint8_t hash[32])
|
||||
{
|
||||
size_t i = ctx->data_len;
|
||||
|
||||
ctx->data[i++] = 0x80;
|
||||
if(i > 56) {
|
||||
while(i < 64)
|
||||
ctx->data[i++] = 0;
|
||||
sha256_transform(ctx, ctx->data);
|
||||
i = 0;
|
||||
}
|
||||
while(i < 56)
|
||||
ctx->data[i++] = 0;
|
||||
|
||||
ctx->bit_len += ctx->data_len * 8;
|
||||
for(int j = 0; j < 8; j++)
|
||||
ctx->data[63 - j] = (uint8_t)(ctx->bit_len >> (j * 8));
|
||||
sha256_transform(ctx, ctx->data);
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
for(int j = 0; j < 8; j++)
|
||||
hash[j * 4 + i] = (uint8_t)(ctx->state[j] >> (24 - i * 8));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
bytes_to_hex(const uint8_t *bytes, size_t len, char *out, size_t out_size)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
size_t needed = len * 2 + 1;
|
||||
|
||||
if(out == NULL || out_size < needed)
|
||||
return;
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
out[i * 2] = hex[bytes[i] >> 4];
|
||||
out[i * 2 + 1] = hex[bytes[i] & 0x0f];
|
||||
}
|
||||
out[len * 2] = '\0';
|
||||
}
|
||||
|
||||
static int
|
||||
hex_to_bytes(const char *hex, uint8_t *out, size_t out_len)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(hex == NULL || out == NULL)
|
||||
return 0;
|
||||
len = strlen(hex);
|
||||
if(len != out_len * 2)
|
||||
return 0;
|
||||
for(size_t i = 0; i < out_len; i++) {
|
||||
unsigned int value;
|
||||
if(sscanf(hex + i * 2, "%2x", &value) != 1)
|
||||
return 0;
|
||||
out[i] = (uint8_t)value;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
inbe_sync_sha256_hex(const uint8_t *data, size_t len, char out_hex[65])
|
||||
{
|
||||
uint8_t digest[32];
|
||||
Sha256Ctx sha;
|
||||
|
||||
if(out_hex == NULL)
|
||||
return;
|
||||
out_hex[0] = '\0';
|
||||
if(data == NULL && len > 0)
|
||||
return;
|
||||
sha256_init(&sha);
|
||||
sha256_update(&sha, data, len);
|
||||
sha256_final(&sha, digest);
|
||||
bytes_to_hex(digest, sizeof(digest), out_hex, 65);
|
||||
}
|
||||
|
||||
static int
|
||||
account_has_values(const InbeSyncAccount *account)
|
||||
{
|
||||
return account != NULL &&
|
||||
account->public_id[0] != '\0' &&
|
||||
account->public_key_hex[0] != '\0' &&
|
||||
account->private_key_hex[0] != '\0';
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_available(void)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
return 1;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_load(InbeSyncAccount *account)
|
||||
{
|
||||
const char *public_id;
|
||||
const char *public_key;
|
||||
const char *private_key;
|
||||
|
||||
data_init();
|
||||
if(account == NULL)
|
||||
return 0;
|
||||
memset(account, 0, sizeof(*account));
|
||||
|
||||
public_id = inbe_storage_get_setting_text(SYNC_PUBLIC_ID_KEY);
|
||||
if(public_id != NULL)
|
||||
snprintf(account->public_id, sizeof(account->public_id), "%s", public_id);
|
||||
public_key = inbe_storage_get_setting_text(SYNC_PUBLIC_KEY_KEY);
|
||||
if(public_key != NULL)
|
||||
snprintf(account->public_key_hex, sizeof(account->public_key_hex), "%s", public_key);
|
||||
private_key = inbe_storage_get_setting_text(SYNC_PRIVATE_KEY_KEY);
|
||||
if(private_key != NULL)
|
||||
snprintf(account->private_key_hex, sizeof(account->private_key_hex), "%s", private_key);
|
||||
return account_has_values(account);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_create(InbeSyncAccount *account)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
OQS_SIG *sig;
|
||||
uint8_t public_key[1312];
|
||||
uint8_t private_key[2560];
|
||||
uint8_t digest[32];
|
||||
Sha256Ctx sha;
|
||||
InbeSyncAccount generated;
|
||||
|
||||
data_init();
|
||||
if(account == NULL)
|
||||
return 0;
|
||||
memset(&generated, 0, sizeof(generated));
|
||||
|
||||
sig = OQS_SIG_new(OQS_SIG_alg_ml_dsa_44);
|
||||
if(sig == NULL ||
|
||||
sig->length_public_key != sizeof(public_key) ||
|
||||
sig->length_secret_key != sizeof(private_key)) {
|
||||
if(sig != NULL)
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
if(OQS_SIG_keypair(sig, public_key, private_key) != OQS_SUCCESS) {
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
OQS_SIG_free(sig);
|
||||
|
||||
sha256_init(&sha);
|
||||
sha256_update(&sha, public_key, sizeof(public_key));
|
||||
sha256_final(&sha, digest);
|
||||
|
||||
bytes_to_hex(digest, sizeof(digest), generated.public_id, sizeof(generated.public_id));
|
||||
bytes_to_hex(public_key, sizeof(public_key), generated.public_key_hex,
|
||||
sizeof(generated.public_key_hex));
|
||||
bytes_to_hex(private_key, sizeof(private_key), generated.private_key_hex,
|
||||
sizeof(generated.private_key_hex));
|
||||
|
||||
inbe_storage_settings_begin_write();
|
||||
inbe_storage_set_setting_text(SYNC_PUBLIC_ID_KEY, generated.public_id);
|
||||
inbe_storage_set_setting_text(SYNC_PUBLIC_KEY_KEY, generated.public_key_hex);
|
||||
inbe_storage_set_setting_text(SYNC_PRIVATE_KEY_KEY, generated.private_key_hex);
|
||||
inbe_storage_settings_end_write();
|
||||
|
||||
*account = generated;
|
||||
return 1;
|
||||
#else
|
||||
(void)account;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_export_private_key(const InbeSyncAccount *account, const char *filename)
|
||||
{
|
||||
char body[5400];
|
||||
int len;
|
||||
|
||||
if(!account_has_values(account) || filename == NULL || filename[0] == '\0')
|
||||
return 0;
|
||||
|
||||
len = snprintf(body, sizeof(body),
|
||||
"inbe-sync-key-v1\nalgorithm=ML-DSA-44\npublic_id=%s\nprivate_key=%s\n",
|
||||
account->public_id, account->private_key_hex);
|
||||
if(len <= 0 || (size_t)len >= sizeof(body))
|
||||
return 0;
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
return android_share_bytes((const unsigned char *)body, (size_t)len, filename,
|
||||
"application/octet-stream");
|
||||
#else
|
||||
if(strchr(filename, '/') != NULL || strchr(filename, '\\') != NULL)
|
||||
return SaveFileData(filename, body, len);
|
||||
{
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/%s", data_root(), filename);
|
||||
return SaveFileData(path, body, len);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_account_sign_hex(const uint8_t *message, size_t message_len,
|
||||
char *out_signature_hex, size_t out_size)
|
||||
{
|
||||
#if defined(INBE_HAS_LIBOQS)
|
||||
InbeSyncAccount account;
|
||||
OQS_SIG *sig;
|
||||
uint8_t private_key[2560];
|
||||
uint8_t signature[2420];
|
||||
size_t signature_len = 0;
|
||||
|
||||
if(out_signature_hex == NULL || out_size < sizeof(signature) * 2 + 1 ||
|
||||
(message == NULL && message_len > 0))
|
||||
return 0;
|
||||
out_signature_hex[0] = '\0';
|
||||
if(!inbe_sync_account_load(&account))
|
||||
return 0;
|
||||
if(!hex_to_bytes(account.private_key_hex, private_key, sizeof(private_key)))
|
||||
return 0;
|
||||
|
||||
sig = OQS_SIG_new(OQS_SIG_alg_ml_dsa_44);
|
||||
if(sig == NULL ||
|
||||
sig->length_secret_key != sizeof(private_key) ||
|
||||
sig->length_signature != sizeof(signature)) {
|
||||
if(sig != NULL)
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(OQS_SIG_sign(sig, signature, &signature_len, message, message_len,
|
||||
private_key) != OQS_SUCCESS ||
|
||||
signature_len != sizeof(signature)) {
|
||||
OQS_SIG_free(sig);
|
||||
return 0;
|
||||
}
|
||||
OQS_SIG_free(sig);
|
||||
|
||||
bytes_to_hex(signature, sizeof(signature), out_signature_hex, out_size);
|
||||
return out_signature_hex[0] != '\0';
|
||||
#else
|
||||
(void)message;
|
||||
(void)message_len;
|
||||
(void)out_signature_hex;
|
||||
(void)out_size;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef INBE_SYNC_ACCOUNT_H
|
||||
#define INBE_SYNC_ACCOUNT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
INBE_SYNC_PUBLIC_ID_HEX_SIZE = 65,
|
||||
INBE_SYNC_PUBLIC_KEY_HEX_SIZE = 2625,
|
||||
INBE_SYNC_PRIVATE_KEY_HEX_SIZE = 5121
|
||||
};
|
||||
|
||||
typedef struct InbeSyncAccount {
|
||||
char public_id[INBE_SYNC_PUBLIC_ID_HEX_SIZE];
|
||||
char public_key_hex[INBE_SYNC_PUBLIC_KEY_HEX_SIZE];
|
||||
char private_key_hex[INBE_SYNC_PRIVATE_KEY_HEX_SIZE];
|
||||
} InbeSyncAccount;
|
||||
|
||||
int inbe_sync_account_available(void);
|
||||
int inbe_sync_account_load(InbeSyncAccount *account);
|
||||
int inbe_sync_account_create(InbeSyncAccount *account);
|
||||
int inbe_sync_account_export_private_key(const InbeSyncAccount *account, const char *filename);
|
||||
void inbe_sync_sha256_hex(const uint8_t *data, size_t len, char out_hex[65]);
|
||||
int inbe_sync_account_sign_hex(const uint8_t *message, size_t message_len,
|
||||
char *out_signature_hex, size_t out_size);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,470 @@
|
||||
#include "sync_client.h"
|
||||
|
||||
#include "storage.h"
|
||||
#include "sync_account.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(PLATFORM_ANDROID) || defined(__ANDROID__) || defined(ANDROID)
|
||||
#define INBE_SYNC_CLIENT_HAS_ANDROID 1
|
||||
#include <android_native_app_glue.h>
|
||||
#include <jni.h>
|
||||
extern struct android_app *GetAndroidApp(void);
|
||||
#elif defined(FLINT_HAS_LIBCURL) && !defined(__EMSCRIPTEN__)
|
||||
#define INBE_SYNC_CLIENT_HAS_CURL 1
|
||||
#include <curl/curl.h>
|
||||
#endif
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_CURL) || defined(INBE_SYNC_CLIENT_HAS_ANDROID)
|
||||
#define INBE_SYNC_CLIENT_HAS_HTTP 1
|
||||
#endif
|
||||
|
||||
#define INBE_SYNC_PATH "/api/v1/sync"
|
||||
#define INBE_CHALLENGE_PATH "/api/v1/sync/challenge"
|
||||
|
||||
typedef struct SyncBuffer {
|
||||
char *data;
|
||||
size_t len;
|
||||
size_t cap;
|
||||
} SyncBuffer;
|
||||
|
||||
static int
|
||||
sync_has_prefix(const char *text, const char *prefix)
|
||||
{
|
||||
return text != NULL && prefix != NULL &&
|
||||
strncmp(text, prefix, strlen(prefix)) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_url_host_boundary(char ch)
|
||||
{
|
||||
return ch == '\0' || ch == ':' || ch == '/' || ch == '?' || ch == '#';
|
||||
}
|
||||
|
||||
static int
|
||||
sync_loopback_authority_valid(const char *authority)
|
||||
{
|
||||
static const char *const hosts[] = {
|
||||
"localhost",
|
||||
"127.0.0.1",
|
||||
"10.0.2.2"
|
||||
};
|
||||
|
||||
if(authority == NULL || authority[0] == '\0')
|
||||
return 0;
|
||||
for(size_t i = 0; i < sizeof(hosts) / sizeof(hosts[0]); i++) {
|
||||
size_t len = strlen(hosts[i]);
|
||||
if(strncmp(authority, hosts[i], len) == 0 &&
|
||||
sync_url_host_boundary(authority[len]))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_client_url_valid(const char *url)
|
||||
{
|
||||
if(url == NULL || url[0] == '\0')
|
||||
return 0;
|
||||
if(sync_has_prefix(url, "https://"))
|
||||
return url[8] != '\0';
|
||||
if(sync_has_prefix(url, "http://"))
|
||||
return sync_loopback_authority_valid(url + 7);
|
||||
return sync_loopback_authority_valid(url);
|
||||
}
|
||||
|
||||
int
|
||||
inbe_sync_client_normalize_url(const char *input, char *out, size_t out_size)
|
||||
{
|
||||
int len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
if(!inbe_sync_client_url_valid(input))
|
||||
return 0;
|
||||
if(sync_has_prefix(input, "https://") || sync_has_prefix(input, "http://"))
|
||||
len = snprintf(out, out_size, "%s", input);
|
||||
else
|
||||
len = snprintf(out, out_size, "http://%s", input);
|
||||
return len > 0 && (size_t)len < out_size;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_buffer_append(SyncBuffer *buffer, const void *data, size_t bytes)
|
||||
{
|
||||
char *next;
|
||||
size_t next_cap;
|
||||
|
||||
if(buffer == NULL || data == NULL || bytes == 0)
|
||||
return 1;
|
||||
if(buffer->cap == 0 || bytes >= buffer->cap - buffer->len) {
|
||||
next_cap = buffer->cap > 0 ? buffer->cap : 1024;
|
||||
while(bytes >= next_cap - buffer->len)
|
||||
next_cap *= 2;
|
||||
next = (char *)realloc(buffer->data, next_cap);
|
||||
if(next == NULL)
|
||||
return 0;
|
||||
buffer->data = next;
|
||||
buffer->cap = next_cap;
|
||||
}
|
||||
memcpy(buffer->data + buffer->len, data, bytes);
|
||||
buffer->len += bytes;
|
||||
buffer->data[buffer->len] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_TESTS)
|
||||
int
|
||||
inbe_sync_client_test_response_buffer(const char *first, const char *second,
|
||||
char *out, size_t out_size)
|
||||
{
|
||||
SyncBuffer buffer = {0};
|
||||
int ok;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
ok = sync_buffer_append(&buffer, first, first != NULL ? strlen(first) : 0) &&
|
||||
sync_buffer_append(&buffer, second, second != NULL ? strlen(second) : 0);
|
||||
if(ok && buffer.data != NULL)
|
||||
snprintf(out, out_size, "%s", buffer.data);
|
||||
free(buffer.data);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
sync_join_url(char *out, size_t out_size, const char *base_url, const char *path)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(out == NULL || out_size == 0)
|
||||
return;
|
||||
out[0] = '\0';
|
||||
if(base_url == NULL || path == NULL)
|
||||
return;
|
||||
len = strlen(base_url);
|
||||
while(len > 0 && base_url[len - 1] == '/')
|
||||
len--;
|
||||
snprintf(out, out_size, "%.*s%s", (int)len, base_url, path);
|
||||
}
|
||||
|
||||
static int
|
||||
sync_build_message(const char *method, const char *path, const char *nonce_hex,
|
||||
const char *body, char *out, size_t out_size)
|
||||
{
|
||||
char body_hash[65];
|
||||
int len;
|
||||
|
||||
if(method == NULL || path == NULL || nonce_hex == NULL || body == NULL ||
|
||||
out == NULL || out_size == 0)
|
||||
return 0;
|
||||
inbe_sync_sha256_hex((const uint8_t *)body, strlen(body), body_hash);
|
||||
if(body_hash[0] == '\0')
|
||||
return 0;
|
||||
len = snprintf(out, out_size, "inbe-sync-v1\n%s\n%s\n%s\n%s\n",
|
||||
method, path, body_hash, nonce_hex);
|
||||
return len > 0 && (size_t)len < out_size;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_find_json_string(const char *json, const char *key, char *out, size_t out_size)
|
||||
{
|
||||
char pattern[64];
|
||||
const char *p;
|
||||
char *w;
|
||||
size_t remaining;
|
||||
|
||||
if(json == NULL || key == NULL || out == NULL || out_size == 0)
|
||||
return 0;
|
||||
out[0] = '\0';
|
||||
snprintf(pattern, sizeof(pattern), "\"%s\"", key);
|
||||
p = strstr(json, pattern);
|
||||
if(p == NULL)
|
||||
return 0;
|
||||
p += strlen(pattern);
|
||||
while(*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||
p++;
|
||||
if(*p++ != ':')
|
||||
return 0;
|
||||
while(*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
|
||||
p++;
|
||||
if(*p++ != '"')
|
||||
return 0;
|
||||
w = out;
|
||||
remaining = out_size - 1;
|
||||
while(*p != '\0' && *p != '"' && remaining > 0) {
|
||||
if(*p == '\\')
|
||||
return 0;
|
||||
*w++ = *p++;
|
||||
remaining--;
|
||||
}
|
||||
*w = '\0';
|
||||
return *p == '"' && out[0] != '\0';
|
||||
}
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_CURL)
|
||||
static size_t
|
||||
sync_write_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
{
|
||||
SyncBuffer *buffer = (SyncBuffer *)userdata;
|
||||
size_t bytes = size * nmemb;
|
||||
|
||||
if(buffer == NULL || bytes == 0)
|
||||
return bytes;
|
||||
return sync_buffer_append(buffer, ptr, bytes) ? bytes : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_http_request(const char *method, const char *url, const char *body,
|
||||
const char *const *headers, int header_count,
|
||||
SyncBuffer *response, long *status)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
struct curl_slist *curl_headers = NULL;
|
||||
|
||||
if(status != NULL)
|
||||
*status = 0;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if(curl == NULL)
|
||||
return 0;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "inbe-sync/1");
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, sync_write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, response);
|
||||
for(int i = 0; i < header_count; i++) {
|
||||
if(headers[i] != NULL)
|
||||
curl_headers = curl_slist_append(curl_headers, headers[i]);
|
||||
}
|
||||
if(curl_headers != NULL)
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_headers);
|
||||
if(strcmp(method, "POST") == 0) {
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body != NULL ? body : "");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)(body != NULL ? strlen(body) : 0));
|
||||
} else if(strcmp(method, "DELETE") == 0) {
|
||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body != NULL ? body : "");
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)(body != NULL ? strlen(body) : 0));
|
||||
}
|
||||
res = curl_easy_perform(curl);
|
||||
if(status != NULL)
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, status);
|
||||
curl_slist_free_all(curl_headers);
|
||||
curl_easy_cleanup(curl);
|
||||
return res == CURLE_OK;
|
||||
}
|
||||
#elif defined(INBE_SYNC_CLIENT_HAS_ANDROID)
|
||||
static int
|
||||
sync_buffer_set(SyncBuffer *response, const char *text)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
if(response == NULL)
|
||||
return 0;
|
||||
len = text != NULL ? strlen(text) : 0;
|
||||
response->data = (char *)malloc(len + 1);
|
||||
if(response->data == NULL)
|
||||
return 0;
|
||||
if(len > 0)
|
||||
memcpy(response->data, text, len);
|
||||
response->data[len] = '\0';
|
||||
response->len = len;
|
||||
response->cap = len + 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
sync_http_request(const char *method, const char *url, const char *body,
|
||||
const char *const *headers, int header_count,
|
||||
SyncBuffer *response, long *status)
|
||||
{
|
||||
struct android_app *app = GetAndroidApp();
|
||||
JavaVM *jvm;
|
||||
JNIEnv *env = NULL;
|
||||
jobject activity;
|
||||
jclass activity_class;
|
||||
jmethodID method_id;
|
||||
jstring jmethod = NULL;
|
||||
jstring jurl = NULL;
|
||||
jstring jbody = NULL;
|
||||
jobjectArray jheaders = NULL;
|
||||
jstring result = NULL;
|
||||
const char *result_text = NULL;
|
||||
const char *newline;
|
||||
int attached = 0;
|
||||
int ok = 0;
|
||||
|
||||
if(status != NULL)
|
||||
*status = 0;
|
||||
if(app == NULL || app->activity == NULL || app->activity->vm == NULL ||
|
||||
app->activity->clazz == NULL || method == NULL || url == NULL)
|
||||
return 0;
|
||||
|
||||
jvm = app->activity->vm;
|
||||
activity = app->activity->clazz;
|
||||
if((*jvm)->GetEnv(jvm, (void **)&env, JNI_VERSION_1_6) != JNI_OK) {
|
||||
if((*jvm)->AttachCurrentThread(jvm, &env, NULL) != JNI_OK || env == NULL)
|
||||
return 0;
|
||||
attached = 1;
|
||||
}
|
||||
|
||||
activity_class = (*env)->GetObjectClass(env, activity);
|
||||
if(activity_class == NULL)
|
||||
goto done;
|
||||
method_id = (*env)->GetMethodID(env, activity_class, "syncHttpRequest",
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/lang/String;");
|
||||
if(method_id == NULL)
|
||||
goto done;
|
||||
|
||||
jmethod = (*env)->NewStringUTF(env, method);
|
||||
jurl = (*env)->NewStringUTF(env, url);
|
||||
jbody = (*env)->NewStringUTF(env, body != NULL ? body : "");
|
||||
jclass string_class = (*env)->FindClass(env, "java/lang/String");
|
||||
if(jmethod == NULL || jurl == NULL || jbody == NULL || string_class == NULL)
|
||||
goto done;
|
||||
jheaders = (*env)->NewObjectArray(env, header_count, string_class, NULL);
|
||||
if(jheaders == NULL)
|
||||
goto done;
|
||||
for(int i = 0; i < header_count; i++) {
|
||||
jstring value = (*env)->NewStringUTF(env, headers[i] != NULL ? headers[i] : "");
|
||||
if(value == NULL)
|
||||
goto done;
|
||||
(*env)->SetObjectArrayElement(env, jheaders, i, value);
|
||||
(*env)->DeleteLocalRef(env, value);
|
||||
}
|
||||
|
||||
result = (jstring)(*env)->CallObjectMethod(env, activity, method_id,
|
||||
jmethod, jurl, jbody, jheaders);
|
||||
if((*env)->ExceptionCheck(env) || result == NULL)
|
||||
goto done;
|
||||
result_text = (*env)->GetStringUTFChars(env, result, NULL);
|
||||
if(result_text == NULL)
|
||||
goto done;
|
||||
newline = strchr(result_text, '\n');
|
||||
if(newline == NULL)
|
||||
goto done;
|
||||
if(status != NULL)
|
||||
*status = strtol(result_text, NULL, 10);
|
||||
ok = sync_buffer_set(response, newline + 1);
|
||||
|
||||
done:
|
||||
if(result_text != NULL && result != NULL)
|
||||
(*env)->ReleaseStringUTFChars(env, result, result_text);
|
||||
if(result != NULL)
|
||||
(*env)->DeleteLocalRef(env, result);
|
||||
if(jheaders != NULL)
|
||||
(*env)->DeleteLocalRef(env, jheaders);
|
||||
if(jbody != NULL)
|
||||
(*env)->DeleteLocalRef(env, jbody);
|
||||
if(jurl != NULL)
|
||||
(*env)->DeleteLocalRef(env, jurl);
|
||||
if(jmethod != NULL)
|
||||
(*env)->DeleteLocalRef(env, jmethod);
|
||||
if((*env)->ExceptionCheck(env)) {
|
||||
(*env)->ExceptionDescribe(env);
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
if(attached)
|
||||
(*jvm)->DetachCurrentThread(jvm);
|
||||
return ok;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_HTTP)
|
||||
static InbeSyncClientResult
|
||||
sync_fetch_challenge(const char *base_url, const char *user_id, char nonce_hex[65])
|
||||
{
|
||||
char url[768];
|
||||
SyncBuffer response = {0};
|
||||
long status = 0;
|
||||
int ok;
|
||||
|
||||
nonce_hex[0] = '\0';
|
||||
sync_join_url(url, sizeof(url), base_url, INBE_CHALLENGE_PATH);
|
||||
if(strlen(url) + strlen(user_id) + 10 >= sizeof(url))
|
||||
return INBE_SYNC_CLIENT_INVALID_URL;
|
||||
strncat(url, "?user_id=", sizeof(url) - strlen(url) - 1);
|
||||
strncat(url, user_id, sizeof(url) - strlen(url) - 1);
|
||||
ok = sync_http_request("GET", url, NULL, NULL, 0, &response, &status);
|
||||
if(!ok || status != 200 ||
|
||||
!sync_find_json_string(response.data, "nonce", nonce_hex, 65) ||
|
||||
strlen(nonce_hex) != 64) {
|
||||
free(response.data);
|
||||
return status == 401 ? INBE_SYNC_CLIENT_AUTH_FAILED : INBE_SYNC_CLIENT_CHALLENGE_FAILED;
|
||||
}
|
||||
free(response.data);
|
||||
return INBE_SYNC_CLIENT_OK;
|
||||
}
|
||||
|
||||
static InbeSyncClientResult
|
||||
sync_send_signed(const char *base_url, const char *path, const char *method,
|
||||
const char *user_id, const char *body)
|
||||
{
|
||||
char nonce_hex[65];
|
||||
char message[256];
|
||||
char signature_hex[5000];
|
||||
char url[768];
|
||||
char user_header[96];
|
||||
char signature_header[5050];
|
||||
const char *headers[3];
|
||||
SyncBuffer response = {0};
|
||||
long status = 0;
|
||||
InbeSyncClientResult challenge_result;
|
||||
int ok;
|
||||
|
||||
challenge_result = sync_fetch_challenge(base_url, user_id, nonce_hex);
|
||||
if(challenge_result != INBE_SYNC_CLIENT_OK)
|
||||
return challenge_result;
|
||||
if(!sync_build_message(method, path, nonce_hex, body, message, sizeof(message)))
|
||||
return INBE_SYNC_CLIENT_SIGN_FAILED;
|
||||
if(!inbe_sync_account_sign_hex((const uint8_t *)message, strlen(message),
|
||||
signature_hex, sizeof(signature_hex)))
|
||||
return INBE_SYNC_CLIENT_SIGN_FAILED;
|
||||
sync_join_url(url, sizeof(url), base_url, path);
|
||||
snprintf(user_header, sizeof(user_header), "X-Inbe-User: %s", user_id);
|
||||
snprintf(signature_header, sizeof(signature_header), "X-Inbe-Signature: %s", signature_hex);
|
||||
headers[0] = "Content-Type: application/json";
|
||||
headers[1] = user_header;
|
||||
headers[2] = signature_header;
|
||||
ok = sync_http_request(method, url, body, headers, 3, &response, &status);
|
||||
free(response.data);
|
||||
if(!ok)
|
||||
return INBE_SYNC_CLIENT_REQUEST_FAILED;
|
||||
if(status == 401)
|
||||
return INBE_SYNC_CLIENT_AUTH_FAILED;
|
||||
return status >= 200 && status < 300 ? INBE_SYNC_CLIENT_OK : INBE_SYNC_CLIENT_REQUEST_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
InbeSyncClientResult
|
||||
inbe_sync_client_sync(const char *base_url)
|
||||
{
|
||||
#if defined(INBE_SYNC_CLIENT_HAS_HTTP)
|
||||
InbeSyncAccount account;
|
||||
char *payload;
|
||||
InbeSyncClientResult result;
|
||||
|
||||
if(!inbe_sync_client_url_valid(base_url))
|
||||
return INBE_SYNC_CLIENT_INVALID_URL;
|
||||
if(!inbe_sync_account_load(&account))
|
||||
return INBE_SYNC_CLIENT_NO_ACCOUNT;
|
||||
payload = inbe_storage_build_sync_payload_json(account.public_id, account.public_key_hex);
|
||||
if(payload == NULL)
|
||||
return INBE_SYNC_CLIENT_PAYLOAD_FAILED;
|
||||
result = sync_send_signed(base_url, INBE_SYNC_PATH, "POST", account.public_id, payload);
|
||||
inbe_storage_free_sync_payload_json(payload);
|
||||
return result;
|
||||
#else
|
||||
(void)base_url;
|
||||
return INBE_SYNC_CLIENT_UNAVAILABLE;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef INBE_SYNC_CLIENT_H
|
||||
#define INBE_SYNC_CLIENT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum InbeSyncClientResult {
|
||||
INBE_SYNC_CLIENT_OK = 0,
|
||||
INBE_SYNC_CLIENT_UNAVAILABLE,
|
||||
INBE_SYNC_CLIENT_INVALID_URL,
|
||||
INBE_SYNC_CLIENT_NO_ACCOUNT,
|
||||
INBE_SYNC_CLIENT_PAYLOAD_FAILED,
|
||||
INBE_SYNC_CLIENT_CHALLENGE_FAILED,
|
||||
INBE_SYNC_CLIENT_SIGN_FAILED,
|
||||
INBE_SYNC_CLIENT_REQUEST_FAILED,
|
||||
INBE_SYNC_CLIENT_AUTH_FAILED
|
||||
} InbeSyncClientResult;
|
||||
|
||||
int inbe_sync_client_url_valid(const char *url);
|
||||
int inbe_sync_client_normalize_url(const char *input, char *out, size_t out_size);
|
||||
InbeSyncClientResult inbe_sync_client_sync(const char *base_url);
|
||||
|
||||
#endif
|
||||
+235
-4
@@ -11,6 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int g_failures = 0;
|
||||
@@ -159,6 +160,32 @@ write_source_database(const char *root)
|
||||
inbe_storage_close();
|
||||
}
|
||||
|
||||
static void
|
||||
insert_raw_habit_day(const char *root, const char *habit_id, int local_date, int completed)
|
||||
{
|
||||
char db_path[512];
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
|
||||
make_path(db_path, sizeof(db_path), root, "inbe.db");
|
||||
check_true("open raw habit day db", sqlite3_open(db_path, &db) == SQLITE_OK);
|
||||
if(db == NULL)
|
||||
return;
|
||||
if(sqlite3_prepare_v2(db,
|
||||
"INSERT OR REPLACE INTO habit_days(habit_id,local_date,completed,updated_at) "
|
||||
"VALUES(?1,?2,?3,0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, habit_id, -1, SQLITE_TRANSIENT);
|
||||
sqlite3_bind_int(stmt, 2, local_date);
|
||||
sqlite3_bind_int(stmt, 3, completed ? 1 : 0);
|
||||
check_true("insert raw habit day", sqlite3_step(stmt) == SQLITE_DONE);
|
||||
} else {
|
||||
check_true("prepare raw habit day", 0);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
static void
|
||||
metadata_history_callback(const char *id, int year, int month, int day,
|
||||
int hour, int minute, int second,
|
||||
@@ -338,6 +365,91 @@ test_habit_name_merge_import(void)
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_import_conflict_prefers_data_over_empty(void)
|
||||
{
|
||||
char source[512], dest[512], zip_path[512];
|
||||
InbeHabits habits;
|
||||
InbeHabit *habit;
|
||||
|
||||
make_clean_root(source, sizeof(source), "conflict-source");
|
||||
make_clean_root(dest, sizeof(dest), "conflict-dest");
|
||||
make_path(zip_path, sizeof(zip_path), source, "conflict-export.zip");
|
||||
|
||||
check_true("init conflict source", inbe_storage_init(source));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict source habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){224, 124, 104, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_storage_set_setting_text("language", "");
|
||||
inbe_storage_close();
|
||||
insert_raw_habit_day(source, "habit-1", 20260618, 0);
|
||||
check_true("reopen conflict source", inbe_storage_init(source));
|
||||
check_true("conflict source export", inbe_storage_export_zip(zip_path));
|
||||
inbe_storage_close();
|
||||
|
||||
check_true("init conflict dest", inbe_storage_init(dest));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add conflict dest habit",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){126, 183, 230, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20260618, 1);
|
||||
inbe_storage_set_setting_text("language", "en");
|
||||
check_true("conflict import",
|
||||
inbe_storage_import_zip_ex(zip_path, INBE_STORAGE_IMPORT_DATA_AND_SETTINGS));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("conflict habits load", inbe_storage_habits_load(&habits));
|
||||
habit = find_habit_ci(&habits, "Meditation");
|
||||
check_true("conflict keeps completed day",
|
||||
habit != NULL && inbe_habit_completed_day(habit, 20260618));
|
||||
check_str("conflict keeps non-empty setting",
|
||||
inbe_storage_get_setting_text("language"), "en");
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_all_resets_habits_to_empty_storage(void)
|
||||
{
|
||||
char root[512];
|
||||
InbeHabits habits;
|
||||
long long deleted;
|
||||
|
||||
make_clean_root(root, sizeof(root), "delete-all");
|
||||
check_true("init delete all db", inbe_storage_init(root));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add delete all habit",
|
||||
inbe_habits_add_custom(&habits, "Work out",
|
||||
(Color){99, 196, 165, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20260618, 1);
|
||||
check_int("delete all habit count before", inbe_storage_habit_count(), 1);
|
||||
check_true("delete all sees habit-only data", inbe_storage_has_any());
|
||||
|
||||
deleted = inbe_storage_delete_all_sessions();
|
||||
check_true("delete all removed habit data", deleted >= 2);
|
||||
check_int("delete all habit count after", inbe_storage_habit_count(), 0);
|
||||
|
||||
inbe_habits_add_default_set(&habits);
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("load default habit after delete all", inbe_storage_habits_load(&habits));
|
||||
check_int("default habit count after delete all", habits.count, 1);
|
||||
check_true("default meditation after delete all",
|
||||
strcmp(habits.items[0].name, "Meditation") == 0);
|
||||
check_true("old workout day removed",
|
||||
!inbe_habit_completed_day(&habits.items[0], 20260618));
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(root);
|
||||
}
|
||||
|
||||
static void
|
||||
write_multi_habit_source_database(const char *root, const char *zip_path)
|
||||
{
|
||||
@@ -533,6 +645,7 @@ static void
|
||||
write_tickmate_database(const char *path)
|
||||
{
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char *error = NULL;
|
||||
|
||||
check_true("open tickmate db", sqlite3_open(path, &db) == SQLITE_OK);
|
||||
@@ -547,15 +660,56 @@ write_tickmate_database(const char *path)
|
||||
"CREATE TABLE ticks(_id integer primary key autoincrement,"
|
||||
"_track_id integer,year integer,month integer,day integer,"
|
||||
"hour integer,minute integer,second integer,has_time_info integer DEFAULT 0);"
|
||||
"INSERT INTO tracks(_id,name,description,icon,enabled,color,\"order\") "
|
||||
"VALUES(1,'Meditation','Silenced my mind','',1,8925,0);"
|
||||
"INSERT INTO tracks(_id,name,description,icon,enabled,multiple_entries_per_day,color,\"order\") "
|
||||
"VALUES(1,'Meditation','Silenced my mind','',1,1,8925,0);"
|
||||
"INSERT INTO ticks(_track_id,year,month,day,hour,minute,second,has_time_info) "
|
||||
"VALUES(1,2026,6,13,0,0,0,0);",
|
||||
"VALUES(1,2026,0,1,0,0,0,0),"
|
||||
"(1,2026,1,2,0,0,0,0),"
|
||||
"(1,2026,2,3,0,0,0,0),"
|
||||
"(1,2026,3,4,0,0,0,0),"
|
||||
"(1,2026,4,5,0,0,0,0),"
|
||||
"(1,2026,5,6,0,0,0,0),"
|
||||
"(1,2026,6,7,0,0,0,0),"
|
||||
"(1,2026,7,8,0,0,0,0),"
|
||||
"(1,2026,8,9,0,0,0,0),"
|
||||
"(1,2026,9,10,0,0,0,0),"
|
||||
"(1,2026,10,11,0,0,0,0),"
|
||||
"(1,2026,11,12,0,0,0,0),"
|
||||
"(1,2025,0,1,0,0,0,0),"
|
||||
"(1,2025,0,1,0,0,0,0);",
|
||||
NULL, NULL, &error) == SQLITE_OK);
|
||||
if(error != NULL) {
|
||||
fprintf(stderr, "tickmate setup SQL error: %s\n", error);
|
||||
sqlite3_free(error);
|
||||
}
|
||||
check_true("prepare large tickmate insert",
|
||||
sqlite3_prepare_v2(db,
|
||||
"INSERT INTO ticks(_track_id,year,month,day,hour,minute,second,has_time_info) "
|
||||
"VALUES(1,?1,?2,?3,0,0,0,0)",
|
||||
-1, &stmt, NULL) == SQLITE_OK);
|
||||
if(stmt != NULL) {
|
||||
struct tm day;
|
||||
|
||||
check_true("begin large tickmate insert", sqlite3_exec(db, "BEGIN", NULL, NULL, NULL) == SQLITE_OK);
|
||||
memset(&day, 0, sizeof(day));
|
||||
day.tm_year = 2025 - 1900;
|
||||
day.tm_mon = 0;
|
||||
day.tm_mday = 1;
|
||||
day.tm_hour = 12;
|
||||
mktime(&day);
|
||||
for(int i = 0; i < 12000; i++) {
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_clear_bindings(stmt);
|
||||
sqlite3_bind_int(stmt, 1, day.tm_year + 1900);
|
||||
sqlite3_bind_int(stmt, 2, day.tm_mon);
|
||||
sqlite3_bind_int(stmt, 3, day.tm_mday);
|
||||
check_true("large tickmate insert row", sqlite3_step(stmt) == SQLITE_DONE);
|
||||
day.tm_mday++;
|
||||
mktime(&day);
|
||||
}
|
||||
check_true("commit large tickmate insert", sqlite3_exec(db, "COMMIT", NULL, NULL, NULL) == SQLITE_OK);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
@@ -575,24 +729,101 @@ test_tickmate_db_import(void)
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("tickmate habits load", inbe_storage_habits_load(&habits));
|
||||
check_int("tickmate habit count", habits.count, 1);
|
||||
check_true("tickmate habit day", inbe_habit_completed_day(&habits.items[0], 20260613));
|
||||
check_true("tickmate january day", inbe_habit_completed_day(&habits.items[0], 20260101));
|
||||
check_true("tickmate february day", inbe_habit_completed_day(&habits.items[0], 20260202));
|
||||
check_true("tickmate march day", inbe_habit_completed_day(&habits.items[0], 20260303));
|
||||
check_true("tickmate april day", inbe_habit_completed_day(&habits.items[0], 20260404));
|
||||
check_true("tickmate may day", inbe_habit_completed_day(&habits.items[0], 20260505));
|
||||
check_true("tickmate june day", inbe_habit_completed_day(&habits.items[0], 20260606));
|
||||
check_true("tickmate july day", inbe_habit_completed_day(&habits.items[0], 20260707));
|
||||
check_true("tickmate august day", inbe_habit_completed_day(&habits.items[0], 20260808));
|
||||
check_true("tickmate september day", inbe_habit_completed_day(&habits.items[0], 20260909));
|
||||
check_true("tickmate october day", inbe_habit_completed_day(&habits.items[0], 20261010));
|
||||
check_true("tickmate november day", inbe_habit_completed_day(&habits.items[0], 20261111));
|
||||
check_true("tickmate december day", inbe_habit_completed_day(&habits.items[0], 20261212));
|
||||
check_true("tickmate loads thousands of days",
|
||||
inbe_habit_completed_day(&habits.items[0], 20571108));
|
||||
check_true("tickmate habit name", strcmp(habits.items[0].name, "Meditation") == 0);
|
||||
check_int("tickmate enables counter habit", habits.items[0].counter_enabled, 1);
|
||||
check_int("tickmate imports count", inbe_habit_day_count(&habits.items[0], 20250101), 3);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_tickmate_reimport_recovers_counter_data(void)
|
||||
{
|
||||
char source[512], dest[512], db_path[512];
|
||||
InbeHabits habits;
|
||||
|
||||
make_clean_root(source, sizeof(source), "tickmate-reimport-source");
|
||||
make_clean_root(dest, sizeof(dest), "tickmate-reimport-dest");
|
||||
make_path(db_path, sizeof(db_path), source, "tickmate.db");
|
||||
write_tickmate_database(db_path);
|
||||
|
||||
check_true("init tickmate reimport dest", inbe_storage_init(dest));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_int("add old boolean meditation",
|
||||
inbe_habits_add_custom(&habits, "Meditation",
|
||||
(Color){99, 196, 165, 255},
|
||||
INBE_HABIT_SYNC_NONE, 0),
|
||||
0);
|
||||
inbe_habit_set_day(&habits, 0, 20250101, 1);
|
||||
check_true("tickmate reimport", inbe_storage_import_zip(db_path));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("tickmate reimport load", inbe_storage_habits_load(&habits));
|
||||
check_int("tickmate reimport habit count", habits.count, 1);
|
||||
check_int("tickmate reimport enables counter", habits.items[0].counter_enabled, 1);
|
||||
check_int("tickmate reimport restores count",
|
||||
inbe_habit_day_count(&habits.items[0], 20250101), 3);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(source);
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
static void
|
||||
test_external_tickmate_db_import(void)
|
||||
{
|
||||
const char *db_path = getenv("INBE_TICKMATE_IMPORT_FIXTURE");
|
||||
char dest[512];
|
||||
InbeStorageImportInfo info;
|
||||
InbeHabits habits;
|
||||
|
||||
if(db_path == NULL || db_path[0] == '\0')
|
||||
return;
|
||||
|
||||
make_clean_root(dest, sizeof(dest), "external-tickmate-dest");
|
||||
check_true("init external tickmate import dest", inbe_storage_init(dest));
|
||||
memset(&info, 0, sizeof(info));
|
||||
check_true("inspect external tickmate db", inbe_storage_inspect_import(db_path, &info));
|
||||
check_true("external tickmate db valid", info.valid);
|
||||
check_true("external tickmate db has habits", info.has_habits);
|
||||
check_true("external tickmate db import", inbe_storage_import_zip(db_path));
|
||||
memset(&habits, 0, sizeof(habits));
|
||||
check_true("external tickmate habits load", inbe_storage_habits_load(&habits));
|
||||
check_true("external tickmate habit count", habits.count > 0);
|
||||
inbe_storage_close();
|
||||
|
||||
remove_tree(dest);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
test_raw_db_import();
|
||||
test_zip_db_import();
|
||||
test_habit_name_merge_import();
|
||||
test_import_conflict_prefers_data_over_empty();
|
||||
test_delete_all_resets_habits_to_empty_storage();
|
||||
test_import_modes_preserve_habits_and_settings_choice();
|
||||
test_legacy_zip_import();
|
||||
test_legacy_file_startup_migration();
|
||||
test_tickmate_db_import();
|
||||
test_tickmate_reimport_recovers_counter_data();
|
||||
test_external_tickmate_db_import();
|
||||
test_session_metadata();
|
||||
|
||||
if(g_failures != 0) {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
#include "sync_client.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int inbe_sync_client_test_response_buffer(const char *first, const char *second,
|
||||
char *out, size_t out_size);
|
||||
|
||||
static int failures = 0;
|
||||
|
||||
static void
|
||||
check_valid(const char *input, const char *normalized)
|
||||
{
|
||||
char out[256];
|
||||
|
||||
if(!inbe_sync_client_url_valid(input)) {
|
||||
fprintf(stderr, "FAIL valid %s\n", input);
|
||||
failures++;
|
||||
return;
|
||||
}
|
||||
if(!inbe_sync_client_normalize_url(input, out, sizeof(out)) ||
|
||||
strcmp(out, normalized) != 0) {
|
||||
fprintf(stderr, "FAIL normalize %s: got %s, want %s\n",
|
||||
input, out, normalized);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_invalid(const char *input)
|
||||
{
|
||||
char out[256];
|
||||
|
||||
if(inbe_sync_client_url_valid(input)) {
|
||||
fprintf(stderr, "FAIL invalid accepted %s\n", input);
|
||||
failures++;
|
||||
}
|
||||
if(inbe_sync_client_normalize_url(input, out, sizeof(out))) {
|
||||
fprintf(stderr, "FAIL invalid normalized %s to %s\n", input, out);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check_response_buffer(void)
|
||||
{
|
||||
char out[64];
|
||||
|
||||
if(!inbe_sync_client_test_response_buffer("{\"nonce\":\"", "abc\"}", out, sizeof(out)) ||
|
||||
strcmp(out, "{\"nonce\":\"abc\"}") != 0) {
|
||||
fprintf(stderr, "FAIL response buffer append: got %s\n", out);
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
check_valid("https://api.waozi.xyz", "https://api.waozi.xyz");
|
||||
check_valid("http://localhost:8080", "http://localhost:8080");
|
||||
check_valid("localhost:8080", "http://localhost:8080");
|
||||
check_valid("localhost:3000", "http://localhost:3000");
|
||||
check_valid("127.0.0.1:8080", "http://127.0.0.1:8080");
|
||||
check_valid("127.0.0.1:49152", "http://127.0.0.1:49152");
|
||||
check_valid("10.0.2.2:8080", "http://10.0.2.2:8080");
|
||||
|
||||
check_invalid("");
|
||||
check_invalid("localhost.evil.test:8080");
|
||||
check_invalid("http://localhost.evil.test");
|
||||
check_invalid("http://example.com");
|
||||
|
||||
check_response_buffer();
|
||||
|
||||
if(failures != 0) {
|
||||
fprintf(stderr, "%d sync URL test failure(s)\n", failures);
|
||||
return 1;
|
||||
}
|
||||
printf("sync URL tests passed\n");
|
||||
return 0;
|
||||
}
|
||||
+1
Submodule vendor/liboqs added at d95fc734f5.
+4
-4
@@ -3,8 +3,8 @@
|
||||
IDI_APP_ICON ICON "inbe.ico"
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,3,4,0
|
||||
PRODUCTVERSION 1,3,4,0
|
||||
FILEVERSION 1,4,0,0
|
||||
PRODUCTVERSION 1,4,0,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@@ -21,11 +21,11 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "waozi"
|
||||
VALUE "FileDescription", "Inner Breeze"
|
||||
VALUE "FileVersion", "1.3.4"
|
||||
VALUE "FileVersion", "1.4.0"
|
||||
VALUE "InternalName", "inbe"
|
||||
VALUE "OriginalFilename", "inbe-windows-x86_64.exe"
|
||||
VALUE "ProductName", "Inner Breeze"
|
||||
VALUE "ProductVersion", "1.3.4"
|
||||
VALUE "ProductVersion", "1.4.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
Reference in new issue
Block a user