Skip to content

Commit

Permalink
Merge pull request #9 from everplus/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Dec 9, 2018
2 parents fa64979 + 1c51fef commit 02a6d2c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 14 deletions.
29 changes: 27 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,32 @@ app.on("ready", function () {

//打开主程序
fs.chmodSync(aria2_dir, 0o777)
let subpy = require("child_process").spawn(aria2_dir, [`--conf-path=${conf_path}`])

let subpy = null

function runAria2() {
killAria2()

subpy = require("child_process").spawn(aria2_dir, [`--conf-path=${conf_path}`], {
stdio: "pipe"
})
subpy.stdout.pipe(process.stdout, { end: false })
subpy.stderr.pipe(process.stderr, { end: false })

subpy.on("error", runAria2)
subpy.on("exit", runAria2)
}

function killAria2() {
if (subpy) {
subpy.removeAllListeners("error")
subpy.removeAllListeners("exit")
subpy.kill("SIGINT")
subpy = null
}
}

runAria2()

// 打开窗口的调试工具
//mainWindow.webContents.openDevTools()
Expand All @@ -70,7 +95,7 @@ app.on("ready", function () {
})

mainWindow.on("closed", function () {
subpy.kill("SIGINT")
killAria2()
mainWindow = null
})

Expand Down
8 changes: 4 additions & 4 deletions app/check_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*
*/

const path = require('path');
const { dialog, shell, app } = require('electron').remote
const path = require("path")
const { dialog, shell, app } = require("electron").remote

const versionCheckApi = "https://raw.githubusercontent.com/Xmader/aria-ng-gui/master/app/package.json"
const DownloadUrl = "https://github.com/Xmader/aria-ng-gui/releases/latest"
Expand All @@ -26,10 +26,10 @@ const found_new_version = (version, new_version) => {
buttons: ["下载", "取消"],
defaultId: 0,
cancelId: 1,
title: `发现新版本!`,
title: "发现新版本!",
message: "是否要下载新版本?",
detail: `当前版本: v${version} ,\n新版本: v${new_version} `,
icon: path.join(__dirname, 'assets/AriaNg.png'),
icon: path.join(__dirname, "assets/AriaNg.png"),
}, (response) => {
if (response == 0) {
shell.openExternal(DownloadUrl)
Expand Down
26 changes: 19 additions & 7 deletions app/edit_conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,33 @@
*
*/

const os = require('os');
const fs = require('fs')
const path = require('path')
const { app } = require('electron')
const os = require("os")
const fs = require("fs")
const path = require("path")
const { app } = require("electron")

const download_dir = app.getPath("downloads") || path.join(os.homedir(), "Downloads")
const default_download_dir = app.getPath("downloads") || path.join(os.homedir(), "Downloads")

const edit_conf = (conf_path) => {
const session_path = path.join(path.dirname(conf_path), "aria2.session")

let old_conf = fs.readFileSync(conf_path).toString()

let download_dir = default_download_dir
let saved_dir = (old_conf.match(/^dir=(.*)$/m) || ["", ""])[1]
if (saved_dir) {
let stat = null
try {
stat = fs.statSync(saved_dir)
} catch (e) { }
if (stat && stat.isDirectory()) {
download_dir = saved_dir
}
}

let new_conf = old_conf
.replace(/dir=.+/, "dir=" + download_dir)
.replace(/(input-file=|save-session=).*/g, "$1" + session_path)
.replace(/^dir=.*$/m, "dir=" + download_dir)
.replace(/^(input-file=|save-session=).*$/gm, "$1" + session_path)

fs.writeFileSync(conf_path, new_conf)
}
Expand Down
2 changes: 1 addition & 1 deletion app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const contextMenuTemplate = [
{ label: "粘贴", role: "paste", accelerator: "CmdOrCtrl+V" }, //Paste菜单项
{ type: "separator" }, //分隔线
{ label: "全选", role: "selectall", accelerator: "CmdOrCtrl+A" }, //Select All菜单项
];
]
if (isDev) {
[
{ type: "separator" }, //分隔线
Expand Down

0 comments on commit 02a6d2c

Please sign in to comment.