This repository has been archived on 2020-04-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Vim-Vixen/src/background/repositories/BrowserSettingRepository.ts
2020-01-02 10:59:37 +00:00

59 lines
1.4 KiB
TypeScript

import { injectable } from 'tsyringe';
import * as urls from '../../shared/urls';
declare namespace browser.browserSettings.homepageOverride {
type BrowserSettings = {
value: string;
levelOfControl: LevelOfControlType;
};
type LevelOfControlType =
'not_controllable' |
'controlled_by_other_extensions' |
'controllable_by_this_extension' |
'controlled_by_this_extension';
function get(param: object): Promise<BrowserSettings>;
}
declare namespace browser.proxy.settings {
type BrowserSettings = {
value: string;
};
function get(param: object): Promise<BrowserSettings>;
function set(param: object): Promise<any>;
function clear(param: object): Promise<any>;
}
@injectable()
export default class BrowserSettingRepository {
async getHomepageUrls(): Promise<string[]> {
let { value } = await browser.browserSettings.homepageOverride.get({});
return value.split('|').map(urls.normalizeUrl);
}
}
export class ProxyRepository {
private clearProxySettings(): Promise<any>{
return browser.proxy.settings.clear({});
}
private setProxySettings(address: string): Promise<any>{
return browser.proxy.settings.set({value: {
proxyType: "manual",
http: address,
httpProxyAll: true
}});
}
set(address: string): Promise<any> {
if( address.toLowerCase() == 'none' ){
return this.clearProxySettings();
}
return this.setProxySettings(address);
}
}