fi xstorage

This commit is contained in:
waozi committed 2026-06-22 00:27:14 -03:00
1 parent 06358b5bfb
commit 0cf6f436e1
29 files changed
+251 -7

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

@@ -1,2 +1,3 @@
### Fixed
Fixed
---
- Import now restores habits, habit sync settings, and optionally app settings from Inbe SQLite exports.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 249 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 37 KiB

+18 -3
View File
@@ -45,6 +45,7 @@ mkdir -p "$PROJECT_ROOT/windows"
mkdir -p "$PROJECT_ROOT/packaging/linux/appimage"
mkdir -p "$PROJECT_ROOT/packaging/chrome-web-store/icons"
mkdir -p "$PROJECT_ROOT/web-assets/icons"
mkdir -p "$PROJECT_ROOT/fastlane/metadata/android/en-US/images"
generate_transparent() {
local size=$1
@@ -52,6 +53,9 @@ generate_transparent() {
magick "$SOURCE_IMAGE" \
-filter lanczos \
-resize "${size}x${size}" \
-strip \
+set date:create +set date:modify +set date:timestamp \
-define png:exclude-chunk=time \
"$output"
}
@@ -68,6 +72,9 @@ generate_maskable() {
\( -size "${size}x${size}" "xc:$SKY_BLUE" \) +swap \
-compose over \
-composite \
-strip \
+set date:create +set date:modify +set date:timestamp \
-define png:exclude-chunk=time \
"$output"
}
@@ -106,9 +113,9 @@ echo "🪟 Generating Windows icon..."
# ICO supports transparency; do not flatten.
magick \
"$SOURCE_IMAGE" -resize 256x256 \
"$SOURCE_IMAGE" -resize 192x192 \
"$SOURCE_IMAGE" -resize 32x32 \
"$SOURCE_IMAGE" -resize 256x256 -strip \
"$SOURCE_IMAGE" -resize 192x192 -strip \
"$SOURCE_IMAGE" -resize 32x32 -strip \
"$PROJECT_ROOT/windows/inbe.ico"
echo "✅ Windows icon generated"
@@ -120,6 +127,13 @@ generate_transparent 256 "$PROJECT_ROOT/packaging/linux/appimage/inbe.png"
echo "✅ Linux AppImage icon generated"
echo "🏪 Generating Fastlane store icon..."
# F-Droid/Fastlane store listing icon expects a 512x512 PNG.
generate_maskable 512 "$PROJECT_ROOT/fastlane/metadata/android/en-US/images/icon.png"
echo "✅ Fastlane store icon generated"
echo "🌐 Generating Chrome Web Store icons..."
# Chrome Web Store icons (transparent, various sizes)
@@ -151,6 +165,7 @@ echo "Generated icons:"
echo " 📱 Android: mipmap PNGs + adaptive drawable foreground/background"
echo " 🪟 Windows: windows/inbe.ico (256, 192, 32 resolutions)"
echo " 🐧 Linux: packaging/linux/appimage/inbe.png (256x256 transparent)"
echo " 🏪 Store: fastlane/metadata/android/en-US/images/icon.png (512x512)"
echo " 🌐 Chrome: packaging/chrome-web-store/icons/ (16, 32, 48, 128)"
echo " 🌐 Web: web-assets/icons/ (transparent + maskable PWA icons)"
echo
+139
View File
@@ -23,6 +23,7 @@
#endif
static long long storage_max_sync_outbox_seq(void);
static int storage_has_orphan_habit_days(void);
#define STORAGE_SYNC_BACKFILL_KEY "sync_backfill_v2_done"
@@ -1200,6 +1201,8 @@ storage_build_sync_payload_json(const char *user_id_hash, const char *public_key
storage_enqueue_all_sync_state();
since_server_version = get_meta_int64("sync_last_server_version", 0);
full_upload_done = get_meta_int64("sync_full_upload_done", 0) != 0;
if(storage_has_orphan_habit_days())
since_server_version = 0;
through_seq = storage_max_sync_outbox_seq();
g_storage.pending_sync_outbox_seq = through_seq;
json.ok = 1;
@@ -1288,6 +1291,26 @@ storage_max_sync_outbox_seq(void)
return seq;
}
static int
storage_has_orphan_habit_days(void)
{
sqlite3_stmt *stmt = NULL;
int found = 0;
if(g_storage.db == NULL)
return 0;
if(sqlite3_prepare_v2(g_storage.db,
"SELECT 1 FROM habit_days hd "
"WHERE hd.habit_id<>'' "
"AND NOT EXISTS (SELECT 1 FROM habits h WHERE h.id=hd.habit_id) "
"LIMIT 1",
-1, &stmt, NULL) != SQLITE_OK)
return 0;
found = sqlite3_step(stmt) == SQLITE_ROW;
sqlite3_finalize(stmt);
return found;
}
static void
storage_clear_uploaded_outbox(long long through_seq)
{
@@ -1362,6 +1385,121 @@ storage_exec_json_user_sql(const char *sql, const char *json)
return 1;
}
static int
storage_ascii_equal_ci(const char *a, const char *b)
{
unsigned char ca;
unsigned char cb;
if(a == NULL || b == NULL)
return 0;
while(*a != '\0' && *b != '\0') {
ca = (unsigned char)*a++;
cb = (unsigned char)*b++;
if(ca >= 'A' && ca <= 'Z')
ca = (unsigned char)(ca - 'A' + 'a');
if(cb >= 'A' && cb <= 'Z')
cb = (unsigned char)(cb - 'A' + 'a');
if(ca != cb)
return 0;
}
return *a == '\0' && *b == '\0';
}
static int
storage_merge_habit_into(const char *keeper_id, const char *duplicate_id)
{
sqlite3_stmt *stmt = NULL;
static const char *const sqls[] = {
"UPDATE habit_days "
"SET completed=MAX(completed,COALESCE((SELECT d.completed FROM habit_days d "
" WHERE d.habit_id=?2 AND d.local_date=habit_days.local_date),0)),"
" count=MAX(count,COALESCE((SELECT d.count FROM habit_days d "
" WHERE d.habit_id=?2 AND d.local_date=habit_days.local_date),0)),"
" session_count=MAX(session_count,COALESCE((SELECT d.session_count FROM habit_days d "
" WHERE d.habit_id=?2 AND d.local_date=habit_days.local_date),0)),"
" updated_at=MAX(updated_at,COALESCE((SELECT d.updated_at FROM habit_days d "
" WHERE d.habit_id=?2 AND d.local_date=habit_days.local_date),0)) "
"WHERE habit_id=?1 AND EXISTS (SELECT 1 FROM habit_days d "
" WHERE d.habit_id=?2 AND d.local_date=habit_days.local_date)",
"INSERT INTO habit_days(habit_id,local_date,completed,count,session_count,updated_at) "
"SELECT ?1,d.local_date,d.completed,d.count,d.session_count,d.updated_at "
"FROM habit_days d WHERE d.habit_id=?2 "
"AND NOT EXISTS (SELECT 1 FROM habit_days k "
" WHERE k.habit_id=?1 AND k.local_date=d.local_date)",
"DELETE FROM habit_days WHERE habit_id=?2",
"DELETE FROM habits WHERE id=?2"
};
int ok = 1;
if(keeper_id == NULL || duplicate_id == NULL ||
keeper_id[0] == '\0' || duplicate_id[0] == '\0' ||
strcmp(keeper_id, duplicate_id) == 0)
return 1;
for(size_t i = 0; i < sizeof(sqls) / sizeof(sqls[0]); i++) {
if(sqlite3_prepare_v2(g_storage.db, sqls[i], -1, &stmt, NULL) != SQLITE_OK)
return 0;
bind_text(stmt, 1, keeper_id);
bind_text(stmt, 2, duplicate_id);
ok = sqlite3_step(stmt) == SQLITE_DONE;
sqlite3_finalize(stmt);
stmt = NULL;
if(!ok)
return 0;
}
return ok;
}
static int
storage_merge_duplicate_habit_names(void)
{
sqlite3_stmt *stmt = NULL;
struct {
char id[INBE_STORAGE_ID_SIZE];
char name[INBE_HABIT_NAME_SIZE];
int merged;
} rows[64];
int count = 0;
int ok = 1;
if(g_storage.db == NULL)
return 0;
if(sqlite3_prepare_v2(g_storage.db,
"SELECT id,name FROM habits WHERE user_id=?1 AND deleted_at=0 "
"ORDER BY sort_order,id",
-1, &stmt, NULL) != SQLITE_OK)
return 0;
bind_text(stmt, 1, g_storage.user_id);
while(count < (int)(sizeof(rows) / sizeof(rows[0])) &&
sqlite3_step(stmt) == SQLITE_ROW) {
const char *id = (const char *)sqlite3_column_text(stmt, 0);
const char *name = (const char *)sqlite3_column_text(stmt, 1);
snprintf(rows[count].id, sizeof(rows[count].id), "%s", id != NULL ? id : "");
snprintf(rows[count].name, sizeof(rows[count].name), "%s", name != NULL ? name : "");
rows[count].merged = 0;
count++;
}
sqlite3_finalize(stmt);
for(int i = 0; i < count && ok; i++) {
if(rows[i].merged || rows[i].name[0] == '\0')
continue;
for(int j = i + 1; j < count; j++) {
if(rows[j].merged)
continue;
if(!storage_ascii_equal_ci(rows[i].name, rows[j].name))
continue;
ok = storage_merge_habit_into(rows[i].id, rows[j].id);
rows[j].merged = 1;
if(!ok)
break;
}
}
return ok;
}
int
storage_apply_sync_response_json(const char *response_json)
{
@@ -1460,6 +1598,7 @@ storage_apply_sync_response_json(const char *response_json)
return 0;
if(!storage_exec_json_user_sql(habits_sql, response_json) ||
!storage_exec_json_user_sql(habit_days_sql, response_json) ||
!storage_merge_duplicate_habit_names() ||
!storage_exec_json_user_sql(sessions_sql, response_json) ||
!storage_exec_json_user_sql(delete_rounds_sql, response_json) ||
!storage_exec_json_user_sql(rounds_sql, response_json)) {
+83
View File
@@ -541,6 +541,87 @@ test_stale_habit_save_keeps_synced_remote_habits(void)
remove_tree(root);
}
static void
test_sync_payload_resets_cursor_for_orphan_habit_days(void)
{
char root[512];
char db_path[512];
char *payload;
sqlite3 *db = NULL;
make_clean_root(root, sizeof(root), "sync-orphan-habit-days");
check_true("init orphan habit day db", storage_init(root));
storage_close();
insert_raw_habit_day(root, "habit-2", 20260617, 1);
insert_raw_habit_day(root, "habit-3", 20260618, 1);
make_path(db_path, sizeof(db_path), root, "inbe.db");
check_true("open orphan cursor raw db", sqlite3_open(db_path, &db) == SQLITE_OK);
if(db != NULL) {
check_true("set orphan sync cursor",
sqlite3_exec(db,
"INSERT OR REPLACE INTO meta(key,value) VALUES('sync_last_server_version','530');"
"INSERT OR REPLACE INTO meta(key,value) VALUES('sync_full_upload_done','1');"
"INSERT OR REPLACE INTO meta(key,value) VALUES('sync_backfill_v2_done','1');",
NULL, NULL, NULL) == SQLITE_OK);
sqlite3_close(db);
}
check_true("reopen orphan habit day db", storage_init(root));
payload = storage_build_sync_payload_json("test-hash", "test-public-key");
check_true("orphan habit days request full snapshot",
payload != NULL && strstr(payload, "\"since_server_version\":0") != NULL);
storage_free_sync_payload_json(payload);
storage_close();
remove_tree(root);
}
static void
test_sync_apply_merges_duplicate_habit_names(void)
{
char root[512];
InbeHabits habits;
InbeHabit *merged;
const char *response =
"{\"server_version\":1,\"changes\":{\"habits\":["
"{\"id\":\"habit-1\",\"name\":\"New Habit\",\"color_r\":99,\"color_g\":196,\"color_b\":165,"
"\"sync_mode\":0,\"sync_activity\":0,\"counter_enabled\":0,\"sort_order\":0,"
"\"deleted_at\":0,\"updated_at\":\"2026-06-19T21:00:00Z\"},"
"{\"id\":\"habit-2\",\"name\":\"New Habit\",\"color_r\":99,\"color_g\":196,\"color_b\":165,"
"\"sync_mode\":0,\"sync_activity\":0,\"counter_enabled\":0,\"sort_order\":1,"
"\"deleted_at\":0,\"updated_at\":\"2026-06-19T21:01:00Z\"},"
"{\"id\":\"meditation\",\"name\":\"Meditation\",\"color_r\":126,\"color_g\":183,\"color_b\":230,"
"\"sync_mode\":1,\"sync_activity\":3,\"counter_enabled\":0,\"sort_order\":2,"
"\"deleted_at\":0,\"updated_at\":\"2026-06-19T21:02:00Z\"}"
"],\"habit_days\":["
"{\"habit_id\":\"habit-1\",\"local_date\":20260617,\"completed\":true,\"count\":1,"
"\"updated_at\":\"2026-06-19T21:00:00Z\"},"
"{\"habit_id\":\"habit-2\",\"local_date\":20260618,\"completed\":true,\"count\":1,"
"\"updated_at\":\"2026-06-19T21:01:00Z\"},"
"{\"habit_id\":\"meditation\",\"local_date\":20260619,\"completed\":true,\"count\":1,"
"\"updated_at\":\"2026-06-19T21:02:00Z\"}"
"],\"sessions\":[]}}";
make_clean_root(root, sizeof(root), "sync-duplicate-habit-names");
check_true("init duplicate habit name db", storage_init(root));
check_true("apply duplicate named habits", storage_apply_sync_response_json(response));
memset(&habits, 0, sizeof(habits));
check_true("load merged duplicate habits", storage_habits_load(&habits));
check_int("duplicate habit names collapse to one tab", habits.count, 2);
merged = find_habit_ci(&habits, "New Habit");
check_true("merged habit visible", merged != NULL);
if(merged != NULL) {
check_true("first duplicate day kept", habit_completed_day(merged, 20260617));
check_true("second duplicate day moved", habit_completed_day(merged, 20260618));
}
check_true("meditation remains visible", find_habit_ci(&habits, "Meditation") != NULL);
habits_free(&habits);
storage_close();
remove_tree(root);
}
static void
test_sync_apply_preserves_queued_habit_counter_enabled(void)
{
@@ -1334,6 +1415,8 @@ main(void)
test_sync_apply_preserves_counter_counts();
test_sync_apply_updates_habit_counter_enabled();
test_stale_habit_save_keeps_synced_remote_habits();
test_sync_payload_resets_cursor_for_orphan_habit_days();
test_sync_apply_merges_duplicate_habit_names();
test_sync_apply_preserves_queued_habit_counter_enabled();
test_session_linked_counts_materialize_for_sync();
test_existing_sessions_materialize_after_habit_save();
+9 -3
View File
@@ -89,7 +89,8 @@ while IFS= read -r VERSION; do
continue
fi
# Extract changelog content for this version
# Extract Fastlane-friendly changelog content for this version. F-Droid
# displays changelogs as text, so avoid literal Markdown heading markers.
CHANGELOG_CONTENT=$(awk -v ver="$VERSION" '
BEGIN { in_section=0 }
/^## \[/ {
@@ -100,8 +101,13 @@ while IFS= read -r VERSION; do
}
}
in_section {
# Print section headers and bullet points
if (/^### / || /^- /) print
if (/^### /) {
sub(/^### /, "")
print
print "---"
} else if (/^- /) {
print
}
}
' "$CHANGELOG_FILE")
Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

After

Width:  |  Height:  |  Size: 249 KiB