typescript: Migrate network-section.js to typescript.

This commit is contained in:
vsvipul
2019-06-23 03:20:50 +05:30
committed by Akash Nimare
parent 8c52b563bf
commit b2bc268c09

View File

@@ -1,17 +1,24 @@
'use strict'; 'use strict';
const {ipcRenderer} = require('electron'); import { ipcRenderer } from 'electron';
const BaseSection = require(__dirname + '/base-section.js'); import BaseSection = require('./base-section.js');
const ConfigUtil = require(__dirname + '/../../utils/config-util.js'); import ConfigUtil = require('../../utils/config-util.js');
class NetworkSection extends BaseSection { class NetworkSection extends BaseSection {
constructor(props) { // TODO: TypeScript - Here props should be object type
props: any;
$proxyPAC: HTMLInputElement;
$proxyRules: HTMLInputElement;
$proxyBypass: HTMLInputElement;
$proxySaveAction: Element;
$manualProxyBlock: Element;
constructor(props: any) {
super(); super();
this.props = props; this.props = props;
} }
template() { template(): string {
return ` return `
<div class="settings-pane"> <div class="settings-pane">
<div class="title">Proxy</div> <div class="title">Proxy</div>
@@ -48,12 +55,12 @@ class NetworkSection extends BaseSection {
`; `;
} }
init() { init(): void {
this.props.$root.innerHTML = this.template(); this.props.$root.innerHTML = this.template();
this.$proxyPAC = document.querySelector('#proxy-pac-option .setting-input-value'); this.$proxyPAC = document.querySelector('#proxy-pac-option .setting-input-value');
this.$proxyRules = document.querySelector('#proxy-rules-option .setting-input-value'); this.$proxyRules = document.querySelector('#proxy-rules-option .setting-input-value');
this.$proxyBypass = document.querySelector('#proxy-bypass-option .setting-input-value'); this.$proxyBypass = document.querySelector('#proxy-bypass-option .setting-input-value');
this.$proxySaveAction = document.getElementById('proxy-save-action'); this.$proxySaveAction = document.querySelector('#proxy-save-action');
this.$manualProxyBlock = this.props.$root.querySelector('.manual-proxy-block'); this.$manualProxyBlock = this.props.$root.querySelector('.manual-proxy-block');
this.initProxyOption(); this.initProxyOption();
@@ -70,14 +77,14 @@ class NetworkSection extends BaseSection {
}); });
} }
initProxyOption() { initProxyOption(): void {
const manualProxyEnabled = ConfigUtil.getConfigItem('useManualProxy', false); const manualProxyEnabled = ConfigUtil.getConfigItem('useManualProxy', false);
this.toggleManualProxySettings(manualProxyEnabled); this.toggleManualProxySettings(manualProxyEnabled);
this.updateProxyOption(); this.updateProxyOption();
} }
toggleManualProxySettings(option) { toggleManualProxySettings(option: boolean): void {
if (option) { if (option) {
this.$manualProxyBlock.classList.remove('hidden'); this.$manualProxyBlock.classList.remove('hidden');
} else { } else {
@@ -85,7 +92,7 @@ class NetworkSection extends BaseSection {
} }
} }
updateProxyOption() { updateProxyOption(): void {
this.generateSettingOption({ this.generateSettingOption({
$element: document.querySelector('#use-system-settings .setting-control'), $element: document.querySelector('#use-system-settings .setting-control'),
value: ConfigUtil.getConfigItem('useSystemProxy', false), value: ConfigUtil.getConfigItem('useSystemProxy', false),
@@ -125,4 +132,4 @@ class NetworkSection extends BaseSection {
} }
} }
module.exports = NetworkSection; export = NetworkSection;