1
0
mirror of https://github.com/rhysd/Mstdn.git synced 2025-01-21 20:52:11 +01:00

enable login with Pixiv account on pawoo.net

This commit is contained in:
rhysd 2017-05-01 18:12:19 +09:00
parent e03537f4f8
commit 754ca9e7c1
2 changed files with 28 additions and 5 deletions

View File

@ -10,6 +10,7 @@ export const PRELOAD_JS = path.join(__dirname, '..', 'renderer', 'preload.js');
export const DATA_DIR = app.getPath('userData'); export const DATA_DIR = app.getPath('userData');
export const CONFIG_FILE = path.join(DATA_DIR, 'config.json'); export const CONFIG_FILE = path.join(DATA_DIR, 'config.json');
export const USER_CSS = path.join(DATA_DIR, 'user.css'); export const USER_CSS = path.join(DATA_DIR, 'user.css');
export const IOS_SAFARI_USERAGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1';
export function trayIcon(color: string) { export function trayIcon(color: string) {
return path.join(__dirname, '..', 'resources', 'icon', `tray-icon-${ return path.join(__dirname, '..', 'resources', 'icon', `tray-icon-${

View File

@ -5,10 +5,19 @@ import * as menubar from 'menubar';
import {Config, Account, hostUrl} from './config'; import {Config, Account, hostUrl} from './config';
import {partitionForAccount} from './account_switcher'; import {partitionForAccount} from './account_switcher';
import log from './log'; import log from './log';
import {IS_DEBUG, IS_DARWIN, IS_WINDOWS, IS_LINUX, APP_ICON, PRELOAD_JS, USER_CSS, trayIcon} from './common'; import {IS_DEBUG, IS_DARWIN, IS_WINDOWS, IS_LINUX, APP_ICON, PRELOAD_JS, USER_CSS, IOS_SAFARI_USERAGENT, trayIcon} from './common';
const ELECTRON_ISSUE_9230 = IS_WINDOWS || IS_LINUX; const ELECTRON_ISSUE_9230 = IS_WINDOWS || IS_LINUX;
function shouldOpenInternal(host: string, url: string): boolean {
if (host.startsWith('https://pawoo.net') && url.startsWith('https://accounts.pixiv.net/login?')) {
log.debug('accounts.pixiv.net opens and will redirect to pawoo.net for signin with Pixiv account.');
return true;
}
return false;
}
export default class Window { export default class Window {
static create(account: Account, config: Config, mb: Menubar.MenubarApp | null = null) { static create(account: Account, config: Config, mb: Menubar.MenubarApp | null = null) {
return (config.normal_window ? startNormalWindow(account, config) : startMenuBar(account, config, mb)) return (config.normal_window ? startNormalWindow(account, config) : startMenuBar(account, config, mb))
@ -35,10 +44,17 @@ export default class Window {
} }
browser.webContents.on('will-navigate', (e, url) => { browser.webContents.on('will-navigate', (e, url) => {
if (!url.startsWith(hostUrl(this.account))) { const host = hostUrl(this.account);
e.preventDefault(); if (url.startsWith(host)) {
shell.openExternal(url); return;
} }
if (shouldOpenInternal(host, url)) {
return;
}
e.preventDefault();
shell.openExternal(url);
log.debug('Opened URL with external browser (will-navigate)', url); log.debug('Opened URL with external browser (will-navigate)', url);
}); });
browser.webContents.on('new-window', (e, url) => { browser.webContents.on('new-window', (e, url) => {
@ -90,7 +106,13 @@ export default class Window {
e.preventDefault(); e.preventDefault();
this.browser.loadURL(hostUrl(this.account) + '/auth/sign_in'); this.browser.loadURL(hostUrl(this.account) + '/auth/sign_in');
}); });
this.browser.loadURL(url); if (url.startsWith('https://pawoo.net')) {
this.browser.loadURL(url, {
userAgent: IOS_SAFARI_USERAGENT,
});
} else {
this.browser.loadURL(url);
}
} }
close() { close() {