-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWotwSeedButton.vue
67 lines (59 loc) · 1.74 KB
/
WotwSeedButton.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<v-tooltip open-delay="500" top :disabled="!isElectron">
<template #activator="{ on, attrs }">
<v-btn v-bind="attrs" :loading="loading" icon text outlined @click="launchOrDownloadSeed" v-on="on">
<v-icon>{{ isElectron && !forceDownload ? 'mdi-play' : 'mdi-download' }}</v-icon>
</v-btn>
</template>
<span>Hold <kbd>Ctrl</kbd> to download</span>
</v-tooltip>
</template>
<script>
import { saveAs } from 'file-saver'
import { isElectron } from '~/assets/lib/isElectron'
import { holdControl } from '~/assets/lib/holdControl'
export default {
name: 'WotwSeedButton',
mixins: [holdControl('forceDownload')],
props: {
worldSeedId: {
type: [String, Number],
required: true,
},
},
data: () => ({
loading: false,
forceDownload: false,
}),
computed: {
isElectron: () => isElectron(),
},
methods: {
async launchOrDownloadSeed() {
const url = `${this.$axios.defaults.baseURL}/world-seeds/${this.worldSeedId}/file`
const fileName = `${this.worldSeedId}.wotwr`
if (isElectron()) {
this.loading = true
const forceDownload = this.forceDownload
try {
await window.electronApi.invoke('launcher.downloadSeedFromUrl', {
url,
fileName,
setToCurrent: !forceDownload,
showInExplorer: forceDownload,
})
if (!forceDownload) {
await this.$store.dispatch('electron/launch')
}
} catch (e) {
console.error(e)
}
this.loading = false
} else {
saveAs(url, fileName)
}
},
},
}
</script>
<style scoped></style>