mirror of
https://github.com/CzBiX/qb-web.git
synced 2026-04-13 18:01:17 +08:00
15
src/App.vue
15
src/App.vue
@@ -74,6 +74,8 @@
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import { mapGetters, mapState, mapMutations } from 'vuex';
|
||||
import { registerProtocolHandler, checkDownloadUrl } from './protocolHandler';
|
||||
|
||||
import GlobalDialog from './components/GlobalDialog.vue';
|
||||
import GlobalSnackBar from './components/GlobalSnackBar.vue';
|
||||
|
||||
@@ -145,7 +147,20 @@ export default class App extends Vue {
|
||||
return this.$vuetify.breakpoint.xsOnly;
|
||||
}
|
||||
|
||||
initProtocolHandler() {
|
||||
registerProtocolHandler();
|
||||
const url = checkDownloadUrl();
|
||||
|
||||
if (url) {
|
||||
this.setPasteUrl({
|
||||
url,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async created() {
|
||||
this.initProtocolHandler();
|
||||
|
||||
await this.getInitData();
|
||||
appWrapEl = (this.$refs.app as any).$el.querySelector('.v-application--wrap');
|
||||
appWrapEl.addEventListener('paste', this.onPaste);
|
||||
|
||||
@@ -317,7 +317,7 @@ export default class AddForm extends Vue {
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
@Watch('pasteUrl')
|
||||
@Watch('pasteUrl', {immediate: true})
|
||||
onPasteUrl(v: string) {
|
||||
if (!v) {
|
||||
return;
|
||||
|
||||
29
src/protocolHandler.ts
Normal file
29
src/protocolHandler.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
function registerProtocolHandler() {
|
||||
if (!('registerProtocolHandler' in navigator)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
navigator.registerProtocolHandler('magnet', location.origin + '#url=%s', document.title);
|
||||
} catch (e) {
|
||||
console.log('Register protocol handler failed.', e);
|
||||
}
|
||||
}
|
||||
|
||||
function checkDownloadUrl() {
|
||||
if (!location.hash) {
|
||||
return null
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(location.hash.substring(1));
|
||||
const url = params.get('url')
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
params.delete('url');
|
||||
location.hash = '#' + params.toString()
|
||||
return url
|
||||
}
|
||||
|
||||
export { registerProtocolHandler, checkDownloadUrl };
|
||||
Reference in New Issue
Block a user