mirror of
https://github.com/rhysd/Mstdn.git
synced 2024-11-28 20:24:10 +01:00
allow host to contain 'https://' or 'http://'
This commit is contained in:
parent
aa6d196f2b
commit
5429c0150c
@ -12,3 +12,4 @@
|
||||
*.ts
|
||||
*.js.map
|
||||
/typings
|
||||
/.github
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Config> {
|
||||
return new Promise<Config>(resolve => {
|
||||
fs.readFile(CONFIG_FILE, 'utf8', (err, json) => {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user