Skip to content

Commit c8cc5f2

Browse files
committed
added homepage sections
1 parent 734fc78 commit c8cc5f2

File tree

8 files changed

+452
-27
lines changed

8 files changed

+452
-27
lines changed

src/Komga/Komga.ts

Lines changed: 327 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {
2+
Form,
3+
Section,
4+
ToggleRow,
5+
type FormSectionElement,
6+
} from '@paperback/types'
7+
import {
8+
getShowContinueReading,
9+
getShowOnDeck,
10+
setShowContinueReading,
11+
setShowOnDeck,
12+
} from '../utils/config.js'
13+
14+
export class HomepageSettingsForm extends Form {
15+
override getSections(): FormSectionElement[] {
16+
return [this.staticHomepageSection()]
17+
}
18+
19+
staticHomepageSection(): FormSectionElement {
20+
return Section(
21+
{ id: 'staticHomepageSection', header: 'Static Hompage Sections' },
22+
[
23+
ToggleRow('showOnDeck', {
24+
title: 'On Deck',
25+
value: getShowOnDeck(),
26+
onValueChange: Application.Selector(
27+
this as HomepageSettingsForm,
28+
'showOnDeckDidChange'
29+
),
30+
}),
31+
ToggleRow('showContinueReading', {
32+
title: 'Continue Reading',
33+
value: getShowContinueReading(),
34+
onValueChange: Application.Selector(
35+
this as HomepageSettingsForm,
36+
'showContinueReadingDidChange'
37+
),
38+
}),
39+
]
40+
)
41+
}
42+
43+
async showOnDeckDidChange(newValue: boolean): Promise<void> {
44+
setShowOnDeck(newValue)
45+
Application.invalidateDiscoverSections()
46+
}
47+
48+
async showContinueReadingDidChange(newValue: boolean): Promise<void> {
49+
setShowContinueReading(newValue)
50+
Application.invalidateDiscoverSections()
51+
}
52+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '../utils/config.js'
1313
import { getCurrentUser } from '../sdk/sdk.gen.js'
1414

15-
export class AuthenticationForm extends Form {
15+
export class ServerSettingsForm extends Form {
1616
baseUrl = getKomgaBaseURL()
1717
credentials = getKomgaCredentials()
1818

@@ -28,7 +28,7 @@ export class AuthenticationForm extends Form {
2828
title: 'Base URL',
2929
value: this.baseUrl,
3030
onValueChange: Application.Selector(
31-
this as AuthenticationForm,
31+
this as ServerSettingsForm,
3232
'baseUrlDidChange'
3333
),
3434
}),
@@ -55,15 +55,15 @@ export class AuthenticationForm extends Form {
5555
title: 'Username',
5656
value: this.credentials.username,
5757
onValueChange: Application.Selector(
58-
this as AuthenticationForm,
58+
this as ServerSettingsForm,
5959
'usernameDidChange'
6060
),
6161
}),
6262
InputRow('password', {
6363
title: 'Password',
6464
value: this.credentials.password,
6565
onValueChange: Application.Selector(
66-
this as AuthenticationForm,
66+
this as ServerSettingsForm,
6767
'passwordDidChange'
6868
),
6969
}),

src/Komga/forms/settings_form.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import { Form, NavigationRow, Section, type FormSectionElement } from '@paperback/types'
2-
import { AuthenticationForm } from './authentication_form.js'
2+
import { ServerSettingsForm } from './server_settings_form.js'
3+
import { HomepageSettingsForm } from './homepage_settings_form.js'
34

45
export class SettingsForm extends Form {
56
override getSections(): FormSectionElement[] {
67
return [
78
Section('authentication', [
89
NavigationRow('authentication', {
9-
title: 'Authenciation',
10-
form: new AuthenticationForm(),
11-
}),
10+
title: 'Server Settings',
11+
form: new ServerSettingsForm(),
12+
}),
13+
]),
14+
15+
Section('homepageSettings', [
16+
NavigationRow('authentication', {
17+
title: 'Homepage Settings',
18+
form: new HomepageSettingsForm(),
19+
}),
1220
]),
1321
]
1422
}

src/Komga/interceptors/image_interceptor.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import { PaperbackInterceptor, type Request, type Response } from '@paperback/types'
1+
import {
2+
PaperbackInterceptor,
3+
type Request,
4+
type Response,
5+
} from '@paperback/types'
26
import { getKomgaCredentials } from '../utils/config.js'
37

4-
58
export class KomgaImageInterceptor extends PaperbackInterceptor {
69
override async interceptRequest(request: Request): Promise<Request> {
7-
if (!request.url.includes('thumbnail')) {
8-
return request
9-
}
10+
console.log(request.url)
11+
12+
// if (!request.url.includes('thumbnail')) {
13+
// return request
14+
// }
1015

1116
const { username, password } = getKomgaCredentials()
1217
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1318
request.headers!['Authorization'] =
1419
'Basic ' + btoa(`${username}:${password}`)
1520

21+
console.log(request.headers!['Authorization'])
22+
1623
return request
1724
}
1825

src/Komga/pbconfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ export default {
3131
SourceIntents.SEARCH_RESULTS_PROVIDING,
3232
SourceIntents.CHAPTER_PROVIDING,
3333
SourceIntents.SETTINGS_FORM_PROVIDING,
34+
SourceIntents.DISCOVER_SECIONS_PROVIDING
3435
],
3536
} satisfies ExtensionInfo

src/Komga/utils.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
import type { Is, IsFalse, IsNot, IsTrue } from './sdk/types.gen.js'
2+
13
export function Operator<T extends string, V>(
24
o: { operator: Uncapitalize<T> } & V
35
): { operator: T } & V {
46
return o as { operator: T } & V
57
}
8+
9+
export function isTrue(): IsTrue {
10+
return Operator({ operator: 'isTrue' })
11+
}
12+
13+
export function isFalse(): IsFalse {
14+
return Operator({ operator: 'isFalse' })
15+
}
16+
17+
export function isEqualTo<T>(value: T): Is {
18+
return Operator({ operator: 'is', value: value })
19+
}
20+
21+
export function isNotEqualTo<T>(value: T): IsNot {
22+
return Operator({ operator: 'isNot', value: value })
23+
}

src/Komga/utils/config.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
const KEY_KOMGA_BASE_URL = 'serverURL'
22
const KEY_KOMGA_USERNAME = 'serverUsername'
33
const KEY_KOMGA_PASSWORD = 'serverPassword'
4+
const KEY_SHOW_ON_DECK = 'showOnDeck'
5+
const KEY_SHOW_CONTINUE_READING = 'showContinueReading'
46

57
const DEFAULT_KOMGA_BASE_URL = 'https://demo.komga.org'
68
const DEFAULT_KOMGA_USERNAME = '[email protected]'
79
const DEFAULT_KOMGA_PASSWORD = 'komga-demo'
10+
const DEFAULT_SHOW_ON_DECK = true
11+
const DEFAULT_SHOW_CONTINUE_READING = true
12+
13+
function getStateOrDefault<T>(key: string, def: T): T {
14+
return Application.getState(key) as T ?? def
15+
}
816

917
export function getKomgaBaseURL() {
10-
return Application.getState(KEY_KOMGA_BASE_URL) as string ?? DEFAULT_KOMGA_BASE_URL
18+
return getStateOrDefault(KEY_KOMGA_BASE_URL, DEFAULT_KOMGA_BASE_URL)
1119
}
1220

1321
export function setKomgaBaseURL(url: string) {
@@ -25,3 +33,20 @@ export function setKomgaCredentials(username: string, password: string) {
2533
Application.setSecureState(username, KEY_KOMGA_USERNAME)
2634
Application.setSecureState(password, KEY_KOMGA_PASSWORD)
2735
}
36+
37+
38+
export function getShowOnDeck() {
39+
return getStateOrDefault(KEY_SHOW_ON_DECK, DEFAULT_SHOW_ON_DECK)
40+
}
41+
42+
export function setShowOnDeck(newValue: boolean) {
43+
Application.setState(newValue, KEY_SHOW_ON_DECK)
44+
}
45+
46+
export function getShowContinueReading() {
47+
return getStateOrDefault(KEY_SHOW_CONTINUE_READING, DEFAULT_SHOW_CONTINUE_READING)
48+
}
49+
50+
export function setShowContinueReading(newValue: boolean) {
51+
Application.setState(newValue, KEY_SHOW_CONTINUE_READING)
52+
}

0 commit comments

Comments
 (0)