-
Notifications
You must be signed in to change notification settings - Fork 221
Add magnet protocol integration and default-handler status #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -807,3 +807,10 @@ stop.name=自动关闭时间 | |
| stop.description=在此选项设置的时间(秒)后关闭应用. 如果设置为 0, 此功能将禁用. | ||
| truncate-console-readout.name=缩短控制台输出内容 | ||
| truncate-console-readout.description=缩短控制台输出的内容在一行中. | ||
| [global] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file already has a "global" section. You should place newly added entries near the related adjacent entries in the UI similar to what you did in the |
||
| Handle magnet links=处理磁力链接 | ||
| Open default apps settings=打开系统默认应用设置 | ||
| Magnet protocol is enabled but this app is not the default handler. Please update system settings.=磁力协议已启用,但当前应用不是默认处理器,请在系统设置中修改。 | ||
| Is default magnet handler=是否为默认磁力处理器 | ||
| Yes=是 | ||
| No=否 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,6 +233,12 @@ | |
| 'Open Browser DevTools': 'Open Browser DevTools', | ||
| 'Swipe Gesture': 'Swipe Gesture', | ||
| 'Change Tasks Order by Drag-and-drop': 'Change Tasks Order by Drag-and-drop', | ||
| 'Handle magnet links': 'Handle magnet links', | ||
| 'Is default magnet handler': 'Is default magnet handler', | ||
| 'Yes': 'Yes', | ||
| 'No': 'No', | ||
| 'Magnet protocol is enabled but this app is not the default handler. Please update system settings.': 'Magnet protocol is enabled but this app is not the default handler. Please update system settings.', | ||
| 'Open default apps settings': 'Open default apps settings', | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above entries are missing: |
||
| 'Action After Creating New Tasks': 'Action After Creating New Tasks', | ||
| 'Navigate to Task List Page': 'Navigate to Task List Page', | ||
| 'Navigate to Task Detail Page': 'Navigate to Task Detail Page', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,8 @@ | |
| config.execCommandOptionsOnStartup = 'as-detached-process'; | ||
| } | ||
|
|
||
| config.enableMagnetProtocol = originalConfig.enableMagnetProtocol !== false; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| return config; | ||
| }; | ||
|
|
||
|
|
@@ -70,6 +72,7 @@ | |
| importNativeSetting(settings, 'execCommandOnStartup', $scope.setExecCommandOnStartup); | ||
| importNativeSetting(settings, 'execCommandArgumentsOnStartup', $scope.setExecCommandArgumentsOnStartup); | ||
| importNativeSetting(settings, 'execCommandOptionsOnStartup', $scope.setExecCommandOptionsOnStartup); | ||
| importNativeSetting(settings, 'enableMagnetProtocol', $scope.setEnableMagnetProtocol); | ||
| ariaNgSettingService.importAllOptions(settings); | ||
| }; | ||
|
|
||
|
|
@@ -149,6 +152,7 @@ | |
| isSupportReconnect: aria2SettingService.canReconnect(), | ||
| isSupportBlob: ariaNgFileService.isSupportBlob(), | ||
| isSupportDarkMode: ariaNgSettingService.isBrowserSupportDarkMode(), | ||
| magnetProtocolStatus: null, | ||
| importSettings: null, | ||
| exportSettings: null, | ||
| exportSettingsCopied: false, | ||
|
|
@@ -439,6 +443,36 @@ | |
| } | ||
| }; | ||
|
|
||
| $scope.setEnableMagnetProtocol = function (value) { | ||
| var status = ariaNgNativeElectronService.setEnableMagnetProtocol(value); | ||
|
|
||
| if (status) { | ||
| $scope.context.magnetProtocolStatus = status; | ||
| } | ||
|
|
||
| if (value && status && !status.isDefault) { | ||
| ariaNgCommonService.showInfo('Default magnet app', 'Magnet protocol is enabled but this app is not the default handler. Please update system settings.'); | ||
| } | ||
| }; | ||
|
|
||
| $scope.openSystemDefaultAppsSetting = function () { | ||
| ariaNgNativeElectronService.openSystemDefaultAppsSetting().then(function (success) { | ||
| if (!success) { | ||
| ariaNgCommonService.showError('This feature is not supported on your system.'); | ||
| } | ||
| }).catch(function () { | ||
| ariaNgCommonService.showError('Failed to open system settings.'); | ||
| }); | ||
| }; | ||
|
|
||
| ariaNgNativeElectronService.getMagnetProtocolStatusAsync().then(function (status) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In addition, the surrounding code in this area is all assigning values to |
||
| if (!status) { | ||
| return; | ||
| } | ||
|
|
||
| $scope.context.magnetProtocolStatus = status; | ||
| }); | ||
|
|
||
| $scope.browseAndSetExecCommandOnStartup = function () { | ||
| ariaNgNativeElectronService.showOpenFileDialogAsync([{ | ||
| name: ariaNgLocalizationService.getLocalizedText('All Files'), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,35 @@ | |
| </select> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this option should be placed after "Default Window Position", as that better aligns with typical user expectations. |
||
| <div class="setting-key setting-key-without-desc col-sm-4"> | ||
| <span translate>Handle magnet links</span> | ||
| </div> | ||
| <div class="setting-value col-sm-8"> | ||
| <div class="input-group" ng-if="context.magnetProtocolStatus"> | ||
| <select class="form-control" ng-model="context.nativeSettings.enableMagnetProtocol" | ||
| ng-change="setEnableMagnetProtocol(context.nativeSettings.enableMagnetProtocol)" | ||
| ng-options="option.value as (option.name | translate) for option in context.trueFalseOptions"> | ||
| </select> | ||
| <span class="input-group-addon"> | ||
| <span translate>Is default magnet handler</span>: | ||
| <span ng-if="context.magnetProtocolStatus.isDefault" translate>Yes</span> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would using bootstrap label here provide a better user experience?
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I suggest placing the "Yes" and "No" entries earlier in the language file, for example near "Enabled" and "Disabled". |
||
| <span ng-if="!context.magnetProtocolStatus.isDefault" translate>No</span> | ||
| </span> | ||
| <span class="input-group-btn"> | ||
| <button class="btn btn-default" type="button" ng-click="openSystemDefaultAppsSetting()" | ||
| ng-disabled="!context.nativeSettings.enableMagnetProtocol || context.magnetProtocolStatus.isDefault"> | ||
| <span translate>Open default apps settings</span> | ||
| </button> | ||
| </span> | ||
| </div> | ||
| <select class="form-control" style="width: 100%;" ng-if="!context.magnetProtocolStatus" | ||
| ng-model="context.nativeSettings.enableMagnetProtocol" | ||
| ng-change="setEnableMagnetProtocol(context.nativeSettings.enableMagnetProtocol)" | ||
| ng-options="option.value as (option.name | translate) for option in context.trueFalseOptions"> | ||
| </select> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="setting-key setting-key-without-desc col-sm-4"> | ||
| <span translate>RPC List Display Order</span> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,9 @@ const userSettingsSchema = { | |
| execDetachedCommandOnStartup: { | ||
| type: 'boolean' | ||
| }, | ||
| enableMagnetProtocol: { | ||
| type: 'boolean' | ||
| }, | ||
| lastCheckUpdatesTime: { | ||
| type: 'number' | ||
| } | ||
|
|
@@ -54,6 +57,7 @@ let config = { | |
| execCommandOnStartup: userSettingsStore.get('execCommandOnStartup'), | ||
| execCommandArgumentsOnStartup: userSettingsStore.get('execCommandArgumentsOnStartup'), | ||
| execDetachedCommandOnStartup: userSettingsStore.get('execDetachedCommandOnStartup', false), | ||
| enableMagnetProtocol: userSettingsStore.get('enableMagnetProtocol', true), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest using |
||
| lastCheckUpdatesTime: userSettingsStore.get('lastCheckUpdatesTime') || 0, | ||
| save: function (item) { | ||
| if (item && this[item] !== undefined) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const electron = require('electron'); | ||
|
|
||
| const core = require('../core'); | ||
|
|
@@ -14,10 +15,55 @@ const localfs = require('../lib/localfs'); | |
| const bittorrent = require('../lib/bittorrent'); | ||
|
|
||
| const shell = electron.shell; | ||
| const app = electron.app; | ||
| const nativeTheme = electron.nativeTheme; | ||
| const dialog = electron.dialog; | ||
| const ipcMain = electron.ipcMain; | ||
|
|
||
| let setMagnetProtocolEnabled = function (enabled) { | ||
| try { | ||
| if (enabled) { | ||
| if (app.isPackaged) { | ||
| return app.setAsDefaultProtocolClient('magnet'); | ||
| } | ||
|
|
||
| if (process.defaultApp && process.argv.length > 1) { | ||
| return app.setAsDefaultProtocolClient('magnet', process.execPath, [path.resolve(process.argv[1])]); | ||
| } | ||
|
|
||
| return app.setAsDefaultProtocolClient('magnet'); | ||
| } | ||
|
|
||
| if (app.isPackaged) { | ||
| return app.removeAsDefaultProtocolClient('magnet'); | ||
| } | ||
|
|
||
| if (process.defaultApp && process.argv.length > 1) { | ||
| return app.removeAsDefaultProtocolClient('magnet', process.execPath, [path.resolve(process.argv[1])]); | ||
| } | ||
|
|
||
| return app.removeAsDefaultProtocolClient('magnet'); | ||
| } catch (ex) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| let isDefaultMagnetProtocol = function () { | ||
| try { | ||
| if (app.isPackaged) { | ||
| return app.isDefaultProtocolClient('magnet'); | ||
| } | ||
|
|
||
| if (process.defaultApp && process.argv.length > 1) { | ||
| return app.isDefaultProtocolClient('magnet', process.execPath, [path.resolve(process.argv[1])]); | ||
| } | ||
|
|
||
| return app.isDefaultProtocolClient('magnet'); | ||
| } catch (ex) { | ||
| return false; | ||
| } | ||
| }; | ||
|
|
||
| ipcMain.on('render-sync-get-runtime-environment', (event) => { | ||
| if (!process || !process.versions) { | ||
| return null; | ||
|
|
@@ -116,7 +162,8 @@ ipcMain.on('render-sync-get-native-config', (event) => { | |
| minimizedToTray: config.minimizedToTray, | ||
| execCommandOnStartup: config.execCommandOnStartup, | ||
| execCommandArgumentsOnStartup: config.execCommandArgumentsOnStartup, | ||
| execDetachedCommandOnStartup: config.execDetachedCommandOnStartup | ||
| execDetachedCommandOnStartup: config.execDetachedCommandOnStartup, | ||
| enableMagnetProtocol: config.enableMagnetProtocol | ||
| }; | ||
| }); | ||
|
|
||
|
|
@@ -145,6 +192,25 @@ ipcMain.on('render-set-native-config-exec-detached-command-on-startup', (event, | |
| config.save('execDetachedCommandOnStartup'); | ||
| }); | ||
|
|
||
| ipcMain.on('render-set-native-config-enable-magnet-protocol', (event, value) => { | ||
| config.enableMagnetProtocol = !!value; | ||
| config.save('enableMagnetProtocol'); | ||
| const registered = setMagnetProtocolEnabled(config.enableMagnetProtocol); | ||
|
|
||
| event.returnValue = { | ||
| enabled: config.enableMagnetProtocol, | ||
| isDefault: isDefaultMagnetProtocol(), | ||
| registered: registered | ||
| }; | ||
| }); | ||
|
|
||
| ipcMain.handle('render-get-native-config-magnet-protocol-status', () => { | ||
| return { | ||
| enabled: !!config.enableMagnetProtocol, | ||
| isDefault: isDefaultMagnetProtocol() | ||
| }; | ||
| }); | ||
|
|
||
| ipcMain.handle('render-get-native-config-last-check-updates-time', (event) => { | ||
| return config.lastCheckUpdatesTime; | ||
| }); | ||
|
|
@@ -225,6 +291,24 @@ ipcMain.on('render-open-external-url', (event, url) => { | |
| shell.openExternal(url); | ||
| }); | ||
|
|
||
| ipcMain.handle('render-open-system-default-apps-setting', async () => { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This project does not use the |
||
| try { | ||
| if (process.platform === 'win32') { | ||
| await shell.openExternal('ms-settings:defaultapps'); | ||
| return true; | ||
| } | ||
|
|
||
| if (process.platform === 'darwin') { | ||
| await shell.openExternal('x-apple.systempreferences:com.apple.preference.general'); | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } catch (ex) { | ||
| return false; | ||
| } | ||
| }); | ||
|
|
||
| ipcMain.on('render-sync-get-package-file-content', (event, path) => { | ||
| event.returnValue = localfs.readPackageFile(path); | ||
| }); | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't learn a language, please do not submit translation file for it, as inaccurate translations may mislead other users.
You may leave these entries empty in these languages.