Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wake Lock #2444

Merged
merged 4 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion API/Services/Tasks/Scanner/ParseScannedFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public async Task ProcessFiles(string folderPath, bool scanDirectoryByDirectory,
if (library.LibraryExcludePatterns.Count != 0)
{
matcher ??= new GlobMatcher();
foreach (var pattern in library.LibraryExcludePatterns)
foreach (var pattern in library.LibraryExcludePatterns.Where(p => !string.IsNullOrEmpty(p.Pattern)))
{

matcher.AddExclude(pattern.Pattern);
}
}
Expand Down
809 changes: 277 additions & 532 deletions UI/Web/package-lock.json

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions UI/Web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
},
"private": true,
"dependencies": {
"@angular/animations": "^17.0.2",
"@angular/cdk": "^17.0.0",
"@angular/common": "^17.0.2",
"@angular/compiler": "^17.0.2",
"@angular/core": "^17.0.2",
"@angular/forms": "^17.0.2",
"@angular/localize": "^17.0.2",
"@angular/platform-browser": "^17.0.2",
"@angular/platform-browser-dynamic": "^17.0.2",
"@angular/router": "^17.0.2",
"@angular/animations": "^17.0.3",
"@angular/cdk": "^17.0.1",
"@angular/common": "^17.0.3",
"@angular/compiler": "^17.0.3",
"@angular/core": "^17.0.3",
"@angular/forms": "^17.0.3",
"@angular/localize": "^17.0.3",
"@angular/platform-browser": "^17.0.3",
"@angular/platform-browser-dynamic": "^17.0.3",
"@angular/router": "^17.0.3",
"@fortawesome/fontawesome-free": "^6.4.2",
"@iharbeck/ngx-virtual-scroller": "^16.0.0",
"@iplab/ngx-file-upload": "^16.0.2",
"@iharbeck/ngx-virtual-scroller": "^17.0.0",
"@iplab/ngx-file-upload": "^17.0.0",
"@microsoft/signalr": "^7.0.12",
"@ng-bootstrap/ng-bootstrap": "^15.1.2",
"@ngneat/transloco": "^6.0.0",
Expand All @@ -46,35 +46,36 @@
"ngx-color-picker": "^15.0.0",
"ngx-extended-pdf-viewer": "^18.1.6",
"ngx-file-drop": "^16.0.0",
"ngx-slider-v2": "^16.0.2",
"ngx-slider-v2": "^17.0.0",
"ngx-stars": "^1.6.5",
"ngx-toastr": "^17.0.2",
"nosleep.js": "^0.12.0",
"rxjs": "^7.8.0",
"screenfull": "^6.0.2",
"swiper": "^8.4.6",
"tslib": "^2.6.2",
"zone.js": "^0.14.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^17.0.0",
"@angular-eslint/builder": "^17.0.1",
"@angular-eslint/eslint-plugin": "^17.0.0",
"@angular-eslint/eslint-plugin-template": "^17.0.0",
"@angular-eslint/schematics": "^17.0.1",
"@angular-eslint/template-parser": "^17.0.1",
"@angular/cli": "^17.0.0",
"@angular/compiler-cli": "^17.0.2",
"@angular-devkit/build-angular": "^17.0.1",
"@angular-eslint/builder": "^17.1.0",
"@angular-eslint/eslint-plugin": "^17.1.0",
"@angular-eslint/eslint-plugin-template": "^17.1.0",
"@angular-eslint/schematics": "^17.1.0",
"@angular-eslint/template-parser": "^17.1.0",
"@angular/cli": "^17.0.1",
"@angular/compiler-cli": "^17.0.3",
"@types/d3": "^7.4.3",
"@types/file-saver": "^2.0.7",
"@types/luxon": "^3.3.4",
"@types/node": "^20.9.0",
"@types/node": "^20.9.2",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.53.0",
"eslint": "^8.54.0",
"jsonminify": "^0.4.2",
"karma-coverage": "~2.2.0",
"ts-node": "~10.9.1",
"typescript": "^5.2.2",
"webpack-bundle-analyzer": "^4.9.1"
"webpack-bundle-analyzer": "^4.10.1"
}
}
6 changes: 3 additions & 3 deletions UI/Web/src/app/_services/member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class MemberService {
return this.httpClient.get<boolean>(this.baseUrl + 'users/has-library-access?libraryId=' + libraryId);
}

hasReadingProgress(librayId: number) {
return this.httpClient.get<boolean>(this.baseUrl + 'users/has-reading-progress?libraryId=' + librayId);
hasReadingProgress(libraryId: number) {
return this.httpClient.get<boolean>(this.baseUrl + 'users/has-reading-progress?libraryId=' + libraryId);
}

addSeriesToWantToRead(seriesIds: Array<number>) {
Expand All @@ -47,5 +47,5 @@ export class MemberService {
getMember() {
return this.httpClient.get<Member>(this.baseUrl + 'users/myself');
}

}
38 changes: 32 additions & 6 deletions UI/Web/src/app/_services/reader.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import {DestroyRef, inject, Injectable} from '@angular/core';
import {Location} from '@angular/common';
import {DestroyRef, Inject, inject, Injectable} from '@angular/core';
import {DOCUMENT, Location} from '@angular/common';
import { Router } from '@angular/router';
import { environment } from 'src/environments/environment';
import { ChapterInfo } from '../manga-reader/_models/chapter-info';
Expand All @@ -10,15 +10,15 @@ import { MangaFormat } from '../_models/manga-format';
import { BookmarkInfo } from '../_models/manga-reader/bookmark-info';
import { PageBookmark } from '../_models/readers/page-bookmark';
import { ProgressBookmark } from '../_models/readers/progress-bookmark';
import { UtilityService } from '../shared/_services/utility.service';
import { FilterUtilitiesService } from '../shared/_services/filter-utilities.service';
import { FileDimension } from '../manga-reader/_models/file-dimension';
import screenfull from 'screenfull';
import { TextResonse } from '../_types/text-response';
import { AccountService } from './account.service';
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {PersonalToC} from "../_models/readers/personal-toc";
import {SeriesFilterV2} from "../_models/metadata/v2/series-filter-v2";
import NoSleep from 'nosleep.js';


export const CHAPTER_ID_DOESNT_EXIST = -1;
export const CHAPTER_ID_NOT_FETCHED = -2;
Expand All @@ -35,16 +35,42 @@ export class ReaderService {
// Override background color for reader and restore it onDestroy
private originalBodyColor!: string;

private noSleep = new NoSleep();

constructor(private httpClient: HttpClient, private router: Router,
private location: Location, private utilityService: UtilityService,
private filterUtilityService: FilterUtilitiesService, private accountService: AccountService) {
private location: Location, private accountService: AccountService,
@Inject(DOCUMENT) private document: Document) {
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
if (user) {
this.encodedKey = encodeURIComponent(user.apiKey);
}
});
}

enableWakeLock(element?: Element | Document) {
// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)

if (!element) element = this.document;

const enableNoSleepHandler = () => {
element!.removeEventListener('click', enableNoSleepHandler, false);
element!.removeEventListener('touchmove', enableNoSleepHandler, false);
element!.removeEventListener('mousemove', enableNoSleepHandler, false);
this.noSleep!.enable();
};

// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
element.addEventListener('click', enableNoSleepHandler, false);
element.addEventListener('touchmove', enableNoSleepHandler, false);
element.addEventListener('mousemove', enableNoSleepHandler, false);
}

disableWakeLock() {
this.noSleep.disable();
}


getNavigationArray(libraryId: number, seriesId: number, chapterId: number, format: MangaFormat) {
if (format === undefined) format = MangaFormat.ARCHIVE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
this.clearTimeout(this.clickToPaginateVisualOverlayTimeout);
this.clearTimeout(this.clickToPaginateVisualOverlayTimeout2);

this.readerService.disableWakeLock();

this.themeService.clearBookTheme();

this.themeService.currentTheme$.pipe(take(1)).subscribe(theme => {
Expand Down Expand Up @@ -679,6 +681,7 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {

// Check if user progress has part, if so load it so we scroll to it
this.loadPage(results.progress.bookScrollId || undefined);
this.readerService.enableWakeLock(this.reader.nativeElement);
}, () => {
setTimeout(() => {
this.closeReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,26 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild(DoubleRendererComponent, { static: false }) doubleRenderer!: DoubleRendererComponent;
@ViewChild(DoubleReverseRendererComponent, { static: false }) doubleReverseRenderer!: DoubleReverseRendererComponent;
@ViewChild(DoubleNoCoverRendererComponent, { static: false }) doubleNoCoverRenderer!: DoubleNoCoverRendererComponent;

private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly accountService = inject(AccountService);
private readonly formBuilder = inject(FormBuilder);
private readonly navService = inject(NavService);
private readonly memberService = inject(MemberService);
private readonly modalService = inject(NgbModal);
private readonly cdRef = inject(ChangeDetectorRef);
private readonly toastr = inject(ToastrService);
public readonly readerService = inject(ReaderService);
public readonly utilityService = inject(UtilityService);
public readonly mangaReaderService = inject(ManagaReaderService);

protected readonly KeyDirection = KeyDirection;
protected readonly ReaderMode = ReaderMode;
protected readonly LayoutMode = LayoutMode;
protected readonly ReadingDirection = ReadingDirection;
protected readonly Breakpoint = Breakpoint;

libraryId!: number;
seriesId!: number;
Expand Down Expand Up @@ -207,12 +226,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
*/
canvasImage = new Image();

/**
* Dictates if we use render with canvas or with image.
* @remarks This is only for Splitting.
*/
//renderWithCanvas: boolean = false;

/**
* A circular array of size PREFETCH_PAGES. Maintains prefetched Images around the current page to load from to avoid loading animation.
* @see CircularArray
Expand Down Expand Up @@ -440,12 +453,6 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
return 'right-side';
}


get KeyDirection() { return KeyDirection; }
get ReaderMode() { return ReaderMode; }
get LayoutMode() { return LayoutMode; }
get ReadingDirection() { return ReadingDirection; }
get Breakpoint() { return Breakpoint; }
get FittingOption() { return this.generalSettingsForm?.get('fittingOption')?.value || FITTING_OPTION.HEIGHT; }
get ReadingAreaWidth() {
return this.readingArea?.nativeElement.scrollWidth - this.readingArea?.nativeElement.clientWidth;
Expand All @@ -455,12 +462,8 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
return this.readingArea?.nativeElement.scrollHeight - this.readingArea?.nativeElement.clientHeight;
}

constructor(private route: ActivatedRoute, private router: Router, private accountService: AccountService,
public readerService: ReaderService, private formBuilder: FormBuilder, private navService: NavService,
private toastr: ToastrService, private memberService: MemberService,
public utilityService: UtilityService, @Inject(DOCUMENT) private document: Document,
private modalService: NgbModal, private readonly cdRef: ChangeDetectorRef,
public mangaReaderService: ManagaReaderService) {

constructor(@Inject(DOCUMENT) private document: Document) {
this.navService.hideNavBar();
this.navService.hideSideNav();
this.cdRef.markForCheck();
Expand All @@ -476,6 +479,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
}

this.getPageFn = this.getPage.bind(this);
this.readerService.enableWakeLock(this.reader.nativeElement);

this.libraryId = parseInt(libraryId, 10);
this.seriesId = parseInt(seriesId, 10);
Expand Down Expand Up @@ -633,6 +637,7 @@ export class MangaReaderComponent implements OnInit, AfterViewInit, OnDestroy {
this.navService.showSideNav();
this.showBookmarkEffectEvent.complete();
if (this.goToPageEvent !== undefined) this.goToPageEvent.complete();
this.readerService.disableWakeLock();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ export class NavHeaderComponent implements OnInit {
}

goToOther(field: FilterField, value: string) {
this.goTo({field, comparison: FilterComparison.Equal, value});
this.goTo({field, comparison: FilterComparison.Equal, value: value + ''});
}

goToPerson(role: PersonRole, filter: any) {
this.clearSearch();
filter = filter + '';
switch(role) {
case PersonRole.Writer:
this.goTo({field: FilterField.Writers, comparison: FilterComparison.Equal, value: filter});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-container *transloco="let t; read: 'pdf-reader'">
<div class="{{theme}}" *ngIf="accountService.currentUser$ | async as user">
<div class="{{theme}}" *ngIf="accountService.currentUser$ | async as user" #container>

<ng-container *ngIf="isLoading">
<div class="loading mx-auto" style="min-width: 200px; width: 600px;">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Component, ElementRef,
HostListener,
inject, OnDestroy,
OnInit
OnInit, ViewChild
} from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { NgxExtendedPdfViewerService, PageViewModeType, ProgressBarEvent, NgxExtendedPdfViewerModule } from 'ngx-extended-pdf-viewer';
Expand Down Expand Up @@ -33,6 +33,8 @@ import {translate, TranslocoDirective} from "@ngneat/transloco";
})
export class PdfReaderComponent implements OnInit, OnDestroy {

@ViewChild('container') container!: ElementRef;

libraryId!: number;
seriesId!: number;
volumeId!: number;
Expand Down Expand Up @@ -111,6 +113,7 @@ export class PdfReaderComponent implements OnInit, OnDestroy {

this.navService.showNavBar();
this.navService.showSideNav();
this.readerService.disableWakeLock();
}

ngOnInit(): void {
Expand Down Expand Up @@ -166,7 +169,7 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
}
this.cdRef.markForCheck();
});

this.readerService.enableWakeLock(this.container.nativeElement);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "GPL-3.0",
"url": "https://github.com/Kareadita/Kavita/blob/develop/LICENSE"
},
"version": "0.7.10.13"
"version": "0.7.10.15"
},
"servers": [
{
Expand Down
Loading