Skip to content

Commit

Permalink
add readCount, fix database patch
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Aug 28, 2024
1 parent 731b9e9 commit fe5262e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions modules/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const prepareMangaModel = (databasePath) => {
type: DataTypes.BOOLEAN,
defaultValue: false
},
readCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
exist: {
type: DataTypes.BOOLEAN,
defaultValue: true
Expand Down
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
@click="handleClickCover(book)"
@contextmenu="onBookContextMenu($event, book)"
/>
<el-tag class="book-card-language" size="small" type="danger" v-show="isChineseTranslatedManga(book)">ZH</el-tag>
<el-tag class="book-card-language" size="small" :type="isChineseTranslatedManga(book) ? 'danger' : 'info'">{{book.readCount}}</el-tag>
<el-tag class="book-card-pagecount" size="small" type="danger" v-if="book.pageDiff" @click="searchFromTag('pageDiff')">{{book.pageCount}}|{{book.filecount}}P</el-tag>
<el-tag class="book-card-pagecount" size="small" type="info" v-else>{{ book.pageCount }}P</el-tag>
<el-icon
Expand Down Expand Up @@ -534,6 +534,7 @@
@message="printMessage"
@update-window-title="updateWindowTitle"
@rescan-book="rescanBook"
@save-book="saveBook"
></InternalViewer>
<el-drawer v-model="sideVisibleFolderTree"
:title="$t('m.folderTree')"
Expand Down Expand Up @@ -2184,6 +2185,8 @@ export default defineComponent({
openLocalBook (book) {
this.bookDetail = book
if (this.setting.imageExplorer) {
this.bookDetail.readCount += 1
this.saveBook(this.bookDetail)
ipcRenderer.invoke('open-local-book', this.bookDetail.filepath)
} else {
this.$refs.InternalViewerRef.viewManga(book)
Expand Down
5 changes: 4 additions & 1 deletion src/components/InternalViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ const emit = defineEmits([
'message',
'updateOptions',
'updateWindowTitle',
'rescanBook'
'rescanBook',
'saveBook'
])
const drawerVisibleViewer = ref(false)
Expand Down Expand Up @@ -258,6 +259,8 @@ const viewManga = (book, viewerHeight = '100%') => {
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 => {
Expand Down

0 comments on commit fe5262e

Please sign in to comment.