mirror of
https://github.com/hyperspacedev/hyperspace
synced 2025-02-03 18:57:38 +01:00
Start writing protocol behaviors seen in vector-im/riot-web
This commit is contained in:
parent
deecd99845
commit
bbf994cecc
@ -1,14 +1,54 @@
|
|||||||
const electron = require('electron');
|
// desktop.js
|
||||||
const app = electron.app;
|
// Electron script to run Hyperspace as an app
|
||||||
const menu = electron.Menu;
|
// © 2018 Hyperspace developers. Licensed under Apache 2.0.
|
||||||
const BrowserWindow = electron.BrowserWindow;
|
|
||||||
const {autoUpdater} = require('electron-updater');
|
|
||||||
|
|
||||||
|
const { app, menu, protocol, BrowserWindow } = require('electron');
|
||||||
|
const { autoUpdater } = require('electron-updater');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
// Check for any updates to the app
|
||||||
autoUpdater.checkForUpdatesAndNotify();
|
autoUpdater.checkForUpdatesAndNotify();
|
||||||
|
|
||||||
|
// Create the protocol to use for Hyperspace in redirect URIs
|
||||||
|
// Also mark it as secure so that Mastodon is happy
|
||||||
|
protocol.registerStandardSchemes(['hyperspace'], {secure: true});
|
||||||
|
|
||||||
|
// Create a container for the window
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the protocol for Hyperspace
|
||||||
|
*/
|
||||||
|
function registerProtocol() {
|
||||||
|
protocol.registerFileProtocol('hyperspace', (request, callback) => {
|
||||||
|
//Throw a METHOD_NOT_SUPPORTED error if it isn't a GET request
|
||||||
|
if (request.method !== "GET") {
|
||||||
|
callback({error: -322});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the URL scheme doesn't contain the protocol, throw an error
|
||||||
|
const parsedUrl = new URL(request.url);
|
||||||
|
if (parsedUrl.protocol !== "hyperspace") {
|
||||||
|
callback({error: -302});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedUrl.host !== "hyperspace") {
|
||||||
|
callback({error: -105});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, (error) => {
|
||||||
|
if (error) {
|
||||||
|
console.error("Failed to register Hyperspace protocol.");
|
||||||
|
console.error(error.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the window and all of its properties
|
||||||
|
*/
|
||||||
function createWindow() {
|
function createWindow() {
|
||||||
mainWindow = new BrowserWindow(
|
mainWindow = new BrowserWindow(
|
||||||
{
|
{
|
||||||
@ -27,6 +67,9 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the menu bar and attach it to a window
|
||||||
|
*/
|
||||||
function createMenubar() {
|
function createMenubar() {
|
||||||
const menuBar = [
|
const menuBar = [
|
||||||
{
|
{
|
||||||
@ -36,8 +79,10 @@ function createMenubar() {
|
|||||||
label: 'New Window',
|
label: 'New Window',
|
||||||
accelerator: 'CmdOrCtrl+N',
|
accelerator: 'CmdOrCtrl+N',
|
||||||
click() {
|
click() {
|
||||||
if (mainWindow == null)
|
if (mainWindow == null) {
|
||||||
|
registerProtocol();
|
||||||
createWindow();
|
createWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -137,20 +182,25 @@ function createMenubar() {
|
|||||||
menu.setApplicationMenu(thisMenu);
|
menu.setApplicationMenu(thisMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When the app is ready, create the window and menu bar
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
|
registerProtocol();
|
||||||
createWindow();
|
createWindow();
|
||||||
createMenubar();
|
createMenubar();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Standard quit behavior changes for macOS
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// When the app is activated, create the window and menu bar
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
createWindow()
|
registerProtocol();
|
||||||
createMenubar()
|
createWindow();
|
||||||
|
createMenubar();
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -31,7 +31,7 @@ export function createHyperspaceApp(name: string, scopes: string, baseurl: strin
|
|||||||
export function getRedirectAddress(type: "desktop" | "dynamic" | string): string {
|
export function getRedirectAddress(type: "desktop" | "dynamic" | string): string {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case "desktop":
|
case "desktop":
|
||||||
return "https://localhost/";
|
return "hyperspace://";
|
||||||
case "dynamic":
|
case "dynamic":
|
||||||
return `https://${window.location.host}`;
|
return `https://${window.location.host}`;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user