From fe5262e70b293f59c0575cbdaebfa7a251d925e5 Mon Sep 17 00:00:00 2001 From: SchneeHertz <39257008+SchneeHertz@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:39:45 +0800 Subject: [PATCH] add readCount, fix database patch --- index.js | 16 ++++++++++++++-- modules/database.js | 4 ++++ src/App.vue | 5 ++++- src/components/InternalViewer.vue | 5 ++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 21452c1..da35916 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,20 @@ if (setting.metadataPath) { metadataSqliteFile = path.join(STORE_PATH, './metadata.sqlite') } let Metadata = prepareMetadataModel(metadataSqliteFile) +const getColumns = async (sequelize, tableName) => { + const query = `PRAGMA table_info(${tableName})` + const [results] = await sequelize.query(query) + return results.map(column => column.name) +} +;(async () => { + const columns = await getColumns(Manga.sequelize, 'Mangas') + if (['hiddenBook', 'readCount'].some(c => !columns.includes(c))) { + await Manga.sync({ alter: true }) + } else { + await Manga.sync() + } + await Metadata.sync() +})() const logFile = fs.createWriteStream(path.join(STORE_PATH, 'log.txt'), { flags: 'w' }) const logStdout = process.stdout @@ -99,8 +113,6 @@ const createWindow = () => { app.commandLine.appendSwitch('js-flags', '--max-old-space-size=65536') // app.disableHardwareAcceleration() app.whenReady().then(async () => { - await Manga.sync() - await Metadata.sync() const primaryDisplay = screen.getPrimaryDisplay() screenWidth = Math.floor(primaryDisplay.workAreaSize.width * primaryDisplay.scaleFactor) mainWindow = createWindow() diff --git a/modules/database.js b/modules/database.js index c5f245c..04f73f6 100644 --- a/modules/database.js +++ b/modules/database.js @@ -42,6 +42,10 @@ const prepareMangaModel = (databasePath) => { type: DataTypes.BOOLEAN, defaultValue: false }, + readCount: { + type: DataTypes.INTEGER, + defaultValue: 0 + }, exist: { type: DataTypes.BOOLEAN, defaultValue: true diff --git a/src/App.vue b/src/App.vue index 82631f9..45276b3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -127,7 +127,7 @@ @click="handleClickCover(book)" @contextmenu="onBookContextMenu($event, book)" /> - ZH + {{book.readCount}} {{book.pageCount}}|{{book.filecount}}P {{ book.pageCount }}P { ipcRenderer.invoke('load-manga-image-list', _.cloneDeep(book)) .then(() => { drawerVisibleViewer.value = true + book.readCount += 1 + emit('saveBook', book) if (props.setting.keepReadingProgress && showThumbnail.value === false) handleJumpToReadingProgress(book) }) .catch(err => {