Feature: Sync reading progress from Kobo in-built reader (#1541)

* feat: add kobo reading progress sync

* fix: remove old variable references

* fix: avoid changing koreader behaviour

* fix: resolve typo in koreader progress

* fix: remove link between booklore progress and kobo sync progress

* feat: add unit tests for kobo reading status sync

* fix: remove unnecessary conversion value for kobo progress

* fix: resolve issue with kobo_progress beiong optional in template

* fix: update entitlement to provide existing reading progress back to kobo on sync

* fix: use stored bookmark before creating new bookmark

* fix: update default thresholds to full numbers. kobo doesn't report progress with any decimal places

* chore: update unit tests

* fix: remove decimal places in kobo settings progress threshold
This commit is contained in:
CounterClops
2025-11-21 00:17:57 -07:00
committed by GitHub
parent 9eb0dabd5e
commit 7ebdc7b106
20 changed files with 937 additions and 9 deletions
@@ -100,6 +100,54 @@
</p-button>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Mark as Reading at: {{ koboSyncSettings.progressMarkAsReadingThreshold?.toFixed(0) }}%</label>
<div class="slider-container">
<p-slider
id="markAsReadingThreshold"
name="markAsReadingThreshold"
[(ngModel)]="koboSyncSettings.progressMarkAsReadingThreshold"
[min]="1"
[max]="10"
[step]="1"
(ngModelChange)="onProgressThresholdsChange()">
</p-slider>
</div>
</div>
<p class="setting-description">
Books are marked as "Reading" when progress exceeds this percentage. This helps automatically track which books you've started.
<br>
<strong>Recommended:</strong> 1% (default) - marks as reading after the first page or two.
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">Mark as Finished at: {{ koboSyncSettings.progressMarkAsFinishedThreshold?.toFixed(0) }}%</label>
<div class="slider-container">
<p-slider
id="markAsFinishedThreshold"
name="markAsFinishedThreshold"
[(ngModel)]="koboSyncSettings.progressMarkAsFinishedThreshold"
[min]="90"
[max]="100"
[step]="1"
(ngModelChange)="onProgressThresholdsChange()">
</p-slider>
</div>
</div>
<p class="setting-description">
Books are marked as "Finished" when progress reaches this percentage. Accounts for books where the last few pages are acknowledgments or index.
<br>
<strong>Recommended:</strong> 99% (default) - marks as finished when nearly complete.
</p>
</div>
</div>
}
</form>
</div>
@@ -50,7 +50,9 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
koboSyncSettings: KoboSyncSettings = {
token: '',
syncEnabled: false
syncEnabled: false,
progressMarkAsReadingThreshold: 1,
progressMarkAsFinishedThreshold: 99
}
ngOnInit() {
@@ -101,6 +103,8 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
next: (settings: KoboSyncSettings) => {
this.koboSyncSettings.token = settings.token;
this.koboSyncSettings.syncEnabled = settings.syncEnabled;
this.koboSyncSettings.progressMarkAsReadingThreshold = settings.progressMarkAsReadingThreshold ?? 1;
this.koboSyncSettings.progressMarkAsFinishedThreshold = settings.progressMarkAsFinishedThreshold ?? 99;
this.credentialsSaved = !!settings.token;
},
error: () => {
@@ -198,6 +202,28 @@ export class KoboSyncSettingsComponent implements OnInit, OnDestroy {
});
}
onProgressThresholdsChange() {
this.koboService.updateProgressThresholds(
this.koboSyncSettings.progressMarkAsReadingThreshold,
this.koboSyncSettings.progressMarkAsFinishedThreshold
).subscribe({
next: () => {
this.messageService.add({
severity: 'success',
summary: 'Thresholds Updated',
detail: 'Progress thresholds updated successfully'
});
},
error: () => {
this.messageService.add({
severity: 'error',
summary: 'Error',
detail: 'Failed to update progress thresholds'
});
}
});
}
saveSettings() {
this.settingsHelperService.saveSetting(AppSettingKey.KOBO_SETTINGS, this.koboSettings)
.subscribe({
@@ -6,6 +6,8 @@ import {API_CONFIG} from '../../../../../core/config/api-config';
export interface KoboSyncSettings {
token: string;
syncEnabled: boolean;
progressMarkAsReadingThreshold?: number;
progressMarkAsFinishedThreshold?: number;
}
@Injectable({
@@ -27,4 +29,15 @@ export class KoboService {
const params = new HttpParams().set('enabled', enabled.toString());
return this.http.put<void>(`${this.baseUrl}/sync`, null, { params });
}
updateProgressThresholds(readingThreshold?: number, finishedThreshold?: number): Observable<KoboSyncSettings> {
let params = new HttpParams();
if (readingThreshold !== undefined && readingThreshold !== null) {
params = params.set('readingThreshold', readingThreshold.toString());
}
if (finishedThreshold !== undefined && finishedThreshold !== null) {
params = params.set('finishedThreshold', finishedThreshold.toString());
}
return this.http.put<KoboSyncSettings>(`${this.baseUrl}/progress-thresholds`, null, { params });
}
}