Skip to content

Commit

Permalink
Merge pull request #308 from theweavrs/feature/protocol_setting_20190…
Browse files Browse the repository at this point in the history
…6091107

feat: add option to set default protocols
  • Loading branch information
agalwood authored Jun 10, 2019
2 parents c0cbfb5 + cdac883 commit 287c903
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 45 deletions.
4 changes: 4 additions & 0 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ export default class Application extends EventEmitter {
app.clearRecentDocuments()
})

this.on('application:setup-protocols-client', (protocols) => {
this.protocolManager.setup(protocols)
})

this.on('help:official-website', () => {
const url = 'https://motrix.app/'
shell.openExternal(url)
Expand Down
25 changes: 10 additions & 15 deletions src/main/core/ProtocolManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ export default class ProtocolManager extends EventEmitter {
handle (url) {
logger.info(`[Motrix] protocol url: ${url}`)

if (url.toLowerCase().startsWith('magnet:')) {
return this.handleMagnetProtocol(url)
}

if (url.toLowerCase().startsWith('thunder:')) {
return this.handleThunderProtocol(url)
}
this.handleMagnetAndThunderProtocol(url)

if (
url.toLowerCase().startsWith('mo:') ||
Expand All @@ -57,20 +51,21 @@ export default class ProtocolManager extends EventEmitter {
}
}

handleMagnetProtocol (url) {
handleMagnetAndThunderProtocol (url) {
if (!url) {
return
}
logger.error(`[Motrix] handleMagnetProtocol url: ${url}`)
let protocolTag = ''

global.application.sendCommandToAll('application:new-task', 'uri', url)
}
if (url.toLowerCase().startsWith('magnet:')) {
protocolTag = 'handleMagnetProtocol'
}

handleThunderProtocol (url) {
if (!url) {
return
if (url.toLowerCase().startsWith('thunder:')) {
protocolTag = 'handleThunderProtocol'
}
logger.error(`[Motrix] handleThunderProtocol url: ${url}`)

logger.error(`[Motrix] ${protocolTag} url: ${url}`)

global.application.sendCommandToAll('application:new-task', 'uri', url)
}
Expand Down
26 changes: 23 additions & 3 deletions src/renderer/components/Preference/Advanced.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
</div>
</el-col>
</el-form-item>
<el-form-item :label="`${$t('preferences.download-protocol')}: `" :label-width="formLabelWidth">
{{ $t('preferences.protocols-default-client') }}
<el-col class="form-item-sub" :span="24">
<el-switch
v-model="form.protocols.magnet"
:active-text="$t('preferences.protocols-magnet')"
>
</el-switch>
</el-col>
<el-col class="form-item-sub" :span="24">
<el-switch
v-model="form.protocols.thunder"
:active-text="$t('preferences.protocols-thunder')"
>
</el-switch>
</el-col>
</el-form-item>
<el-form-item :label="`${$t('preferences.proxy')}: `" :label-width="formLabelWidth">
<el-switch
v-model="form.useProxy"
Expand Down Expand Up @@ -181,7 +198,8 @@
lastCheckUpdateTime,
rpcSecret,
useProxy,
userAgent
userAgent,
protocols
} = config
const result = {
allProxy,
Expand All @@ -192,7 +210,8 @@
lastCheckUpdateTime,
rpcSecret,
useProxy,
userAgent
userAgent,
protocols
}
return result
}
Expand Down Expand Up @@ -298,7 +317,7 @@
btTracker: convertLineToComma(this.form.btTracker)
}
console.log('changed====》', data)
this.$store.dispatch('preference/save', data)
.then(() => {
this.$store.dispatch('app/fetchEngineOptions')
Expand All @@ -309,6 +328,7 @@
})
if (this.isRenderer()) {
this.$electron.ipcRenderer.send('command', 'application:setup-protocols-client', data.protocols)
}
})
},
Expand Down
17 changes: 0 additions & 17 deletions src/renderer/components/Preference/Lab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@
{{ $t('preferences.lab-warning') }}
</div>
</el-form-item>
<el-form-item :label="`${$t('preferences.download-protocol')}: `" :label-width="formLabelWidth">
{{ $t('preferences.protocols-default-client') }}
<el-col class="form-item-sub" :span="24">
<el-switch
v-model="form.protocols.magnet"
:active-text="$t('preferences.protocols-magnet')"
>
</el-switch>
</el-col>
<el-col class="form-item-sub" :span="24">
<el-switch
v-model="form.protocols.thunder"
:active-text="$t('preferences.protocols-thunder')"
>
</el-switch>
</el-col>
</el-form-item>
<el-form-item :label="`${$t('preferences.browser-extensions')}: `" :label-width="formLabelWidth">
<el-col class="form-item-sub" :span="24">
<a target="_blank" href="https://motrix.app/release/BaiduExporter.zip" rel="noopener noreferrer">
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/de/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': 'Sollen die Einstellungen auf die Werkseinstellungen unwiderruflich zurückgesetzt werden?',
'lab-warning': '⚠️ Die Aktivierung von experimentellen Funktionen kann zu App-Abstürzen oder Datenverlust führen!',
'download-protocol': 'Protokoll',
'support-more-download-protocols': 'Erweiterte Protokollunterstützung aktivieren',
'protocols-default-client': 'Als Standardclient für die folgenden Protokolle festlegen',
'protocols-magnet': 'Magnet [ magnet:// ]',
'protocols-thunder': 'Donner [ thunder:// ]',
'browser-extensions': 'Erweiterungen',
'baidu-exporter': 'Baidu Exporter',
'browser-extensions-tips': 'Von der Community bereitgestellt, ',
Expand Down
1 change: 0 additions & 1 deletion src/shared/locales/en-US/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default {
'factory-reset-confirm': 'Are you sure you want to revert to factory settings?',
'lab-warning': '⚠️ Enabling lab features may result in app crash or data loss, decide at you own risk!',
'download-protocol': 'Protocols',
'support-more-download-protocols': 'Enable support for more download protocols',
'protocols-default-client': 'Set as the default client for the following protocols',
'protocols-magnet': 'Magnet [ magnet:// ]',
'protocols-thunder': 'Thunder [ thunder:// ]',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/fa/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': 'آیا شما مطمئن هستید؟',
'lab-warning': '⚠️ فعالسازی امکانات آزمایشگاه ممکن است باعث کرش برنامه یا از دست دادن دیتا بشود، خودتون تصمیم بگیرین!',
'download-protocol': 'پروتکل',
'support-more-download-protocols': 'فعالسازی حمایت از پروتکل‌های دانلود بیشتر',
'protocols-default-client': 'به عنوان مشتری پیش فرض برای پروتکل های زیر تنظیم شده است',
'protocols-magnet': 'آهن ربا [ magnet:// ]',
'protocols-thunder': 'تندر [ thunder:// ]',
'browser-extensions': 'افزونه‌ها',
'baidu-exporter': 'BaiduExporter',
'browser-extensions-tips': 'تهیه شده توسط انجمن، ',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/fr/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': 'Êtes vous sûr de vouloir réinitialiser les paramètres',
'lab-warning': '⚠️ Activer les fonctionalités labo peut causer des crash ou la perte de données !',
'download-protocol': 'Protocole',
'support-more-download-protocols': 'Activer les protocoles de téléchargement suplémentaires',
'protocols-default-client': 'Définir comme client par défaut pour les protocoles suivants',
'protocols-magnet': 'Aimant [ magnet:// ]',
'protocols-thunder': 'Tonnerre [ thunder:// ]',
'browser-extensions': 'Extensions',
'baidu-exporter': 'BaiduExporter',
'browser-extensions-tips': 'Fourni par la communauté, ',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/ja/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': '本当に初期設定に戻しますか?',
'lab-warning': '⚠️ベータ機能をオンにするとアプリケーションの強制終了やデータが損失する可能性があります。自己責任でお願いします。',
'download-protocol': 'プロトコル',
'support-more-download-protocols': 'より多くのプロトコルを適用',
'protocols-default-client': '以下のプロトコルのデフォルトクライアントとして設定',
'protocols-magnet': '磁石 [ magnet:// ]',
'protocols-thunder': 'サンダー [ thunder:// ]',
'browser-extensions': 'ブラウザ拡張機能',
'baidu-exporter': 'バイドゥオンラインストレージ拡張機能',
'browser-extensions-tips': '他のユーザによって作成されたものです。動作は保証できません。',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/ko/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': '초기 설정으로 되돌리시겠습니까?',
'lab-warning': '⚠️ 실험실 기능을 활성화하면 앱 충돌이나 데이터 손실을 초래할 수 있으므로 직접 결정하십시오!',
'download-protocol': '프로토콜',
'support-more-download-protocols': '더 많은 다운로드 프로토콜 지원 허용',
'protocols-default-client': '다음 프로토콜의 기본 클라이언트로 설정',
'protocols-magnet': '자석 [ magnet:// ]',
'protocols-thunder': '우뢰 [ thunder:// ]',
'browser-extensions': '확장 프로그램',
'baidu-exporter': 'BaiduExporter',
'browser-extensions-tips': '커뮤니티에서 제공하는, ',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/pt-BR/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': 'Você tem certeza de que deseja resetar às configurações de fábrica?',
'lab-warning': '⚠️ Habilitar os recursos de lab pode causar perda de dados e fechar o app inesperadamete. Use por sua conta e risco!',
'download-protocol': 'Protocolo',
'support-more-download-protocols': 'Habilitar suporte a mais protocolos de download',
'protocols-default-client': 'Definir como cliente padrão para os seguintes protocolos',
'protocols-magnet': 'Magnético [ magnet:// ]',
'protocols-thunder': 'Trovão [ thunder:// ]',
'browser-extensions': 'Extensões',
'baidu-exporter': 'BaiduExporter',
'browser-extensions-tips': 'Fornecido pela comunidade, ',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/tr/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': 'Fabrika ayarlarına geri dönmek istediğinize emin misiniz?',
'lab-warning': '⚠️ Deneysel özellikleri etkinleştirmek uygulamanın çökmesine veya veri kaybına neden olabilir, kendiniz karar verin!',
'download-protocol': 'Protokol',
'support-more-download-protocols': 'Daha fazla indirme protokolü desteğini etkinleştir',
'protocols-default-client': 'Aşağıdaki protokoller için varsayılan istemci olarak ayarla',
'protocols-magnet': 'Mıknatıs [ magnet:// ]',
'protocols-thunder': 'gök gürültüsü [ thunder:// ]',
'browser-extensions': 'Eklentiler',
'baidu-exporter': 'BaiduExporter',
'browser-extensions-tips': 'Topluluk tarafından sağlanan, ',
Expand Down
1 change: 0 additions & 1 deletion src/shared/locales/zh-CN/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default {
'factory-reset-confirm': '你确定要恢复为初始设置吗?',
'lab-warning': '⚠️启用实验特性可能造成应用崩溃或数据丢失,请自行决定!',
'download-protocol': '下载协议',
'support-more-download-protocols': '支持更多下载协议',
'protocols-default-client': '设置为以下协议的默认客户端',
'protocols-magnet': '磁力链接 [ magnet:// ]',
'protocols-thunder': '迅雷链接 [ thunder:// ]',
Expand Down
4 changes: 3 additions & 1 deletion src/shared/locales/zh-TW/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export default {
'factory-reset-confirm': '您確定要還原為出廠預設值嗎?',
'lab-warning': '⚠️開啟實驗性功能可能會造成程式當機或資料遺失,請自己決定!',
'download-protocol': '下載協定',
'support-more-download-protocols': '支援更多下載協定',
'protocols-default-client': '設置為以下協議的默認客戶端',
'protocols-magnet': '磁鐵 [ magnet:// ]',
'protocols-thunder': '雷 [ thunder:// ]',
'browser-extensions': '瀏覽器擴充功能',
'baidu-exporter': '百度網盤助手',
'browser-extensions-tips': '社群提供的瀏覽器擴充功能「不保證可用性」,',
Expand Down

0 comments on commit 287c903

Please sign in to comment.