Skip to content

Commit

Permalink
fix lowdb permission, drawer; add youtube-dl method in select
Browse files Browse the repository at this point in the history
  • Loading branch information
7Red4 committed Jul 20, 2021
1 parent 8ee03af commit 61032b6
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 94 deletions.
89 changes: 57 additions & 32 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,55 @@
</v-btn>
</v-app-bar>

<v-main>
<transition name="route-change-transition">
<keep-alive>
<router-view :key="$route.fullPath"></router-view>
</keep-alive>
</transition>
</v-main>

<v-navigation-drawer
:value="getShowQue"
@input="(v) => SET_SHOW_QUE(v)"
class="que_drawer"
width="400"
disable-resize-watcher
clipped
right
app
>
<v-card
:style="{
position: 'absolute',
top: $vuetify.breakpoint.mdAndUp
? 0
: `${$vuetify.application.top + $vuetify.application.bar}px`,
width: '100%',
zIndex: 1
}"
>
<v-card :ripple="false" @click.right="showMenu" class="fill-height">
<SizeBox
:height="$vuetify.application.top + $vuetify.application.bar"
class="d-block d-lg-none"
/>
<v-card-title>
下載中的影片
<v-spacer></v-spacer>
<v-btn text @click="startAll">全部開始</v-btn>
</v-card-title>
<div class="pt-4">
<div v-for="tracker in getQueList" :key="tracker.id">
<QueTracker :tracker="tracker" />
<v-divider></v-divider>
</div>
</div>
</v-card>
<div
:style="{
height: $vuetify.breakpoint.mdAndUp
? 0
: `${$vuetify.application.top + $vuetify.application.bar}px`
}"
></div>
<div class="py-8"></div>
<div v-for="tracker in getQueList" :key="tracker.id">
<QueTracker :tracker="tracker" />
<v-divider></v-divider>
</div>
</v-navigation-drawer>

<v-main>
<transition name="route-change-transition">
<keep-alive>
<router-view :key="$route.fullPath"></router-view>
</keep-alive>
</transition>
</v-main>
<v-menu
v-model="isMenuShow"
:position-x="x"
:position-y="y"
absolute
offset-y
>
<v-list>
<v-list-item @click="startAll">全部開始</v-list-item>
<v-list-item @click="deleteAll">全部刪除</v-list-item>
<v-list-item @canplay="stopAll">全部停止</v-list-item>
</v-list>
</v-menu>
</v-navigation-drawer>
</v-app>
</template>

Expand All @@ -119,7 +122,11 @@ export default {
return {
platform: '',
isMaximized: false,
isDrawer: false
isDrawer: false,
isMenuShow: false,
x: 0,
y: 0
};
},
Expand Down Expand Up @@ -209,8 +216,26 @@ export default {
ipcRenderer.send('close-window');
},
showMenu(e) {
e.preventDefault();
this.isMenuShow = false;
this.x = e.clientX;
this.y = e.clientY;
this.$nextTick(() => {
this.isMenuShow = true;
});
},
startAll() {
ipcRenderer.send('start-ques');
},
deleteAll() {
ipcRenderer.send('delete-ques');
},
stopAll() {
ipcRenderer.send('stop-ques');
}
}
};
Expand Down
7 changes: 7 additions & 0 deletions src/GlobalComponentsInject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Vue from 'vue';

import Async from '@/components/Globals/Async.vue';
import SizeBox from '@/components/Globals/SizeBox.vue';

Vue.component('Async', Async);
Vue.component('SizeBox', SizeBox);
44 changes: 36 additions & 8 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import https from 'https';
import os from 'os';

import { app, protocol, BrowserWindow, ipcMain, dialog } from 'electron';
import { app, protocol, BrowserWindow, ipcMain, dialog, shell } from 'electron';
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib';
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer';
import { getInfo } from './controller/ytdl.js';
Expand Down Expand Up @@ -139,6 +139,19 @@ ipcMain.on('delete-que', async (event, queId) => {
}
});

ipcMain.on('delete-ques', async (event) => {
queMap.forEach(({ id, stopProcess }) => {
try {
stopProcess();
queMap.delete(id);
event.reply('delete-que-reply', id);
} catch (error) {
event.reply('delete-fail', id);
consola.error(error);
}
});
});

ipcMain.on('start-que-by-id', async (event, queId) => {
const que = queMap.get(queId);
try {
Expand All @@ -151,14 +164,14 @@ ipcMain.on('start-que-by-id', async (event, queId) => {
});

ipcMain.on('start-ques', async (event, req) => {
try {
queMap.forEach((que) => {
queMap.forEach((que) => {
try {
que.startProcess({ event });
});
} catch (error) {
// event.reply('start-fail', que.id);
consola.error(error);
}
} catch (error) {
// event.reply('start-fail', que.id);
consola.error(error);
}
});
});

ipcMain.on('stop-que', async (event, queId) => {
Expand All @@ -170,6 +183,17 @@ ipcMain.on('stop-que', async (event, queId) => {
}
});

ipcMain.on('stop-que', async (event) => {
queMap.forEach(({ id, stopProcess }) => {
try {
stopProcess();
} catch (error) {
event.reply('stoped-error', id);
consola.error(error);
}
});
});

ipcMain.on('edit-que', (event, tracker) => {
try {
queMap.get(tracker.id).updateQue(tracker);
Expand Down Expand Up @@ -227,3 +251,7 @@ ipcMain.on('export-list', async (event, { exporting, path }) => {
consola.error(error);
}
});

ipcMain.on('show-item-in-folder', (event, path) => {
shell.openPath(path);
});
72 changes: 72 additions & 0 deletions src/components/Globals/Async.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<span v-if="inline">
<v-progress-circular
v-if="isLoading"
v-bind="$attrs"
indeterminate
></v-progress-circular>
<slot v-if="shoudShowContent" :res="res"></slot>
</span>

<div v-else>
<v-progress-circular
v-if="isLoading"
v-bind="$attrs"
indeterminate
></v-progress-circular>
<slot v-if="shoudShowContent" :res="res"></slot>
</div>
</template>

<script>
export default {
props: {
fn: {
type: Function,
default: null
},
loading: {
type: Boolean,
default: false
},
inline: {
type: Boolean,
default: false
},
remainContent: {
type: Boolean,
default: false
}
},
data() {
return {
loadComplete: false,
res: null
};
},
computed: {
isLoading() {
return this.loading || !this.loadComplete;
},
shoudShowContent() {
return !this.isLoading || this.remainContent;
}
},
async mounted() {
if (this.fn) {
this.res = await this.fn();
}
this.loadComplete = true;
this.$nextTick(() => {
this.$emit('load');
});
}
};
</script>
77 changes: 77 additions & 0 deletions src/components/Globals/SizeBox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<script>
const sizeUnitsRe =
/[^d]m|[^d]ex[^d]|[^d]%|[^d]px|[^d]cm|[^d]mm|[^d]in|[^d]pt|[^d]pc|[^d]ch|[^d]rem|[^d]vh|[^d]vw|[^d]vmin|[^d]vmax/;
const validator = (v) => {
return sizeUnitsRe.test(v) || !Number.isNaN(v);
};
export default {
name: 'SizeBox',
props: {
width: {
type: [String, Number],
default: 0,
validate(v) {
return validator(v);
}
},
height: {
type: [String, Number],
default: 0,
validate(v) {
return validator(v);
}
},
minWidth: {
type: [String, Number],
default: 0,
validate(v) {
return validator(v);
}
},
minHeight: {
type: [String, Number],
default: 0,
validate(v) {
return validator(v);
}
},
inline: {
type: Boolean,
default: false
}
},
computed: {
computedStyle() {
return {
width: Number.isNaN(this.width)
? this.width
: this.width
? `${this.width}px`
: null,
height: Number.isNaN(this.height)
? this.height
: this.height
? `${this.height}px`
: null,
minWidth: Number.isNaN(this.minWidth)
? this.minWidth
: this.minWidth
? `${this.minWidth}px`
: null,
minHeight: Number.isNaN(this.minHeight)
? this.minHeight
: this.minHeight
? `${this.minHeight}px`
: null,
display: this.inline ? 'inline-block' : 'block'
};
}
},
render(h) {
return h('div', { style: this.computedStyle });
}
};
</script>
Loading

0 comments on commit 61032b6

Please sign in to comment.