Skip to content

Commit

Permalink
Merge pull request #542 from YuRiJinX/boorkmark
Browse files Browse the repository at this point in the history
feat: support bookmark
  • Loading branch information
ipy committed Apr 4, 2019
2 parents 36ba85e + 46ad27c commit 67fb5ab
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/renderer/components/LandingView/Playlist.vue
Expand Up @@ -111,6 +111,9 @@ export default {
window.onkeyup = null;
},
mounted() {
this.$bus.$on('clean-lastPlayedFile', () => {
this.firstIndex = 0;
});
window.onkeyup = (e) => {
this.tranFlag = true;
if (e.keyCode === 39) {
Expand Down
4 changes: 0 additions & 4 deletions src/renderer/components/PlayingView/RecentPlaylistItem.vue
Expand Up @@ -358,11 +358,7 @@ export default {
if (val !== this.index) {
this.$refs.recentPlaylistItem.style.setProperty('transform', `translate(${(val - this.index) * distance}px,0)`);
} else {
this.tranFlag = false;
this.$refs.recentPlaylistItem.style.setProperty('transform', 'translate(0,0)');
setTimeout(() => {
this.tranFlag = true;
}, 0);
}
});
},
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/PlayingView/VideoCanvas.vue
Expand Up @@ -225,6 +225,9 @@ export default {
this.changeWindowRotate(val);
},
originSrc(val, oldVal) {
if (process.mas && oldVal) {
this.$bus.$emit(`stop-accessing-${oldVal}`, oldVal);
}
this.saveScreenshot(oldVal);
this.$bus.$emit('show-speedlabel');
this.videoConfigInitialize({
Expand Down Expand Up @@ -396,6 +399,7 @@ export default {
};
},
beforeDestroy() {
this.$bus.$emit(`stop-accessing-${this.originSrc}`, this.originSrc);
window.onbeforeunload = null;
},
};
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/helpers/bookmark.js
@@ -0,0 +1,14 @@
import syncStorage from '@/helpers/syncStorage';

function resolveBookmarks(files, bookmarks) {
const data = syncStorage.getSync('bookmark');
const temp = {};
files.forEach((file, i) => {
temp[file] = bookmarks[i];
});
syncStorage.setSync('bookmark', { ...data, ...temp });
}

export default {
resolveBookmarks,
};
24 changes: 22 additions & 2 deletions src/renderer/helpers/index.js
Expand Up @@ -3,6 +3,8 @@ import fs, { promises as fsPromises } from 'fs';
import crypto from 'crypto';
import lolex from 'lolex';
import { times } from 'lodash';
import bookmark from '@/helpers/bookmark';
import syncStorage from '@/helpers/syncStorage';
import infoDB from '@/helpers/infoDB';
import { getValidVideoExtensions, getValidVideoRegex } from '@/../shared/utils';
import { FILE_NON_EXIST, EMPTY_FOLDER, OPEN_FAILED, ADD_NO_VIDEO } from '@/../shared/notificationcodes';
Expand All @@ -20,6 +22,7 @@ export default {
infoDB,
sagi: Sagi,
showingPopupDialog: false,
access: [],
};
},
methods: {
Expand Down Expand Up @@ -170,7 +173,7 @@ export default {
this.showingPopupDialog = false;
if (process.mas && bookmarks?.length > 0) {
// TODO: put bookmarks to database
console.log(bookmarks);
bookmark.resolveBookmarks(files, bookmarks);
}
if (files) {
// if selected files contain folders only, then call openFolder()
Expand Down Expand Up @@ -207,7 +210,7 @@ export default {
this.showingPopupDialog = false;
if (process.mas && bookmarks?.length > 0) {
// TODO: put bookmarks to database
console.log(bookmarks);
bookmark.resolveBookmarks(files, bookmarks);
}
if (files) {
this.addFiles(...files);
Expand Down Expand Up @@ -342,6 +345,23 @@ export default {
async playFile(vidPath) {
const originPath = vidPath;
let mediaQuickHash;
if (process.mas) {
const bookmarkObj = syncStorage.getSync('bookmark');
if (bookmarkObj.hasOwnProperty(vidPath)) {
const { app } = remote;
const bookmark = bookmarkObj[vidPath];
const stopAccessing = app.startAccessingSecurityScopedResource(bookmark);
this.access.push({
src: vidPath,
stopAccessing
});
this.$bus.$once(`stop-accessing-${vidPath}`, (e) => {
this.access.find(item => item.src === e)?.stopAccessing();
const index = this.access.findIndex(item => item.src === e);
if (index >= 0) this.access.splice(index, 1);
});
}
}
try {
mediaQuickHash = await this.mediaQuickHash(originPath);
} catch (err) {
Expand Down
35 changes: 35 additions & 0 deletions test/unit/specs/helpers/bookmark.spec.js
@@ -0,0 +1,35 @@
import bookmark from '@/helpers/bookmark';
import syncStorage from '@/helpers/syncStorage';

describe.only('bookmark', () => {
const data = {
'/path/1/2/4': 'bookmark1',
'/path/1/3/2': 'bookmark2',
};
beforeEach(() => {
syncStorage.setSync('bookmark', data);
});
it('resolveBookmarks', () => {
const files = ['/path/1/2/3/4.mp4'];
const bookmarks = ['bookmark3'];
bookmark.resolveBookmarks(files, bookmarks);

const data = syncStorage.getSync('bookmark');
expect(data).deep.equal({
'/path/1/2/4': 'bookmark1',
'/path/1/3/2': 'bookmark2',
'/path/1/2/3/4.mp4': 'bookmark3',
});
});
// it('resolveBookmarks can replace the child files', () => {
// const files = ['/path/1/2'];
// const bookmarks = ['bookmark4'];
// bookmark.resolveBookmarks(files, bookmarks);

// const data = syncStorage.getSync('bookmark');
// expect(data).deep.equal({
// '/path/1/2': 'bookmark4',
// '/path/1/3/2': 'bookmark2',
// });
// });
});

0 comments on commit 67fb5ab

Please sign in to comment.