diff --git a/src/package.json b/src/package.json index 52fff42..6cc4bc5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,7 +1,7 @@ { "name": "electron-webtoon", "productName": "electron-webtoon", - "version": "2.3.5", + "version": "2.3.6", "description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development", "main": "./main.prod.js", "author": { diff --git a/src/server/comicsservice.ts b/src/server/comicsservice.ts index d8bf5ea..ad6ae27 100644 --- a/src/server/comicsservice.ts +++ b/src/server/comicsservice.ts @@ -172,21 +172,39 @@ export default class ComicService { return R.find(R.propEq('id', id), library); } - async addComicToLibrary(comicpath: string) { + + isExistsAndTouch(comicPath: string) { const library = this.store.get('library'); - const newLibrary = (library || []).concat( - await this.buildNewComic(comicpath) - ); - this.store.set('library', newLibrary); + const index = R.findIndex(R.propEq('path', comicPath), library); + + if (index !== -1) { + const newLibrary = [...library]; + newLibrary.splice(index, 1); + this.store.set('library', [...newLibrary, library[index]]); + return true; + } + return false; + } + + async addComicToLibrary(comicpath: string) { + if (!this.isExistsAndTouch(comicpath)) { + const library = this.store.get('library'); + const newLibrary = (library || []).concat( + await this.buildNewComic(comicpath) + ); + this.store.set('library', newLibrary); + } } // add compress file meta info to config async addComicToLibrary2(comicpath: string, compressFilePath: string) { - const library = this.store.get('library'); - const newComic = await this.buildNewComic(comicpath); - newComic.compressFilePath = compressFilePath; - const newLibrary = (library || []).concat(newComic); - this.store.set('library', newLibrary); + if (!this.isExistsAndTouch(comicpath)) { + const library = this.store.get('library'); + const newComic = await this.buildNewComic(comicpath); + newComic.compressFilePath = compressFilePath; + const newLibrary = (library || []).concat(newComic); + this.store.set('library', newLibrary); + } } // 打开文件选择对话框