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

request user's permission for 'media' and 'geolocation'

This commit is contained in:
rhysd 2017-04-16 22:36:37 +09:00
parent 16b224d973
commit 7fa8cdac10
2 changed files with 20 additions and 3 deletions

View File

@ -8,7 +8,7 @@ Features:
- [x] Small window on your menubar (or isolated window)
- [x] Desktop notification
- [x] Customizable shortcut keybinds
- [ ] Multi-account
- [ ] Multi-account (switching among accounts)
Mastodon is an open source project. So if you want to make a new UI, you can just fork the project,
implement your favorite UI and host it on your place. Then you can participate Mastodon networks from it.

View File

@ -1,5 +1,5 @@
import * as path from 'path';
import {app, BrowserWindow, globalShortcut, Tray, shell} from 'electron';
import {app, BrowserWindow, globalShortcut, Tray, shell, dialog} from 'electron';
import windowState = require('electron-window-state');
import * as menubar from 'menubar';
import log from './log';
@ -23,6 +23,7 @@ export class App {
}
open() {
this.win.loadURL(`https://${this.account.host}${this.account.default_page}`);
this.win.webContents.on('will-navigate', (e, url) => {
if (!url.startsWith(`https://${this.account.host}`)) {
e.preventDefault();
@ -33,7 +34,23 @@ export class App {
e.preventDefault();
shell.openExternal(url);
});
this.win.loadURL(`https://${this.account.host}${this.account.default_page}`);
this.win.webContents.session.setPermissionRequestHandler((contents, permission, callback) => {
if (permission !== 'geolocation' && permission !== 'media') {
// Granted
callback(true);
return;
}
dialog.showMessageBox({
type: 'question',
buttons: ['Accept', 'Reject'],
message: `Permission '${permission}' is requested by ${contents.getURL()}`,
detail: "Please choose one of 'Accept' or 'Reject'",
}, (buttonIndex: number) => {
const granted = buttonIndex === 0;
callback(granted);
});
});
this.win.show();
}
}