Skip to content

Commit

Permalink
Merge pull request #925 from agalwood/hotfix/app_hang_20210507
Browse files Browse the repository at this point in the history
  • Loading branch information
agalwood committed May 7, 2021
2 parents 9461381 + 53ec0b1 commit e939f9e
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 102 deletions.
16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Motrix",
"version": "1.6.8",
"version": "1.6.9",
"description": "A full-featured download manager",
"homepage": "https://motrix.app",
"author": {
Expand Down Expand Up @@ -92,18 +92,10 @@
},
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"x64",
"arm64"
]
},
{
"target": "zip",
"arch": [
"x64",
"arm64"
"x64"
]
}
],
Expand Down Expand Up @@ -240,7 +232,7 @@
"css-loader": "^5.2.4",
"css-minimizer-webpack-plugin": "^2.0.0",
"del": "^6.0.0",
"electron": "^11.4.4",
"electron": "^11.4.5",
"electron-builder": "22.10.5",
"electron-builder-notarize": "^1.2.0",
"electron-devtools-installer": "^3.2.0",
Expand All @@ -266,7 +258,7 @@
"vue-style-loader": "^4.1.3",
"vue-template-compiler": "^2.6.12",
"webpack": "^5.36.2",
"webpack-cli": "^4.6.0",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "^3.11.2",
"webpack-hot-middleware": "^2.25.0",
"webpack-merge": "^5.7.3",
Expand Down
64 changes: 44 additions & 20 deletions src/main/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class Application extends EventEmitter {
}

init () {
this.configManager = new ConfigManager()
this.configManager = this.initConfigManager()

this.locale = this.configManager.getLocale()
this.localeManager = setupLocaleManager(this.locale)
Expand Down Expand Up @@ -84,6 +84,22 @@ export default class Application extends EventEmitter {
this.emit('application:initialized')
}

initConfigManager () {
this.configListeners = {}
return new ConfigManager()
}

offConfigListeners () {
try {
Object.keys(this.configListeners).forEach((key) => {
this.configListeners[key]()
})
} catch (e) {
logger.warn('[Motrix] offConfigListeners===>', e)
}
this.configListeners = {}
}

setupApplicationMenu () {
this.menuManager = new MenuManager()
this.menuManager.setup(this.locale)
Expand Down Expand Up @@ -172,7 +188,9 @@ export default class Application extends EventEmitter {
}

watchTraySpeedometerEnabledChange () {
this.configManager.userConfig.onDidChange('tray-speedometer', async (newValue, oldValue) => {
const { userConfig } = this.configManager
const key = 'tray-speedometer'
this.configListeners[key] = userConfig.onDidChange('tray-speedometer', async (newValue, oldValue) => {
logger.info('[Motrix] detected tray speedometer value change event:', newValue, oldValue)
this.trayManager.handleSpeedometerEnableChange(newValue)
})
Expand Down Expand Up @@ -230,10 +248,11 @@ export default class Application extends EventEmitter {
}

watchUPnPPortsChange () {
const { systemConfig } = this.configManager
const watchKeys = ['listen-port', 'dht-listen-port']

watchKeys.forEach((key) => {
this.configManager.systemConfig.onDidChange(key, async (newValue, oldValue) => {
this.configListeners[key] = systemConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info('[Motrix] detected port change event:', key, newValue, oldValue)
const enable = this.configManager.getUserConfig('enable-upnp')
if (!enable) {
Expand All @@ -254,7 +273,9 @@ export default class Application extends EventEmitter {
}

watchUPnPEnabledChange () {
this.configManager.userConfig.onDidChange('enable-upnp', async (newValue, oldValue) => {
const { userConfig } = this.configManager
const key = 'enable-upnp'
this.configListeners[key] = userConfig.onDidChange(key, async (newValue, oldValue) => {
logger.info('[Motrix] detected enable-upnp value change event:', newValue, oldValue)
if (newValue) {
this.startUPnPMapping()
Expand Down Expand Up @@ -546,12 +567,27 @@ export default class Application extends EventEmitter {
})
}

relaunch () {
this.stop()
async relaunch () {
await this.stop()
app.relaunch()
app.exit()
}

async resetSession () {
await this.stopEngine()

app.clearRecentDocuments()

const sessionPath = this.configManager.getUserConfig('session-path') || getSessionPath()
setTimeout(() => {
unlink(sessionPath, function (err) {
logger.info('[Motrix] Removed the download seesion file:', err)
})

this.engine.start()
}, 3000)
}

savePreference (config = {}) {
logger.info('[Motrix] save preference:', config)
const { system, user } = config
Expand Down Expand Up @@ -602,22 +638,10 @@ export default class Application extends EventEmitter {
this.hide(page)
})

this.on('application:reset-session', () => {
this.engine.stop()

app.clearRecentDocuments()

const sessionPath = this.configManager.getUserConfig('session-path') || getSessionPath()
setTimeout(() => {
unlink(sessionPath, function (err) {
logger.info('[Motrix] Removed the download seesion file:', err)
})

this.engine.start()
}, 3000)
})
this.on('application:reset-session', () => this.resetSession())

this.on('application:reset', () => {
this.offConfigListeners()
this.configManager.reset()
this.relaunch()
})
Expand Down
5 changes: 4 additions & 1 deletion src/main/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export default class Engine {

const binPath = this.getBinPath()
const args = this.getStartArgs()
this.instance = spawn(binPath, args)
this.instance = spawn(binPath, args, {
windowsHide: false,
stdio: is.dev() ? 'pipe' : 'ignore'
})
const pid = this.instance.pid.toString()
this.writePidFile(pidPath, pid)

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/About/Copyright.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<el-row class="copyright">
<el-col :span="6" class="copyright-left">
<a target="_blank" rel="noopener noreferrer" href="https://motrix.app/">
&copy;2020 Motrix
&copy;2021 Motrix
</a>
</el-col>
<el-col :span="18" class="copyright-right">
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/Task/TaskItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
}
.task-name {
color: #505753;
margin-bottom: 32px;
margin-right: 240px;
margin-bottom: 1.5rem;
margin-right: 220px;
word-break: break-all;
min-height: 26px;
&> span {
Expand Down
97 changes: 58 additions & 39 deletions src/renderer/components/Task/TaskProgressInfo.vue
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
<template>
<el-row class="task-progress-info">
<el-col :span="8" class="task-progress-info-left">
<el-col :span="6" class="task-progress-info-left">
<div v-if="task.completedLength > 0 || task.totalLength > 0">
<span>{{ task.completedLength | bytesToSize }}</span>
<span v-if="task.totalLength > 0"> / {{ task.totalLength | bytesToSize }}</span>
</div>
</el-col>
<el-col :span="16" class="task-progress-info-right">
<el-col :span="18" class="task-progress-info-right">
<div class="task-speed-info" v-if="isActive">
<span class="task-speed-text" v-if="isBT">
<i><mo-icon name="arrow-up" width="10" height="10" /></i>
<i>{{ task.uploadSpeed | bytesToSize }}/s</i>
</span>
<span class="task-speed-text">
<i><mo-icon name="arrow-down" width="10" height="10" /></i>
<i>{{ task.downloadSpeed | bytesToSize }}/s</i>
</span>
<span class="task-speed-text" v-if="remaining > 0">
{{
remaining | timeFormat({
prefix: $t('task.remaining-prefix'),
i18n: {
'gt1d': $t('app.gt1d'),
'hour': $t('app.hour'),
'minute': $t('app.minute'),
'second': $t('app.second')
}
})
}}
</span>
<span class="task-speed-text" v-if="isBT">
<i><mo-icon name="magnet" width="10" height="10" /></i>
<i>{{ task.numSeeders }}</i>
</span>
<span class="task-speed-text">
<i><mo-icon name="node" width="10" height="10" /></i>
<i>{{ task.connections }}</i>
</span>
<div class="task-speed-text" v-if="isBT">
<i><mo-icon name="arrow-up" width="10" height="14" /></i>
<span>{{ task.uploadSpeed | bytesToSize }}/s</span>
</div>
<div class="task-speed-text">
<i><mo-icon name="arrow-down" width="10" height="14" /></i>
<span>{{ task.downloadSpeed | bytesToSize }}/s</span>
</div>
<div class="task-speed-text" v-if="remaining > 0">
<span>
{{
remaining | timeFormat({
prefix: $t('task.remaining-prefix'),
i18n: {
'gt1d': $t('app.gt1d'),
'hour': $t('app.hour'),
'minute': $t('app.minute'),
'second': $t('app.second')
}
})
}}
</span>
</div>
<div class="task-speed-text" v-if="isBT">
<i><mo-icon name="magnet" width="10" height="14" /></i>
<span>{{ task.numSeeders }}</span>
</div>
<div class="task-speed-text">
<i><mo-icon name="node" width="10" height="14" /></i>
<span>{{ task.connections }}</span>
</div>
</div>
</el-col>
</el-row>
Expand Down Expand Up @@ -87,29 +89,46 @@

<style lang="scss">
.task-progress-info {
font-size: 12px;
line-height: 14px;
min-height: 14px;
font-size: 0.75rem;
line-height: 0.875rem;
min-height: 0.875rem;
color: #9B9B9B;
margin-top: 8px;
margin-top: 0.5rem;
i {
font-style: normal;
}
}
.task-progress-info-left {
min-height: 14px;
min-height: 0.875rem;
text-align: left;
}
.task-progress-info-right {
min-height: 14px;
min-height: 0.875rem;
text-align: right;
}
.task-speed-info {
font-size: 0;
& > .task-speed-text {
margin-left: 8px;
& > i {
margin-left: 0.375rem;
font-size: 0;
line-height: 0.875rem;
vertical-align: middle;
display: inline-block;
&:first-of-type {
margin-left: 0;
}
& > i, & > span {
height: 0.875rem;
line-height: 0.875rem;
display: inline-block;
vertical-align: middle;
}
& > i {
margin-right: 0.125rem;
}
& > span {
font-size: 0.75rem;
}
}
}
</style>
2 changes: 1 addition & 1 deletion src/renderer/components/TaskDetail/TaskActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/>
</div>
</el-col>
<el-col :span="4">
<el-col :span="5">
{{ percent }}
</el-col>
</el-row>
Expand Down
15 changes: 11 additions & 4 deletions src/renderer/components/TaskDetail/TaskPeers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<el-table
stripe
ref="peerTable"
style="width: 100%"
class="mo-peer-table"
:data="peers"
>
<el-table-column
Expand All @@ -16,7 +16,7 @@
</el-table-column>
<el-table-column
:label="`${$t('task.task-peer-client')}: `"
min-width="130">
min-width="125">
<template slot-scope="scope">
{{ scope.row.peerId | peerIdParser }}
</template>
Expand All @@ -32,15 +32,15 @@
<el-table-column
:label="``"
align="right"
width="95">
width="90">
<template slot-scope="scope">
{{ scope.row.uploadSpeed | bytesToSize }}/s
</template>
</el-table-column>
<el-table-column
:label="``"
align="right"
width="95">
width="90">
<template slot-scope="scope">
{{ scope.row.downloadSpeed | bytesToSize }}/s
</template>
Expand Down Expand Up @@ -74,3 +74,10 @@
}
}
</script>

<style lang="scss">
.el-table.mo-peer-table .cell {
padding-left: 0.5rem;
padding-right: 0.5rem;
}
</style>
1 change: 1 addition & 0 deletions src/renderer/components/Theme/Default.scss
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ iframe {
line-height: 0;
border: 1px solid $--task-detail-box-border;
border-radius: $--border-radius-base;
box-sizing: content-box;
}

.form-static-value {
Expand Down
Loading

0 comments on commit e939f9e

Please sign in to comment.