A full-featured download manager.
feat: sync bt tracker from github
Dr_rOotcb50d6709b99
diff --git a/src/renderer/api/Api.js b/src/renderer/api/Api.jsindex 32a09f42..54293d06 100644--- a/src/renderer/api/Api.js+++ b/src/renderer/api/Api.js@@ -9,6 +9,10 @@ import {changeKeysToCamelCase,changeKeysToKebabCase} from '@shared/utils'+import {+ BEST_TRACKERS_URL,+ BEST_TRACKERS_IP_URL+} from '@shared/constants'const application = remote.getGlobal('application')@@ -268,4 +272,17 @@ export default class Api {stopPowerSaveBlocker () {application.energyManager.stopPowerSaveBlocker()}++ fetchBtTrackerFromGitHub () {+ const now = Date.now()+ const promises = [+ fetch(`${BEST_TRACKERS_IP_URL}?t=${now}`).then((res) => res.text()),+ fetch(`${BEST_TRACKERS_URL}?t=${now}`).then((res) => res.text())+ ]++ return Promise.all(promises).then((values) => {+ let result = values.join('\r\n').replace(/^\s*[\r\n]/gm, '')+ return result+ })+ }}diff --git a/src/renderer/components/Icons/sync.js b/src/renderer/components/Icons/sync.jsnew file mode 100644index 00000000..ddb268a6--- /dev/null+++ b/src/renderer/components/Icons/sync.js@@ -0,0 +1,22 @@+import Icon from '@/components/Icons/Icon'++Icon.register({+ 'sync': {+ 'width': 24,+ 'height': 24,+ 'raw': `<g stroke-linecap="round" stroke-linejoin="round" stroke-width="2">+ <path fill="none" stroke-miterlimit="10" d="M3,14V4 c0-0.552,0.448-1,1-1h16c0.552,0,1,0.448,1,1v6"></path>+ <path fill="none" stroke="#111111" stroke-miterlimit="10" d="M10,18H1v0 c0,1.657,1.343,3,3,3h6"></path>+ <path data-cap="butt" data-color="color-2" fill="none" stroke-miterlimit="10" d="M14.126,17 c0.444-1.725,2.01-3,3.874-3c1.48,0,2.772,0.804,3.464,1.999"></path>+ <polygon data-color="color-2" data-stroke="none" points="23.22,13.649 22.792,18 18.522,17.061 " stroke-linejoin="miter" stroke-linecap="square" stroke="none"></polygon>+ <path data-cap="butt" data-color="color-2" fill="none" stroke-miterlimit="10" d="M21.874,20 c-0.444,1.725-2.01,3-3.874,3c-1.48,0-2.772-0.804-3.464-1.999"></path>+ <polygon data-color="color-2" data-stroke="none" points="12.78,23.351 13.208,19 17.478,19.939 " stroke-linejoin="miter" stroke-linecap="square" stroke="none"></polygon>+ </g>`,+ 'g': {+ 'stroke': 'currentColor',+ 'stroke-linecap': 'round',+ 'stroke-linejoin': 'round',+ 'stroke-width': '2'+ }+ }+})diff --git a/src/renderer/components/Preference/Advanced.vue b/src/renderer/components/Preference/Advanced.vueindex 1c4d3dce..d4cd3e7a 100644--- a/src/renderer/components/Preference/Advanced.vue+++ b/src/renderer/components/Preference/Advanced.vue@@ -56,6 +56,27 @@:placeholder="`${$t('preferences.bt-tracker-input-tips')}`"v-model="form.btTracker"></el-input>+ <div class="sync-tracker">+ <el-tooltip+ class="item"+ effect="dark"+ :content="$t('preferences.sync-tracker-tips')"+ placement="bottom"+ >+ <el-button+ @click="syncTrackerFromGitHub"+ >+ <mo-icon+ name="refresh"+ width="12"+ height="12"+ :spin="true"+ v-if="isSyncTracker"+ />+ <mo-icon name="sync" width="12" height="12" v-else />+ </el-button>+ </el-tooltip>+ </div></div><div class="el-form-item__info" style="margin-top: 8px;">{{ $t('preferences.bt-tracker-tips') }}@@ -136,6 +157,8 @@import {convertToTextRows} from '@shared/utils'+ import '@/components/Icons/sync'+ import '@/components/Icons/refresh'const initialForm = (config) => {const {@@ -171,6 +194,7 @@return {formLabelWidth: '23%',form: initialForm(this.$store.state.preference.config),+ isSyncTracker: false,rules: {},color: '#c00',locales: availableLanguages@@ -202,6 +226,17 @@this.form.theme = themethis.$electron.ipcRenderer.send('command', 'application:change-theme', theme)},+ syncTrackerFromGitHub () {+ this.isSyncTracker = true+ this.$store.dispatch('preference/fetchBtTracker')+ .then((data) => {+ console.log('syncTrackerFromGitHub data====>', data)+ this.form.btTracker = data+ })+ .finally(() => {+ this.isSyncTracker = false+ })+ },onUseProxyChange (flag) {this.form.allProxy = flag ? this.form.allProxyBackup : ''},@@ -250,6 +285,14 @@</script><style lang="scss">+.bt-tracker {+ position: relative;+ .sync-tracker {+ position: absolute;+ top: 8px;+ right: 8px;+ }+}.ua-group {margin-top: 8px;}diff --git a/src/renderer/components/Preference/Index.vue b/src/renderer/components/Preference/Index.vueindex 4062bf9a..517548d8 100644--- a/src/renderer/components/Preference/Index.vue+++ b/src/renderer/components/Preference/Index.vue@@ -28,6 +28,19 @@font-weight: $--font-weight-secondary;color: $--color-text-regular;}+ .el-form-item {+ a {+ color: $--color-text-regular;+ text-decoration: none;+ &:hover {+ color: $--color-text-primary;+ text-decoration: underline;+ }+ &:active {+ color: $--color-text-primary;+ }+ }+ }.el-form-item.el-form-item--mini {margin-bottom: 24px;}@@ -39,14 +52,6 @@&:last-of-type {margin-bottom: 0;}- a {- color: $--color-text-regular;- text-decoration: none;- &:hover {- color: $--color-text-primary;- text-decoration: underline;- }- }}}.form-actions {diff --git a/src/renderer/store/modules/preference.js b/src/renderer/store/modules/preference.jsindex f08d1abd..80409634 100644--- a/src/renderer/store/modules/preference.js+++ b/src/renderer/store/modules/preference.js@@ -21,13 +21,22 @@ const actions = {})})},- save ({ commit }, config) {+ save ({ commit }, data) {+ let { btTracker } = data+ btTracker = btTracker.trim().replace(/(?:\r\n|\r|\n)/g, ',')+ const config = {+ ...data,+ btTracker+ }commit('UPDATE_PREFERENCE_DATA', config)return api.savePreference(config)},changeThemeConfig ({ commit }, theme) {commit('UPDATE_PREFERENCE_DATA', { theme })},+ fetchBtTracker () {+ return api.fetchBtTrackerFromGitHub()+ },toggleEngineMode () {}diff --git a/src/shared/constants.js b/src/shared/constants.jsindex d4605d99..c3e4b498 100644--- a/src/shared/constants.js+++ b/src/shared/constants.js@@ -1,2 +1,5 @@export const LIGHT_THEME = 'light'export const DARK_THEME = 'dark'++export const BEST_TRACKERS_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt'+export const BEST_TRACKERS_IP_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt'diff --git a/src/shared/utils.js b/src/shared/utils.jsindex 122d03d6..7b6dffaf 100644--- a/src/shared/utils.js+++ b/src/shared/utils.js@@ -322,11 +322,18 @@ export function compactUndefined (arr = []) {}export function splitTextRows (text = '') {- let result = text.replace(/\r\n/g, '\n').split('\n') || []+ let result = text.replace(/(?:\r\n|\r|\n)/g, '\n').split('\n') || []result = result.map((row) => row.trim())return result}+export function convertToTextRows (text = '') {+ let arr = text.split(',')+ arr = arr.map((row) => row.trim())+ const result = arr.join('\n')+ return result+}+const audioSuffix = ['.aac', '.mp3', '.ogg', '.ape', '.flac', '.m4a', '.wav', '.wma', '.flav']const videoSuffix = ['.avi', '.mkv', '.rmvb', '.wmv', '.mp4', '.m4a', '.vob', '.mov', '.mpg']export function isAudioOrVideo (uri = '') {