Skip to content

Commit ce01d76

Browse files
committed
finalize downloads page :)
1 parent ad3c459 commit ce01d76

File tree

10 files changed

+139
-17
lines changed

10 files changed

+139
-17
lines changed

app/src/guest/renderer/components/AboutMainView/Lulumi.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,3 @@
1818
},
1919
};
2020
</script>
21-
22-
<style scoped>
23-
html {
24-
background-color: #eee;
25-
}
26-
</style>

app/src/guest/renderer/components/AboutMainView/Preferences/Downloads.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<template lang="pug">
22
div
33
h1 Downloads
4+
el-button#downloads-clear(type="info", @click="setDownloads") Clear
45
ul(class="download-list")
56
li(v-for="(file, index) in files", :key="index", class="download-list__item")
7+
span(class="el-icon-close", @click="setDownloads(index)")
68
el-progress(:status="checkStateForProgress(file.state)", :text-inside="true", :percentage="percentage(file)", :stroke-width="18", class="download-list__item-progress")
79
a(class="download-list__item-name", :href="`${file.url}`")
810
i(class="el-icon-document") {{ file.name }}
@@ -34,6 +36,15 @@
3436
percentage(file) {
3537
return parseInt((file.getReceivedBytes / file.totalBytes) * 100, 10) || 0;
3638
},
39+
setDownloads(index) {
40+
if (index) {
41+
this.files.splice(index, 1);
42+
} else {
43+
this.files = [];
44+
}
45+
// eslint-disable-next-line no-undef
46+
ipcRenderer.send('set-downloads', this.files);
47+
},
3748
showItemInFolder(savePath) {
3849
// eslint-disable-next-line no-undef
3950
ipcRenderer.send('show-item-in-folder', savePath);
@@ -99,11 +110,18 @@
99110
align-items: center;
100111
justify-content: space-around;
101112
}
113+
a.download-list__item-name:link {
114+
text-decoration: none;
115+
}
116+
a.download-list__item-name:hover {
117+
color: green;
118+
text-decoration: none;
119+
}
102120
.download-list__item-name {
103121
color: #48576a;
104122
padding-left: 4px;
105123
transition: color .3s;
106-
flex: 5
124+
flex: 5;
107125
}
108126
.download-list__item-name > i {
109127
overflow: hidden;
@@ -115,4 +133,9 @@
115133
right: 0;
116134
flex: 1;
117135
}
136+
#downloads-clear {
137+
top: 10px;
138+
right: 50px;
139+
position: absolute;
140+
}
118141
</style>

app/src/main/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ ipcMain.on('show-item-in-folder', (event, path) => {
190190
}
191191
});
192192

193+
ipcMain.on('open-item', (event, path) => {
194+
if (path) {
195+
shell.openItem(path);
196+
}
197+
});
198+
193199
ipcMain.on('lulumi-scheme-loaded', (event, val) => {
194200
const type = val.substr((config.lulumiPagesCustomProtocol).length).split('/')[0];
195201
const data = {};
@@ -295,3 +301,7 @@ ipcMain.on('set-homepage', (event, val) => {
295301
ipcMain.on('set-tab-config', (event, val) => {
296302
mainWindow.webContents.send('set-tab-config', val);
297303
});
304+
305+
ipcMain.on('set-downloads', (event, val) => {
306+
mainWindow.webContents.send('set-downloads', val);
307+
});

app/src/renderer/components/BrowserMainView.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@
288288
this.getWebView(pageIndex).send('guest-here-your-data', this.$store.getters.downloads);
289289
}
290290
},
291+
onSetDownloads(event, pageIndex, val) {
292+
this.$store.dispatch('setDownloads', val);
293+
this.getWebView(pageIndex).send('guest-here-your-data', this.$store.getters.downloads);
294+
},
291295
// tabHandlers
292296
onNewTab(location) {
293297
this.$store.dispatch('incrementPid');

app/src/renderer/components/BrowserMainView/Download.vue

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
el-button(:disabled="file.state !== 'progressing'", :plain="true", type="danger", size="mini", icon="circle-close", @click="cancelDownload(file.startTime)")
1212
el-button(:disabled="file.state === 'cancelled'", :plain="true", type="info", size="mini", icon="document", @click="showItemInFolder(file.savePath)")
1313
li(class="download-list__item", slot="reference")
14-
a(class="download-list__item-name", :href="`${file.url}`")
15-
i(class="el-icon-document") {{ file.name }}
14+
div(class="download-list__item-panel")
15+
a(class="download-list__item-name", href='#', @click.prevent="openItem(file.savePath)")
16+
i(class="el-icon-document") {{ file.name }}
17+
span(class="download-list__item-description") {{ file.state === 'progressing' ? `${prettyReceivedSize(file.getReceivedBytes)}/${file.totalSize}`: file.state }}
1618
el-progress(:status="checkStateForProgress(file.state)", type="circle", :percentage="percentage(file)", :width="30", :stroke-width="3", class="download-list__item-progress")
1719
span#download-bar-close(class="el-icon-close", @click="closeDownloadBar")
1820
</template>
@@ -22,6 +24,7 @@
2224
2325
import '../../css/el-progress';
2426
import '../../css/el-popover';
27+
import prettySize from '../../js/lib/prettysize';
2528
2629
export default {
2730
components: {
@@ -32,19 +35,32 @@
3235
},
3336
computed: {
3437
files() {
35-
// eslint-disable-next-line arrow-body-style
36-
return this.$store.getters.downloads.filter((download) => {
37-
return download.style !== 'hidden';
38-
});
38+
let tmpFiles = [];
39+
if (this.$store.getters.downloads.length !== 0) {
40+
// eslint-disable-next-line arrow-body-style
41+
tmpFiles = this.$store.getters.downloads.filter((download) => {
42+
return download.style !== 'hidden';
43+
});
44+
tmpFiles.forEach((file) => {
45+
file.totalSize = prettySize.process(file.totalBytes);
46+
});
47+
}
48+
return tmpFiles;
3949
},
4050
},
4151
methods: {
52+
prettyReceivedSize(size) {
53+
return prettySize.process(size);
54+
},
4255
percentage(file) {
4356
return parseInt((file.getReceivedBytes / file.totalBytes) * 100, 10) || 0;
4457
},
4558
showItemInFolder(savePath) {
4659
this.$electron.ipcRenderer.send('show-item-in-folder', savePath);
4760
},
61+
openItem(savePath) {
62+
this.$electron.ipcRenderer.send('open-item', savePath);
63+
},
4864
checkStateForButtonGroup(state) {
4965
switch (state) {
5066
case 'cancelled':
@@ -143,6 +159,10 @@
143159
align-items: center;
144160
justify-content: space-around;
145161
}
162+
.download-list__item-panel {
163+
display: flex;
164+
flex-direction: column;
165+
}
146166
.download-list__item-name {
147167
color: #48576a;
148168
padding-left: 4px;
@@ -154,6 +174,9 @@
154174
text-overflow: ellipsis;
155175
width: 160px;
156176
}
177+
.download-list__item-description {
178+
font-size: 13px;
179+
}
157180
.download-list__item-progress {
158181
right: 0;
159182
}

app/src/renderer/components/BrowserMainView/Page.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@
236236
this.$parent.onGetDownloads(event, this.pageIndex, data);
237237
}
238238
});
239+
ipc.on('set-downloads', (event, val) => {
240+
if (this.$parent.onSetDownloads) {
241+
this.$parent.onSetDownloads(event, this.pageIndex, val);
242+
}
243+
});
239244
240245
this.$nextTick(() => {
241246
// TODO: https://github.com/qazbnm456/lulumi-browser/issues/3
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const sizes = [
2+
'Bytes', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB',
3+
];
4+
5+
const prettySize = {
6+
/**
7+
* Pretty print a size from bytes
8+
* @method pretty
9+
* @param {Number} size The number to pretty print
10+
* @param {Boolean} [nospace=false] Don't print a space
11+
* @param {Boolean} [one=false] Only print one character
12+
*/
13+
process(size, nospace, one) {
14+
let mysize;
15+
let f;
16+
17+
sizes.forEach((f, id) => {
18+
if (one) {
19+
f = f.slice(0, 1);
20+
}
21+
22+
const s = 1024 ** id;
23+
let fixed;
24+
if (size >= s) {
25+
fixed = String((size / s).toFixed(1));
26+
if (fixed.indexOf('.0') === fixed.length - 2) {
27+
fixed = fixed.slice(0, -2);
28+
}
29+
mysize = fixed + (nospace ? '' : ' ') + f;
30+
}
31+
});
32+
33+
// zero handling
34+
// always prints in Bytes
35+
if (!mysize) {
36+
f = (one ? sizes[0].slice(0, 1) : sizes[0]);
37+
mysize = `0${nospace ? '' : ' '}${f}`;
38+
}
39+
40+
return mysize;
41+
},
42+
};
43+
44+
export default prettySize;

app/src/renderer/vuex/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export const setHomepage = ({ commit }, val) => {
5757
export const setTabConfig = ({ commit }, val) => {
5858
commit(types.SET_TAB_CONFIG, val);
5959
};
60+
export const setDownloads = ({ commit }, val) => {
61+
commit(types.SET_DOWNLOADS, val);
62+
};
6063
export const createDownloadTask = ({ commit }, file) => {
6164
commit(types.CREATE_DOWNLOAD_TASK, file);
6265
};

app/src/renderer/vuex/modules/browser.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,41 @@ const mutations = {
167167
[types.SET_TAB_CONFIG](state, val) {
168168
state.tabConfig = val;
169169
},
170+
[types.SET_DOWNLOADS](state, val) {
171+
state.downloads = val;
172+
},
170173
// downloads handlers
171174
[types.CREATE_DOWNLOAD_TASK](state, file) {
172175
state.downloads.push(file);
173176
},
174177
[types.UPDATE_DOWNLOADS_PROGRESS](state, file) {
175-
state.downloads.forEach((download) => {
178+
state.downloads.every((download) => {
176179
if (download.startTime === file.startTime) {
177180
download.getReceivedBytes = file.getReceivedBytes;
178181
download.savePath = file.savePath;
179182
download.isPaused = file.isPaused;
180183
download.canResume = file.canResume;
181184
download.state = file.state;
185+
return false;
186+
// eslint-disable-next-line no-else-return
187+
} else {
188+
return true;
182189
}
183190
});
184191
},
185192
[types.COMPLETE_DOWNLOADS_PROGRESS](state, file) {
186-
state.downloads.forEach((download) => {
193+
state.downloads.every((download, index) => {
187194
if (download.startTime === file.startTime) {
188-
download.name = file.name;
189-
download.state = file.state;
195+
if (download.savePath === '') {
196+
state.downloads.splice(index, 1);
197+
} else {
198+
download.name = file.name;
199+
download.state = file.state;
200+
}
201+
return false;
202+
// eslint-disable-next-line no-else-return
203+
} else {
204+
return true;
190205
}
191206
});
192207
},

app/src/renderer/vuex/mutation-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const UPDATE_LOCATION = 'UPDATE_LOCATION';
1919
export const SET_CURRENT_SEARCH_ENGINE_PROVIDER = 'SET_CURRENT_SEARCH_ENGINE_PROVIDER';
2020
export const SET_HOMEPAGE = 'SET_HOMEPAGE';
2121
export const SET_TAB_CONFIG = 'SET_TAB_CONFIG';
22+
export const SET_DOWNLOADS = 'SET_DOWNLOADS';
2223
export const CREATE_DOWNLOAD_TASK = 'CREATE_DOWNLOAD_TASK';
2324
export const UPDATE_DOWNLOADS_PROGRESS = 'UPDATE_DOWNLOADS_PROGRESS';
2425
export const COMPLETE_DOWNLOADS_PROGRESS = 'COMPLETE_DOWNLOADS_PROGRESS';

0 commit comments

Comments
 (0)