Skip to content

Commit a1eb489

Browse files
authored
Merge pull request #420 from agalwood/feature/custom_tracker_source_201909091524
feat: user config custom tracker source
2 parents c0a2b50 + c1ed827 commit a1eb489

File tree

5 files changed

+42
-22
lines changed

5 files changed

+42
-22
lines changed

src/main/Launcher.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {
1010
parseArgvAsUrl,
1111
parseArgvAsFile
1212
} from './utils'
13-
14-
const EMPTY_STRING = ''
13+
import { EMPTY_STRING } from '@shared/constants'
1514

1615
export default class Launcher extends EventEmitter {
1716
constructor () {

src/main/core/ConfigManager.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import {
88
getSessionPath,
99
getUserDownloadsPath
1010
} from '../utils/index'
11+
import {
12+
EMPTY_STRING,
13+
TRACKERS_ALL_URL,
14+
TRACKERS_ALL_IP_URL
15+
} from '@shared/constants'
1116

1217
export default class ConfigManager {
1318
constructor () {
@@ -33,7 +38,7 @@ export default class ConfigManager {
3338
this.systemConfig = new Store({
3439
name: 'system',
3540
defaults: {
36-
'all-proxy': '',
41+
'all-proxy': EMPTY_STRING,
3742
'allow-overwrite': true,
3843
'auto-file-renaming': true,
3944
'bt-tracker': tracker.join(','),
@@ -49,7 +54,7 @@ export default class ConfigManager {
4954
'min-split-size': '1M',
5055
'pause': true,
5156
'rpc-listen-port': 16800,
52-
'rpc-secret': '',
57+
'rpc-secret': EMPTY_STRING,
5358
'seed-time': 60,
5459
'split': 16,
5560
'user-agent': 'Transmission/2.94'
@@ -69,7 +74,7 @@ export default class ConfigManager {
6974
// }
7075
// },
7176
defaults: {
72-
'all-proxy-backup': '',
77+
'all-proxy-backup': EMPTY_STRING,
7378
'auto-check-update': is.macOS(),
7479
'hide-app-menu': is.windows() || is.linux(),
7580
'last-check-update-time': 0,
@@ -83,6 +88,10 @@ export default class ConfigManager {
8388
'session-path': getSessionPath(),
8489
'task-notification': true,
8590
'theme': 'auto',
91+
'tracker-source': [
92+
TRACKERS_ALL_IP_URL,
93+
TRACKERS_ALL_URL
94+
],
8695
'update-channel': 'latest',
8796
'use-proxy': false,
8897
'window-state': {}
@@ -98,6 +107,13 @@ export default class ConfigManager {
98107
if (this.getUserConfig('open-at-login') !== openAtLogin) {
99108
this.setUserConfig('open-at-login', openAtLogin)
100109
}
110+
111+
if (this.getUserConfig('tracker-source').length === 0) {
112+
this.setUserConfig('tracker-source', [
113+
TRACKERS_ALL_IP_URL,
114+
TRACKERS_ALL_URL
115+
])
116+
}
101117
}
102118

103119
getSystemConfig (key, defaultValue) {

src/renderer/api/Api.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
changeKeysToCamelCase,
1111
changeKeysToKebabCase
1212
} from '@shared/utils'
13-
import {
14-
BEST_TRACKERS_URL,
15-
BEST_TRACKERS_IP_URL
16-
} from '@shared/constants'
13+
import { EMPTY_STRING } from '@shared/constants'
1714

1815
const application = remote.getGlobal('application')
1916

@@ -312,16 +309,18 @@ export default class Api {
312309
application.energyManager.stopPowerSaveBlocker()
313310
}
314311

315-
fetchBtTrackerFromGitHub () {
312+
async fetchBtTrackerFromGitHub (source) {
313+
if (isEmpty(source)) {
314+
return EMPTY_STRING
315+
}
316+
316317
const now = Date.now()
317-
const promises = [
318-
fetch(`${BEST_TRACKERS_IP_URL}?t=${now}`).then((res) => res.text()),
319-
fetch(`${BEST_TRACKERS_URL}?t=${now}`).then((res) => res.text())
320-
]
321-
322-
return Promise.all(promises).then((values) => {
323-
let result = values.join('\r\n').replace(/^\s*[\r\n]/gm, '')
324-
return result
318+
const promises = source.map((url) => {
319+
return fetch(`${url}?t=${now}`).then((res) => res.text())
325320
})
321+
322+
const values = await Promise.all(promises)
323+
let result = values.join('\r\n').replace(/^\s*[\r\n]/gm, '')
324+
return result
326325
}
327326
}

src/renderer/store/modules/preference.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ const actions = {
3434
changeThemeConfig ({ commit }, theme) {
3535
commit('UPDATE_PREFERENCE_DATA', { theme })
3636
},
37-
fetchBtTracker () {
38-
return api.fetchBtTrackerFromGitHub()
37+
fetchBtTracker ({ state }) {
38+
const { trackerSource = [] } = state.config
39+
return api.fetchBtTrackerFromGitHub(trackerSource)
3940
},
4041
toggleEngineMode () {
4142

src/shared/constants.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
export const EMPTY_STRING = ''
2+
13
export const LIGHT_THEME = 'light'
24
export const DARK_THEME = 'dark'
35

4-
export const BEST_TRACKERS_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt'
5-
export const BEST_TRACKERS_IP_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt'
6+
// https://github.com/ngosang/trackerslist
7+
export const TRACKERS_BEST_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt'
8+
export const TRACKERS_BEST_IP_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt'
9+
export const TRACKERS_ALL_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt'
10+
export const TRACKERS_ALL_IP_URL = 'https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all_ip.txt'
611

712
// One Week
813
export const AUTO_CHECK_UPDATE_INTERVAL = 7 * 24 * 60 * 60 * 1000

0 commit comments

Comments
 (0)