Make redirection work for hyperspace://protocol
This commit is contained in:
parent
bbf994cecc
commit
d1154f77b4
|
@ -11878,7 +11878,8 @@
|
||||||
"mdi-material-ui": {
|
"mdi-material-ui": {
|
||||||
"version": "5.11.0",
|
"version": "5.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/mdi-material-ui/-/mdi-material-ui-5.11.0.tgz",
|
"resolved": "https://registry.npmjs.org/mdi-material-ui/-/mdi-material-ui-5.11.0.tgz",
|
||||||
"integrity": "sha512-9fIvdiKCKAfBoW11LqZsgaxZtu9WCQEd8FL9/8ceLHvStSf+fZM6sC7exwXaXZmzfwtJMfN1KiMGsPBPSTQFQg=="
|
"integrity": "sha512-9fIvdiKCKAfBoW11LqZsgaxZtu9WCQEd8FL9/8ceLHvStSf+fZM6sC7exwXaXZmzfwtJMfN1KiMGsPBPSTQFQg==",
|
||||||
|
"dev": true
|
||||||
},
|
},
|
||||||
"mdn-data": {
|
"mdn-data": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "HTTPS=true BROWSER='Safari Technology Preview' react-scripts start",
|
"start": "HTTPS=true BROWSER='Safari Technology Preview' react-scripts start",
|
||||||
"electrify": "npm run build; electron .",
|
"electrify": "npm run build; electron .",
|
||||||
|
"electrify-nobuild": "electron .",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"build-desktop": "build -mwl deb AppImage snap",
|
"build-desktop": "build -mwl deb AppImage snap",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": "1.0.0beta4",
|
"version": "1.0.0beta4",
|
||||||
"location": "https://hyperspaceapp-next.herokuapp.com",
|
"location": "desktop",
|
||||||
"branding": {
|
"branding": {
|
||||||
"name": "Hyperspace",
|
"name": "Hyperspace",
|
||||||
"logo": "logo.svg",
|
"logo": "logo.svg",
|
||||||
|
|
|
@ -9,41 +9,77 @@ const path = require('path');
|
||||||
// Check for any updates to the app
|
// 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
|
// Create a container for the window
|
||||||
let mainWindow;
|
let mainWindow;
|
||||||
|
|
||||||
|
protocol.registerSchemesAsPrivileged([
|
||||||
|
{ scheme: 'hyperspace', privileges: { standard: true, secure: true } }
|
||||||
|
])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the protocol for Hyperspace
|
* Register the protocol for Hyperspace
|
||||||
*/
|
*/
|
||||||
function registerProtocol() {
|
function registerProtocol() {
|
||||||
protocol.registerFileProtocol('hyperspace', (request, callback) => {
|
protocol.registerFileProtocol('hyperspace', (request, callback) => {
|
||||||
//Throw a METHOD_NOT_SUPPORTED error if it isn't a GET request
|
|
||||||
|
// Check to make sure we're doing a GET request
|
||||||
if (request.method !== "GET") {
|
if (request.method !== "GET") {
|
||||||
callback({error: -322});
|
callback({error: -322});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the URL scheme doesn't contain the protocol, throw an error
|
// Check to make sure we're actually working with a hyperspace
|
||||||
|
// protocol and that the host is 'hyperspace'
|
||||||
const parsedUrl = new URL(request.url);
|
const parsedUrl = new URL(request.url);
|
||||||
if (parsedUrl.protocol !== "hyperspace") {
|
if (parsedUrl.protocol !== "hyperspace:") {
|
||||||
callback({error: -302});
|
callback({error: -302});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedUrl.host !== "hyperspace") {
|
if (parsedUrl.host !== "hyperspace") {
|
||||||
callback({error: -105});
|
callback({error: -105});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, (error) => {
|
|
||||||
if (error) {
|
//
|
||||||
console.error("Failed to register Hyperspace protocol.");
|
// Target Checks
|
||||||
console.error(error.message);
|
//
|
||||||
|
|
||||||
|
const target = parsedUrl.pathname.split("/");
|
||||||
|
|
||||||
|
//Check that the target isn't something else
|
||||||
|
if (target[0] !== "") {
|
||||||
|
callback({error: -6});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target[target.length -1] === "") {
|
||||||
|
target[target.length -1] = "index.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
let baseDirectory;
|
||||||
|
if (target[1] === "app" || target[1] === "oauth") {
|
||||||
|
baseDirectory = __dirname + "/../build/";
|
||||||
|
} else {
|
||||||
|
callback({error: -6});
|
||||||
|
}
|
||||||
|
|
||||||
|
baseDirectory = path.normalize(baseDirectory);
|
||||||
|
|
||||||
|
const relTarget = path.normalize(path.join(...target.slice(2)));
|
||||||
|
if (relTarget.startsWith('..')) {
|
||||||
|
callback({error: -6});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const absTarget = path.join(baseDirectory, relTarget);
|
||||||
|
|
||||||
|
callback({
|
||||||
|
path: absTarget,
|
||||||
|
});
|
||||||
|
|
||||||
|
}, (error) => {
|
||||||
|
if (error) console.error('Failed to register protocol')
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,12 +91,12 @@ function createWindow() {
|
||||||
width: 1000,
|
width: 1000,
|
||||||
height: 600,
|
height: 600,
|
||||||
minWidth: 476,
|
minWidth: 476,
|
||||||
titleBarStyle: 'hidden',
|
//titleBarStyle: 'hidden',
|
||||||
webPreferences: {nodeIntegration: true}
|
webPreferences: {nodeIntegration: true}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
mainWindow.loadURL(`file://${path.join(__dirname, '../build/index.html#/')}`);
|
mainWindow.loadURL("hyperspace://hyperspace/app/");
|
||||||
|
|
||||||
mainWindow.on('closed', () => {
|
mainWindow.on('closed', () => {
|
||||||
mainWindow = null
|
mainWindow = null
|
||||||
|
@ -186,7 +222,7 @@ function createMenubar() {
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
registerProtocol();
|
registerProtocol();
|
||||||
createWindow();
|
createWindow();
|
||||||
createMenubar();
|
//createMenubar();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Standard quit behavior changes for macOS
|
// Standard quit behavior changes for macOS
|
||||||
|
@ -199,7 +235,7 @@ app.on('window-all-closed', () => {
|
||||||
// When the app is activated, create the window and menu bar
|
// When the app is activated, create the window and menu bar
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
registerProtocol();
|
//registerProtocol();
|
||||||
createWindow();
|
createWindow();
|
||||||
createMenubar();
|
createMenubar();
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,6 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
|
||||||
let config: Config = result;
|
let config: Config = result;
|
||||||
if (result.location === "dynamic") {
|
if (result.location === "dynamic") {
|
||||||
console.warn("Recirect URI is set to dyanmic, which may affect how sign-in works for some users. Careful!");
|
console.warn("Recirect URI is set to dyanmic, which may affect how sign-in works for some users. Careful!");
|
||||||
} else if (result.location === "desktop") {
|
|
||||||
console.warn("Recirect URI is set to desktop, which may affect how sign-in works for some users. This will use https://localhost; careful!");
|
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
logoUrl: config.branding? result.branding.logo: "logo.png",
|
logoUrl: config.branding? result.branding.logo: "logo.png",
|
||||||
|
@ -170,7 +168,7 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
|
||||||
this.state.brandName? this.state.brandName: "Hyperspace",
|
this.state.brandName? this.state.brandName: "Hyperspace",
|
||||||
scopes,
|
scopes,
|
||||||
baseurl,
|
baseurl,
|
||||||
this.state.defaultRedirectAddress
|
getRedirectAddress(this.state.defaultRedirectAddress)
|
||||||
).then((resp: any) => {
|
).then((resp: any) => {
|
||||||
let saveSessionForCrashing: SaveClientSession = {
|
let saveSessionForCrashing: SaveClientSession = {
|
||||||
clientId: resp.clientId,
|
clientId: resp.clientId,
|
||||||
|
@ -290,10 +288,10 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
|
||||||
undefined:
|
undefined:
|
||||||
clientLoginSession.authUrl.includes("urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob")?
|
clientLoginSession.authUrl.includes("urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob")?
|
||||||
undefined:
|
undefined:
|
||||||
`https://${window.location.host}`,
|
window.location.protocol === "hyperspace:"? "hyperspace://hyperspace/app/": `https://${window.location.host}`,
|
||||||
).then((tokenData: any) => {
|
).then((tokenData: any) => {
|
||||||
localStorage.setItem("access_token", tokenData.access_token);
|
localStorage.setItem("access_token", tokenData.access_token);
|
||||||
window.location.href=`https://${window.location.host}/#/`;
|
window.location.href = window.location.protocol === "hyperspace:"? "hyperspace://hyperspace/app/": `https://${window.location.host}/#/`;
|
||||||
}).catch((err: Error) => {
|
}).catch((err: Error) => {
|
||||||
this.props.enqueueSnackbar(`Couldn't authorize ${this.state.brandName? this.state.brandName: "Hyperspace"}: ${err.name}`, {variant: 'error'});
|
this.props.enqueueSnackbar(`Couldn't authorize ${this.state.brandName? this.state.brandName: "Hyperspace"}: ${err.name}`, {variant: 'error'});
|
||||||
console.error(err.message);
|
console.error(err.message);
|
||||||
|
|
|
@ -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 "hyperspace://";
|
return "hyperspace://hyperspace/app/";
|
||||||
case "dynamic":
|
case "dynamic":
|
||||||
return `https://${window.location.host}`;
|
return `https://${window.location.host}`;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue