Skip to content

Commit c22860b

Browse files
committed
fix: #420 internal epub font; chore: comment clean
1 parent a5af6d7 commit c22860b

14 files changed

Lines changed: 33 additions & 58 deletions

File tree

src/common/types/legacy.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type BookItem = {
2323
title: string;
2424
author: string;
2525
link: string;
26-
//todo impl
2726
cover: string;
2827
date?: string;
2928
chapterData?: {

src/electron/db/index.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ import { libraryItems, mangaProgress, bookProgress, mangaBookmarks, bookBookmark
99
import { HistoryItem, Manga_BookItem } from "@common/types/legacy";
1010
import Database from "better-sqlite3";
1111
import { dateFromOldDateString, electronOnly, log } from "../util";
12-
import { AddToLibraryData, UpdateBookProgressData, UpdateMangaProgressData } from "@common/types/db";
12+
import {
13+
AddToLibraryData,
14+
BookProgress,
15+
LibraryItem,
16+
MangaProgress,
17+
UpdateBookProgressData,
18+
UpdateMangaProgressData,
19+
} from "@common/types/db";
1320

1421
electronOnly();
15-
// todo : add proper error handling
1622

1723
export const DB_PATH = app.isPackaged ? path.join(app.getPath("userData"), "data.db") : "data.db";
1824

@@ -23,17 +29,17 @@ export class DatabaseService {
2329
this._db = drizzle({ client: sqlite, schema });
2430
}
2531

26-
get db() {
32+
get db(): ReturnType<typeof drizzle> {
2733
return this._db;
2834
}
29-
async initialize() {
35+
async initialize(): Promise<void> {
3036
console.log("Migrating database");
31-
migrate(this._db, {
37+
await migrate(this._db, {
3238
migrationsFolder: app.isPackaged ? path.join(path.dirname(app.getAppPath()), "drizzle") : "drizzle",
3339
});
3440
console.log(this._db.all(`select unixepoch() as time`));
3541
}
36-
async addLibraryItem(data: AddToLibraryData) {
42+
async addLibraryItem(data: AddToLibraryData): Promise<LibraryItem> {
3743
return await this._db.transaction(async (tx) => {
3844
const [item] = await tx.insert(libraryItems).values(data.data).returning();
3945
if (data.type === "manga") {
@@ -54,7 +60,7 @@ export class DatabaseService {
5460
});
5561
}
5662

57-
async updateMangaProgress(data: UpdateMangaProgressData) {
63+
async updateMangaProgress(data: UpdateMangaProgressData): Promise<MangaProgress[]> {
5864
const { itemLink, ...updateData } = data;
5965
return await this._db
6066
.update(mangaProgress)
@@ -66,7 +72,7 @@ export class DatabaseService {
6672
.returning();
6773
}
6874

69-
async updateMangaChapterRead(itemLink: string, chapterNames: string[], read: boolean) {
75+
async updateMangaChapterRead(itemLink: string, chapterNames: string[], read: boolean): Promise<string[]> {
7076
return await this._db.transaction(async (tx) => {
7177
const [progress] = await tx.select().from(mangaProgress).where(eq(mangaProgress.itemLink, itemLink));
7278
if (!progress) {
@@ -89,7 +95,7 @@ export class DatabaseService {
8995
});
9096
}
9197

92-
async updateBookProgress(data: UpdateBookProgressData) {
98+
async updateBookProgress(data: UpdateBookProgressData): Promise<BookProgress[]> {
9399
const { itemLink, ...updateData } = data;
94100
return await this._db
95101
.update(bookProgress)
@@ -101,9 +107,7 @@ export class DatabaseService {
101107
.returning();
102108
}
103109

104-
// todo: review
105-
// todo: add option in frontend to manually import as well
106-
async migrateFromJSON(historyData: HistoryItem[], bookmarkData: Manga_BookItem[]) {
110+
async migrateFromJSON(historyData: HistoryItem[], bookmarkData: Manga_BookItem[]): Promise<void> {
107111
log.log(
108112
"Migrating from JSON " +
109113
historyData.length +

src/electron/db/schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { relations, sql } from "drizzle-orm";
22
import { sqliteTable, text, integer, unique, index } from "drizzle-orm/sqlite-core";
33

4-
// todo : add relations
5-
64
const timeNow = sql`(unixepoch() * 1000)`;
75

86
export const libraryItems = sqliteTable("library_items", {

src/electron/main.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ app.on("ready", async () => {
8585
{ role: "forceReload" },
8686
{ role: "toggleDevTools" },
8787
{ type: "separator" },
88-
// ! moving to App.tsx
89-
// { role: "resetZoom" },
90-
// { role: "zoomIn", accelerator: "CommandOrControl+=" },
91-
// { role: "zoomOut" },
9288
],
9389
},
9490
{

src/electron/util/migrate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const migrateToSqlite = async (
1616
db: DatabaseService,
1717
history: HistoryItem[],
1818
bookmarks: Manga_BookItem[],
19-
) => {
19+
): Promise<void> => {
2020
try {
2121
log.log("Backing up db");
2222
await fs.access(DB_PATH);
@@ -37,7 +37,7 @@ export const migrateToSqlite = async (
3737
}
3838
};
3939

40-
export const checkForJSONMigration = async (db: DatabaseService) => {
40+
export const checkForJSONMigration = async (db: DatabaseService): Promise<void> => {
4141
const bookmarks: Manga_BookItem[] = [];
4242
const history: HistoryItem[] = [];
4343
try {

src/renderer/components/ListNavigator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ type SearchInputProps = {
224224
}
225225
);
226226

227-
const SearchInputComponent = ({
227+
const SearchInputComponent: React.FC<SearchInputProps> = ({
228228
placeholder = "Type to search",
229229
className = "search-input",
230230
onChange,
231231
runOriginalOnChange = false,
232-
}: SearchInputProps) => {
232+
}) => {
233233
const { inputRef, handleFilterChange, handleKeyDown, setFocused } = useListNavigator();
234234

235235
useEffect(() => {

src/renderer/components/ui/MenuList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { shallowEqual } from "react-redux";
99

1010
// ! not indented to be used without `AppContext::optSelectData`
1111
//todo rename later for select only
12-
const MenuList = () => {
12+
const MenuList: React.FC = () => {
1313
const { optSelectData } = useAppContext();
1414
const shortcutsMapped = useAppSelector(getShortcutsMapped, shallowEqual);
1515

src/renderer/components/ui/Modal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type PropsBase = {
99
type Props1 = PropsBase & { children: ReactNode; asHTML?: false };
1010
type Props2 = PropsBase & { children: string; asHTML: true };
1111
const Modal = memo((props: Props1 | Props2) => {
12-
//todo impl
1312
return (
1413
<FocusLock disabled={!!props.noFocusLock}>
1514
<div

src/renderer/features/reader/epub/StyleSheets.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ const StyleSheets = memo(
88
className="stylesheets"
99
ref={(node) => {
1010
if (node) {
11-
// todo check async behavior
1211
sheets.forEach(async (url) => {
1312
try {
1413
const stylesheet = document.createElement("style");
1514
let txt = await window.fs.readFile(url, "utf-8");
1615
const matches = Array.from(txt.matchAll(/url\((.*?)\);/gi));
1716
matches.forEach((e) => {
1817
// for font
19-
const url_old = e[1].slice(1, -1);
18+
let originalURL = e[1];
19+
if (originalURL.startsWith(`'`) || originalURL.startsWith(`"`))
20+
originalURL = originalURL.slice(1, -1);
2021
txt = txt.replaceAll(
21-
url_old,
22-
"file://" +
23-
window.path
24-
.join(window.path.dirname(url), url_old)
25-
.replaceAll("\\", "/"),
22+
e[1],
23+
`"file://${window.path
24+
.join(window.path.dirname(url), originalURL)
25+
.replaceAll("\\", "/")}"`,
2626
);
2727
});
2828
// to make sure styles don't apply outside
@@ -49,5 +49,6 @@ const StyleSheets = memo(
4949
},
5050
(prev, next) => prev.sheets.length === next.sheets.length && prev.sheets[0] === next.sheets[0],
5151
);
52+
StyleSheets.displayName = "StyleSheets";
5253

5354
export default StyleSheets;

src/renderer/store/shortcuts.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ const shortcuts = createSlice({
6565
initialState,
6666
reducers: {
6767
setShortcuts: (state, action: PayloadAction<{ command: ShortcutCommands; key: string }>) => {
68-
// todo: why did i do this?
69-
// if (action.payload instanceof Array) state = action.payload;
7068
const { command, key } = action.payload;
7169
const index = state.findIndex((e) => e.command === command);
7270
if (index > -1) {

0 commit comments

Comments
 (0)