diff --git a/.npmignore b/.npmignore index c31027a..6547e0e 100644 --- a/.npmignore +++ b/.npmignore @@ -12,3 +12,4 @@ *.ts *.js.map /typings +/.github diff --git a/main/app.ts b/main/app.ts index 967f2c4..802eba2 100644 --- a/main/app.ts +++ b/main/app.ts @@ -1,6 +1,6 @@ import {app, Menu, globalShortcut, Tray} from 'electron'; import log from './log'; -import {Config, Account} from './config'; +import {Config, Account, hostUrl} from './config'; import AccountSwitcher from './account_switcher'; import defaultMenu from './default_menu'; import Window from './window'; @@ -26,7 +26,7 @@ export class App { start() { const a = this.switcher.current; - const url = `https://${a.host}${a.default_page}`; + const url = hostUrl(a) + a.default_page; this.win.open(url); log.debug('Application started', a, url); } diff --git a/main/config.ts b/main/config.ts index 5a7b3c5..715f735 100644 --- a/main/config.ts +++ b/main/config.ts @@ -73,6 +73,14 @@ function recommendConfigAndDie(file: string) { showDyingDialog(title, detail); } +export function hostUrl(a: Account) { + if (a.host.startsWith('https://') || a.host.startsWith('http://')) { + return a.host; + } else { + return 'https://' + a.host; + } +} + export default function loadConfig(): Promise { return new Promise(resolve => { fs.readFile(CONFIG_FILE, 'utf8', (err, json) => { diff --git a/main/window.ts b/main/window.ts index 4dc5ecc..be5d1f0 100644 --- a/main/window.ts +++ b/main/window.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import {app, BrowserWindow, shell, dialog, Menu} from 'electron'; import windowState = require('electron-window-state'); import * as menubar from 'menubar'; -import {Config, Account} from './config'; +import {Config, Account, hostUrl} from './config'; import {partitionForAccount} from './account_switcher'; import log from './log'; import {IS_DEBUG, IS_DARWIN, IS_WINDOWS, IS_LINUX, APP_ICON, PRELOAD_JS, USER_CSS, trayIcon} from './common'; @@ -35,7 +35,7 @@ export default class Window { } browser.webContents.on('will-navigate', (e, url) => { - if (!url.startsWith(`https://${this.account.host}`)) { + if (!url.startsWith(hostUrl(this.account))) { e.preventDefault(); shell.openExternal(url); } @@ -56,7 +56,7 @@ export default class Window { browser.webContents.session.setPermissionRequestHandler((contents, permission, callback) => { const url = contents.getURL(); const grantedByDefault = - url.startsWith(`https://${this.account.host}`) && + url.startsWith(hostUrl(this.account)) && permission !== 'geolocation' && permission !== 'media'; @@ -88,7 +88,7 @@ export default class Window { } log.debug('Redirecting to ' + newUrl + '. Will navigate to login page for user using single user mode'); e.preventDefault(); - this.browser.loadURL(`https://${this.account.host}/auth/sign_in`); + this.browser.loadURL(hostUrl(this.account) + '/auth/sign_in'); }); this.browser.loadURL(url); }