Skip to content

Commit

Permalink
(Enhance::Module::ViewSite) 新增浏览网站代理开关
Browse files Browse the repository at this point in the history
  • Loading branch information
Medicean committed Jan 30, 2019
1 parent 0d6dcfb commit 9713e7e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

* 支持使用代理访问插件市场,当配置了代理之后,默认开启

### 浏览网站

* 新增代理开关, 在配置了代理之后,可通过该开关控制是否使用代理浏览目标网站

### Other

* 调整 aproxy uri 初始化 URL 格式
Expand Down
1 change: 1 addition & 0 deletions source/language/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ module.exports = {
},
viewsite: {
toolbar: {
useproxy: (s) => `Proxy: ${s?'ON':'OFF'}`,
save: 'Save',
view: 'View'
},
Expand Down
1 change: 1 addition & 0 deletions source/language/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ module.exports = {
},
viewsite: {
toolbar: {
useproxy: (s) => `代理: ${s?'开':'关'}`,
save: '保存',
view: '浏览'
},
Expand Down
29 changes: 25 additions & 4 deletions source/modules/viewsite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ViewSite {

this.opts = opts;
this.cell = tabbar.cells(`tab_viewsite_${hash}`);

this.useproxy = antSword.aproxymode !== "noproxy";
// 初始化工具栏
this.toolbar = this._initToolbar();

Expand Down Expand Up @@ -52,10 +52,21 @@ class ViewSite {
const toolbar = this.cell.attachToolbar();
toolbar.loadStruct([
{ id: 'url', width: 400, type: 'buttonInput', value: this.opts.url || 'loading..' },
{ type: 'separator' },
{ id: 'useproxy', type: 'buttonTwoState', icon: 'paper-plane', text: LANG['toolbar'].useproxy(this.useproxy), pressed: this.useproxy, disabled: antSword.aproxymode === "noproxy"},
{ type: 'separator' },
{ id: 'view', type: 'button', icon: 'chrome', text: LANG['toolbar'].view },
{ type: 'separator' },
{ id: 'save', type: 'button', icon: 'save', text: LANG['toolbar'].save },
]);
toolbar.attachEvent('onStateChange', (id, state) => {
switch(id) {
case 'useproxy':
this.useproxy = state;
toolbar.setItemText('useproxy', `<i class="fa fa-paper-plane"></i> ${LANG['toolbar'].useproxy(this.useproxy)}`);
break;
}
});
toolbar.attachEvent('onClick', (id) => {
switch(id) {
case 'save':
Expand Down Expand Up @@ -171,9 +182,19 @@ class ViewSite {
},
title: url
});
win.loadURL(url);
win.show();
win.openDevTools();
win.on('close', () => {
win = null;
});
let ses = win.webContents.session;
let proxyuri = "";
if(this.useproxy && antSword.aproxymode != "noproxy") {
proxyuri = antSword.aproxyuri;
}
ses.setProxy({proxyRules: proxyuri}, ()=>{
win.loadURL(url);
win.show();
win.openDevTools();
});
}
}

Expand Down

0 comments on commit 9713e7e

Please sign in to comment.