chore: make two-way progress sync always-on (#2734)

This commit is contained in:
James Ward
2026-09-26 11:23:26 -04:00
committed by GitHub
parent 4923b62f88
commit 18b0c8cfbc
34 changed files with 54 additions and 470 deletions
@@ -49,27 +49,21 @@
</div>
</div>
@if (!deviceForm.kobo.twoWaySync().hidden()) {
<app-field [field]="deviceForm.kobo.twoWaySync" label="Two-way progress sync" hint="Requires KEPUB.">
<app-switch [formField]="deviceForm.kobo.twoWaySync" />
</app-field>
<app-field [field]="deviceForm.kobo.convertToKepub" label="Convert to KEPUB" hint="Needed for proper sync.">
<app-switch [formField]="deviceForm.kobo.convertToKepub" />
</app-field>
<app-field [field]="deviceForm.kobo.convertToKepub" label="Convert to KEPUB" hint="Needed for two-way sync.">
<app-switch [formField]="deviceForm.kobo.convertToKepub" />
</app-field>
<app-field [field]="deviceForm.kobo.markAsReading" label="Mark as reading at {{ model().kobo.markAsReading }}%" hint="1-10%.">
<app-slider [formField]="deviceForm.kobo.markAsReading" ariaLabel="Mark as reading threshold" />
</app-field>
<app-field [field]="deviceForm.kobo.markAsReading" label="Mark as reading at {{ model().kobo.markAsReading }}%" hint="1-10%.">
<app-slider [formField]="deviceForm.kobo.markAsReading" ariaLabel="Mark as reading threshold" />
</app-field>
<app-field [field]="deviceForm.kobo.markAsFinished" label="Mark as finished at {{ model().kobo.markAsFinished }}%" hint="90-100%.">
<app-slider [formField]="deviceForm.kobo.markAsFinished" ariaLabel="Mark as finished threshold" />
</app-field>
<app-field [field]="deviceForm.kobo.markAsFinished" label="Mark as finished at {{ model().kobo.markAsFinished }}%" hint="90-100%.">
<app-slider [formField]="deviceForm.kobo.markAsFinished" ariaLabel="Mark as finished threshold" />
</app-field>
<app-field [field]="deviceForm.kobo.conversionLimitMb" label="Conversion size limit" hint="1-250 MB.">
<app-number-input [formField]="deviceForm.kobo.conversionLimitMb" unit="MB" />
</app-field>
}
<app-field [field]="deviceForm.kobo.conversionLimitMb" label="Conversion size limit" hint="1-250 MB.">
<app-number-input [formField]="deviceForm.kobo.conversionLimitMb" unit="MB" />
</app-field>
</section>
<section class="flex flex-col gap-5 py-7">
@@ -83,10 +77,6 @@
</div>
@if (!deviceForm.koreader.username().hidden()) {
<app-field [field]="deviceForm.koreader.syncWithWebReader" label="Also sync with the web reader" hint="Shares progress.">
<app-switch [formField]="deviceForm.koreader.syncWithWebReader" />
</app-field>
<app-field [field]="deviceForm.koreader.username" label="Sync username" hint="Required when enabled.">
<app-input [formField]="deviceForm.koreader.username" placeholder="reader" />
</app-field>
@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/cor
import { JsonPipe } from '@angular/common';
import { CdkScrollable } from '@angular/cdk/scrolling';
import { Router } from '@angular/router';
import { form, FormField, FormRoot, hidden, max, min, minLength, required, validate } from '@angular/forms/signals';
import { form, FormField, FormRoot, hidden, max, min, minLength, required } from '@angular/forms/signals';
import { AppButtonComponent } from '../../../shared/ui/button/app-button.component';
import { AppFieldComponent } from '../../../shared/ui/field/app-field.component';
import { AppInputComponent } from '../../../shared/ui/input/app-input.component';
@@ -17,13 +17,12 @@ interface DeviceFormModel {
hardcover: { enabled: boolean; apiKey: string };
kobo: {
enabled: boolean;
twoWaySync: boolean;
convertToKepub: boolean;
markAsReading: number;
markAsFinished: number;
conversionLimitMb: number | null;
};
koreader: { enabled: boolean; syncWithWebReader: boolean; username: string; password: string };
koreader: { enabled: boolean; username: string; password: string };
}
function createInitialModel(): DeviceFormModel {
@@ -31,13 +30,12 @@ function createInitialModel(): DeviceFormModel {
hardcover: { enabled: false, apiKey: '' },
kobo: {
enabled: true,
twoWaySync: false,
convertToKepub: true,
markAsReading: 3,
markAsFinished: 95,
conversionLimitMb: 50,
},
koreader: { enabled: false, syncWithWebReader: false, username: '', password: '' },
koreader: { enabled: false, username: '', password: '' },
};
}
@@ -83,18 +81,11 @@ export class DeviceFormExampleComponent {
max(path.kobo.markAsFinished, 100);
min(path.kobo.conversionLimitMb, 1);
max(path.kobo.conversionLimitMb, 250);
hidden(path.kobo.twoWaySync, ({ valueOf }) => !valueOf(path.kobo.enabled));
hidden(path.kobo.convertToKepub, ({ valueOf }) => !valueOf(path.kobo.enabled));
hidden(path.kobo.markAsReading, ({ valueOf }) => !valueOf(path.kobo.enabled));
hidden(path.kobo.markAsFinished, ({ valueOf }) => !valueOf(path.kobo.enabled));
hidden(path.kobo.conversionLimitMb, ({ valueOf }) => !valueOf(path.kobo.enabled));
validate(path.kobo.twoWaySync, ({ value, valueOf }) =>
value() && !valueOf(path.kobo.convertToKepub)
? { kind: 'needsKepub', message: 'Two-way sync needs KEPUB conversion turned on' }
: null,
);
hidden(path.koreader.syncWithWebReader, ({ valueOf }) => !valueOf(path.koreader.enabled));
hidden(path.koreader.username, ({ valueOf }) => !valueOf(path.koreader.enabled));
hidden(path.koreader.password, ({ valueOf }) => !valueOf(path.koreader.enabled));
required(path.koreader.username, { message: 'Choose a sync username' });
@@ -47,20 +47,8 @@
@if (syncForm.controls.syncEnabled.value) {
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<span class="setting-label">{{ t('kobo.twoWaySyncLabel') }}</span>
<p-toggle-switch
inputId="koboTwoWayProgressSync"
formControlName="twoWayProgressSync"
(onChange)="onTwoWaySyncToggle($event.checked)">
</p-toggle-switch>
</div>
<p class="setting-description">
{{ t('kobo.twoWaySyncDesc') }}
<br>
<strong>{{ t('kobo.twoWaySyncNote') }}</strong>
</p>
@if (syncForm.controls.twoWayProgressSync.value && !koboSettings.convertToKepub) {
@if (!koboSettings.convertToKepub) {
<p class="setting-warning border-l-red-700 dark:border-l-red-300" role="status" aria-live="polite" aria-atomic="true">
<i class="pi pi-exclamation-triangle text-red-700 dark:text-red-300" aria-hidden="true"></i>
@if (isAdmin) {
@@ -20,7 +20,6 @@ const DEFAULT_KOBO_SYNC_SETTINGS: KoboSyncSettings = {
progressMarkAsReadingThreshold: 1,
progressMarkAsFinishedThreshold: 99,
autoAddToShelf: false,
twoWayProgressSync: false,
};
const DEFAULT_KOBO_ADMIN_SETTINGS: KoboSettings = {
@@ -158,7 +157,6 @@ describe('KoboSyncSettingsComponent', () => {
progressMarkAsReadingThreshold: 1,
progressMarkAsFinishedThreshold: 99,
autoAddToShelf: false,
twoWayProgressSync: false,
};
setupKoboTest({
@@ -179,19 +177,18 @@ describe('KoboSyncSettingsComponent', () => {
component.onAutoAddToggle(true);
// Before the response arrives, the user edits a different control.
component.syncForm.controls.twoWayProgressSync.setValue(true);
component.syncForm.controls.twoWayProgressSync.markAsDirty();
component.syncForm.controls.progressMarkAsFinishedThreshold.setValue(4);
component.syncForm.controls.progressMarkAsFinishedThreshold.markAsDirty();
// Server confirms the autoAddToShelf change but still has the old twoWayProgressSync.
// Server confirms the autoAddToShelf change
updateSettings$.next({
...initialSettings,
autoAddToShelf: true,
twoWayProgressSync: false,
});
// The newer in-flight edit must not be reverted.
expect(component.syncForm.controls.twoWayProgressSync.value).toBe(true);
expect(component.syncForm.controls.twoWayProgressSync.dirty).toBe(true);
expect(component.syncForm.controls.progressMarkAsFinishedThreshold.value).toBe(4);
expect(component.syncForm.controls.progressMarkAsFinishedThreshold.dirty).toBe(true);
expect(component.syncForm.controls.autoAddToShelf.value).toBe(true);
expect(component.syncForm.controls.autoAddToShelf.pristine).toBe(true);
@@ -224,7 +221,6 @@ describe('KoboSyncSettingsComponent', () => {
progressMarkAsReadingThreshold: 2,
progressMarkAsFinishedThreshold: 95,
autoAddToShelf: true,
twoWayProgressSync: true,
});
fixture.detectChanges();
await fixture.whenStable();
@@ -240,7 +236,6 @@ describe('KoboSyncSettingsComponent', () => {
progressMarkAsReadingThreshold: 2,
progressMarkAsFinishedThreshold: 95,
autoAddToShelf: true,
twoWayProgressSync: true,
});
expect(fixture.nativeElement.querySelector('input#koboToken')).not.toBeNull();
@@ -60,7 +60,6 @@ export class KoboSyncSettingsComponent implements OnInit {
progressMarkAsReadingThreshold: [1],
progressMarkAsFinishedThreshold: [99],
autoAddToShelf: [true],
twoWayProgressSync: [false],
});
koboSettings: KoboSettings = {
@@ -157,7 +156,6 @@ export class KoboSyncSettingsComponent implements OnInit {
progressMarkAsReadingThreshold: settings.progressMarkAsReadingThreshold ?? 1,
progressMarkAsFinishedThreshold: settings.progressMarkAsFinishedThreshold ?? 99,
autoAddToShelf: settings.autoAddToShelf ?? true,
twoWayProgressSync: settings.twoWayProgressSync ?? false,
};
for (const [key, value] of Object.entries(next)) {
@@ -267,13 +265,6 @@ export class KoboSyncSettingsComponent implements OnInit {
this.updateKoboSettings(message);
}
onTwoWaySyncToggle(checked: boolean) {
const message = checked
? this.t.translate('settingsDevice.kobo.twoWaySyncEnabled')
: this.t.translate('settingsDevice.kobo.twoWaySyncDisabled');
this.updateKoboSettings(message);
}
private updateKoboSettings(successMessage: string) {
const submitted = this.buildKoboUserSettings();
this.koboService.updateSettings(submitted).pipe(
@@ -41,14 +41,12 @@ describe('KoboService', () => {
token: 'abc123',
syncEnabled: true,
autoAddToShelf: false,
twoWayProgressSync: true,
});
expect(responseBody).toEqual({
token: 'abc123',
syncEnabled: true,
autoAddToShelf: false,
twoWayProgressSync: true,
});
});
@@ -63,7 +61,6 @@ describe('KoboService', () => {
token: 'new-token',
syncEnabled: false,
autoAddToShelf: true,
twoWayProgressSync: false,
});
});
@@ -72,7 +69,6 @@ describe('KoboService', () => {
token: 'abc123',
syncEnabled: true,
autoAddToShelf: true,
twoWayProgressSync: false,
progressMarkAsReadingThreshold: 25,
progressMarkAsFinishedThreshold: 95,
};
@@ -9,7 +9,6 @@ export interface KoboSyncSettings {
progressMarkAsReadingThreshold?: number;
progressMarkAsFinishedThreshold?: number;
autoAddToShelf: boolean;
twoWayProgressSync: boolean;
hardcoverApiKey?: string;
hardcoverSyncEnabled?: boolean;
}
@@ -46,23 +46,6 @@
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<span class="setting-label">{{ t('koreader.syncWithGrimmory') }}</span>
<p-toggle-switch
name="syncWithWebReader"
[ngModel]="syncWithWebReader()"
(ngModelChange)="onToggleSyncWithWebReader($event)"
inputId="syncWithWebReader"
[disabled]="!credentialsSaved() || !koReaderSyncEnabled()">
</p-toggle-switch>
</div>
<p class="setting-description" [innerHTML]="t('koreader.syncWithGrimmoryDesc')">
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
@@ -33,7 +33,6 @@ export class KoreaderSettingsComponent {
editMode = signal(true);
showPassword = signal(false);
koReaderSyncEnabled = signal(false);
syncWithWebReader = signal(false);
koReaderUsername = signal('');
koReaderPassword = signal('');
credentialsSaved = signal(false);
@@ -75,7 +74,6 @@ export class KoreaderSettingsComponent {
this.koReaderUsername.set(koreaderUser.username);
this.koReaderPassword.set(koreaderUser.password);
this.koReaderSyncEnabled.set(koreaderUser.syncEnabled);
this.syncWithWebReader.set(koreaderUser.syncWithWebReader ?? false);
this.credentialsSaved.set(true);
},
error: err => {
@@ -115,31 +113,6 @@ export class KoreaderSettingsComponent {
});
}
onToggleSyncWithWebReader(enabled: boolean) {
const previousSyncWithWebReader = this.syncWithWebReader();
this.syncWithWebReader.set(enabled);
this.koreaderService.toggleSyncProgressWithWebReader(enabled).pipe(
takeUntilDestroyed(this.destroyRef)
).subscribe({
next: () => {
this.syncWithWebReader.set(enabled);
this.messageService.add({
severity: 'success',
summary: this.t.translate('settingsDevice.koreader.syncUpdated'),
detail: enabled ? this.t.translate('settingsDevice.koreader.grimmoryReaderEnabled') : this.t.translate('settingsDevice.koreader.grimmoryReaderDisabled')
});
},
error: () => {
this.syncWithWebReader.set(previousSyncWithWebReader);
this.messageService.add({
severity: 'error',
summary: this.t.translate('settingsDevice.koreader.syncUpdateFailed'),
detail: this.t.translate('settingsDevice.koreader.grimmoryReaderError')
});
}
});
}
toggleShowPassword() {
this.showPassword.update(showPassword => !showPassword);
}
@@ -69,14 +69,12 @@ describe('KoreaderService', () => {
username: 'reader',
password: 'secret123',
syncEnabled: false,
syncWithWebReader: true,
});
expect(responseBody).toEqual({
username: 'reader',
password: 'secret123',
syncEnabled: false,
syncWithWebReader: true,
});
});
@@ -8,7 +8,6 @@ export interface KoreaderUser {
username: string;
password: string;
syncEnabled: boolean;
syncWithWebReader?: boolean;
}
@Injectable({
-5
View File
@@ -1370,8 +1370,6 @@
"syncConfigDesc": "Enable and configure synchronization between your Grimmory library and KOReader device.",
"enableSync": "Enable KOReader Sync",
"enableSyncDesc": "Turn on synchronization to automatically sync your reading progress.",
"syncWithGrimmory": "Sync reading progress with Grimmory eBook Reader",
"syncWithGrimmoryDesc": "Enable bidirectional sync between Grimmory's eBook reader and KOReader. <strong>Note:</strong> Progress sync is approximate and may update by chapter rather than exact page or location.",
"apiPath": "KOReader API Path",
"apiPathDesc": "The API endpoint path for your KOReader sync service.",
"username": "KOReader Username",
@@ -1454,9 +1452,6 @@
"syncEnabled": "Kobo sync enabled",
"syncDisabled": "Kobo sync disabled",
"progressUpdated": "Progress thresholds updated successfully",
"twoWaySyncLabel": "Two-Way Reading Progress Sync",
"twoWaySyncDesc": "Enable bidirectional sync between Grimmory's web reader and your Kobo device. Reading progress made on either platform will be reflected on the other.",
"twoWaySyncNote": "Note: Due to different position formats, sync accuracy is best-effort. In most cases progress will be accurate to the chapter level.",
"twoWaySyncKepubWarning": "KEPUB conversion is currently disabled. Two-way progress sync requires KEPUB conversion to be enabled by an administrator.",
"twoWaySyncKepubWarningAdmin": "KEPUB conversion is currently disabled. Enable it in the Administrator Settings below for two-way progress sync to work.",
"twoWaySyncEnabled": "Two-way progress sync enabled",