mirror of
https://github.com/hyperspacedev/hyperspace
synced 2025-02-03 18:57:38 +01:00
Make redirection work for hyperspace://protocol
This commit is contained in:
parent
bbf994cecc
commit
d1154f77b4
3
package-lock.json
generated
3
package-lock.json
generated
@ -11878,7 +11878,8 @@
|
||||
"mdi-material-ui": {
|
||||
"version": "5.11.0",
|
||||
"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": {
|
||||
"version": "1.1.4",
|
||||
|
@ -38,6 +38,7 @@
|
||||
"scripts": {
|
||||
"start": "HTTPS=true BROWSER='Safari Technology Preview' react-scripts start",
|
||||
"electrify": "npm run build; electron .",
|
||||
"electrify-nobuild": "electron .",
|
||||
"build": "react-scripts build",
|
||||
"build-desktop": "build -mwl deb AppImage snap",
|
||||
"test": "react-scripts test",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"version": "1.0.0beta4",
|
||||
"location": "https://hyperspaceapp-next.herokuapp.com",
|
||||
"location": "desktop",
|
||||
"branding": {
|
||||
"name": "Hyperspace",
|
||||
"logo": "logo.svg",
|
||||
|
@ -9,41 +9,77 @@ const path = require('path');
|
||||
// Check for any updates to the app
|
||||
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;
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{ scheme: 'hyperspace', privileges: { standard: true, secure: true } }
|
||||
])
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
// Check to make sure we're doing a GET request
|
||||
if (request.method !== "GET") {
|
||||
callback({error: -322});
|
||||
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);
|
||||
if (parsedUrl.protocol !== "hyperspace") {
|
||||
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);
|
||||
|
||||
//
|
||||
// Target Checks
|
||||
//
|
||||
|
||||
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,
|
||||
height: 600,
|
||||
minWidth: 476,
|
||||
titleBarStyle: 'hidden',
|
||||
//titleBarStyle: 'hidden',
|
||||
webPreferences: {nodeIntegration: true}
|
||||
}
|
||||
);
|
||||
|
||||
mainWindow.loadURL(`file://${path.join(__dirname, '../build/index.html#/')}`);
|
||||
mainWindow.loadURL("hyperspace://hyperspace/app/");
|
||||
|
||||
mainWindow.on('closed', () => {
|
||||
mainWindow = null
|
||||
@ -186,7 +222,7 @@ function createMenubar() {
|
||||
app.on('ready', () => {
|
||||
registerProtocol();
|
||||
createWindow();
|
||||
createMenubar();
|
||||
//createMenubar();
|
||||
});
|
||||
|
||||
// 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
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) {
|
||||
registerProtocol();
|
||||
//registerProtocol();
|
||||
createWindow();
|
||||
createMenubar();
|
||||
}
|
||||
|
@ -64,8 +64,6 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
|
||||
let config: Config = result;
|
||||
if (result.location === "dynamic") {
|
||||
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({
|
||||
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",
|
||||
scopes,
|
||||
baseurl,
|
||||
this.state.defaultRedirectAddress
|
||||
getRedirectAddress(this.state.defaultRedirectAddress)
|
||||
).then((resp: any) => {
|
||||
let saveSessionForCrashing: SaveClientSession = {
|
||||
clientId: resp.clientId,
|
||||
@ -290,10 +288,10 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
|
||||
undefined:
|
||||
clientLoginSession.authUrl.includes("urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob")?
|
||||
undefined:
|
||||
`https://${window.location.host}`,
|
||||
window.location.protocol === "hyperspace:"? "hyperspace://hyperspace/app/": `https://${window.location.host}`,
|
||||
).then((tokenData: any) => {
|
||||
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) => {
|
||||
this.props.enqueueSnackbar(`Couldn't authorize ${this.state.brandName? this.state.brandName: "Hyperspace"}: ${err.name}`, {variant: 'error'});
|
||||
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 {
|
||||
switch(type) {
|
||||
case "desktop":
|
||||
return "hyperspace://";
|
||||
return "hyperspace://hyperspace/app/";
|
||||
case "dynamic":
|
||||
return `https://${window.location.host}`;
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user