mirror of https://github.com/keeweb/keeweb.git
fix #79: using system proxy settings for updater
This commit is contained in:
parent
1df736d85b
commit
f1b1c8a8d5
|
@ -100,6 +100,15 @@ if (window.process && window.process.versions && window.process.versions.electro
|
|||
},
|
||||
updaterEnabled: function() {
|
||||
return this.req('remote').process.argv.indexOf('--disable-updater') === -1;
|
||||
},
|
||||
resolveProxy: function(url, callback) {
|
||||
var window = this.remReq('app').getMainWindow();
|
||||
var session = window.webContents.session;
|
||||
session.resolveProxy(url, function(proxy) {
|
||||
var match = /^proxy\s+([\w\.]+):(\d+)+\s*/i.exec(proxy);
|
||||
proxy = match && match[1] ? { host: match[1], port: +match[2] } : null;
|
||||
callback(proxy);
|
||||
});
|
||||
}
|
||||
};
|
||||
Backbone.on('launcher-exit-request', function() {
|
||||
|
|
|
@ -28,43 +28,58 @@ var Transport = {
|
|||
logger.info('GET ' + config.url);
|
||||
var opts = Launcher.req('url').parse(config.url);
|
||||
opts.headers = { 'User-Agent': navigator.userAgent };
|
||||
Launcher.req(proto).get(opts, function(res) {
|
||||
logger.info('Response from ' + config.url + ': ' + res.statusCode);
|
||||
if (res.statusCode === 200) {
|
||||
if (config.file) {
|
||||
var file = fs.createWriteStream(tmpFile);
|
||||
res.pipe(file);
|
||||
file.on('finish', function() {
|
||||
file.close(function() { config.success(tmpFile); });
|
||||
});
|
||||
file.on('error', function(err) { config.error(err); });
|
||||
Launcher.resolveProxy(config.url, function(proxy) {
|
||||
logger.info('Request to ' + config.url + ' ' + (proxy ? 'using proxy ' + proxy.host + ':' + proxy.port : 'without proxy'));
|
||||
if (proxy) {
|
||||
opts.headers.Host = opts.host;
|
||||
opts.host = proxy.host;
|
||||
opts.port = proxy.port;
|
||||
opts.path = config.url;
|
||||
}
|
||||
Launcher.req(proto).get(opts, function (res) {
|
||||
logger.info('Response from ' + config.url + ': ' + res.statusCode);
|
||||
if (res.statusCode === 200) {
|
||||
if (config.file) {
|
||||
var file = fs.createWriteStream(tmpFile);
|
||||
res.pipe(file);
|
||||
file.on('finish', function () {
|
||||
file.close(function () {
|
||||
config.success(tmpFile);
|
||||
});
|
||||
});
|
||||
file.on('error', function (err) {
|
||||
config.error(err);
|
||||
});
|
||||
} else {
|
||||
var data = [];
|
||||
res.on('data', function (chunk) {
|
||||
data.push(chunk);
|
||||
});
|
||||
res.on('end', function () {
|
||||
data = window.Buffer.concat(data);
|
||||
if (config.utf8) {
|
||||
data = data.toString('utf8');
|
||||
}
|
||||
config.success(data);
|
||||
});
|
||||
}
|
||||
} else if (res.headers.location && [301, 302].indexOf(res.statusCode) >= 0) {
|
||||
if (config.noRedirect) {
|
||||
return config.error('Too many redirects');
|
||||
}
|
||||
config.url = res.headers.location;
|
||||
config.noRedirect = true;
|
||||
Transport.httpGet(config);
|
||||
} else {
|
||||
var data = [];
|
||||
res.on('data', function(chunk) { data.push(chunk); });
|
||||
res.on('end', function() {
|
||||
data = window.Buffer.concat(data);
|
||||
if (config.utf8) {
|
||||
data = data.toString('utf8');
|
||||
}
|
||||
config.success(data);
|
||||
});
|
||||
config.error('HTTP status ' + res.statusCode);
|
||||
}
|
||||
} else if (res.headers.location && [301, 302].indexOf(res.statusCode) >= 0) {
|
||||
if (config.noRedirect) {
|
||||
return config.error('Too many redirects');
|
||||
}).on('error', function (e) {
|
||||
logger.error('Cannot GET ' + config.url, e);
|
||||
if (tmpFile) {
|
||||
fs.unlink(tmpFile);
|
||||
}
|
||||
config.url = res.headers.location;
|
||||
config.noRedirect = true;
|
||||
Transport.httpGet(config);
|
||||
} else {
|
||||
config.error('HTTP status ' + res.statusCode);
|
||||
}
|
||||
}).on('error', function(e) {
|
||||
logger.error('Cannot GET ' + config.url, e);
|
||||
if (tmpFile) {
|
||||
fs.unlink(tmpFile);
|
||||
}
|
||||
config.error(e);
|
||||
config.error(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -76,6 +76,9 @@ app.minimizeApp = function() {
|
|||
appIcon.setToolTip('KeeWeb');
|
||||
}
|
||||
};
|
||||
app.getMainWindow = function() {
|
||||
return mainWindow;
|
||||
};
|
||||
|
||||
function createMainWindow() {
|
||||
mainWindow = new BrowserWindow({
|
||||
|
|
|
@ -5,6 +5,7 @@ Performance, stability and quality improvements
|
|||
`+` track changes in local files
|
||||
`+` mobile layout made more convenient
|
||||
`+` command-line option to disable updater
|
||||
`+` using system proxy settings for updater
|
||||
`-` #80: prevent data loss on group move
|
||||
`-` issues with clipboard clear fixed
|
||||
|
||||
|
|
Loading…
Reference in New Issue