Dynamically change app name in rrgistry, change name in Welcome pages

This commit is contained in:
Marquis Kurt 2019-04-28 15:50:18 -04:00
parent 1a05cb9417
commit 7ebfff138b
3 changed files with 41 additions and 8 deletions

22
src/interfaces/Config.tsx Normal file
View File

@ -0,0 +1,22 @@
import {License} from '../types/Config';
export interface Config {
version: string;
location: string;
branding?: {
name?: string;
logo?: string;
background?: string;
};
developer?: string;
federated?: string;
registration?: {
defaultInstance?: string;
};
admin?: {
name?: string;
account?: string;
};
license: License;
respository?: string;
}

View File

@ -151,7 +151,12 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
const scopes = 'read write follow';
const baseurl = this.getLoginUser(this.state.user);
localStorage.setItem("baseurl", baseurl);
createHyperspaceApp(scopes, baseurl, this.state.defaultRedirectAddress).then((resp: any) => {
createHyperspaceApp(
this.state.brandName? this.state.brandName: "Hyperspace",
scopes,
baseurl,
this.state.defaultRedirectAddress
).then((resp: any) => {
let saveSessionForCrashing: SaveClientSession = {
clientId: resp.clientId,
clientSecret: resp.clientSecret,
@ -175,9 +180,13 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
console.log("Creating an emergency login...")
const scopes = "read write follow";
const baseurl = localStorage.getItem('baseurl') || this.getLoginUser(this.state.user);
Mastodon.registerApp(this.state.brandName? this.state.brandName: "Hyperspace", {
scopes: scopes
}, baseurl).then((appData: any) => {
Mastodon.registerApp(
this.state.brandName? this.state.brandName: "Hyperspace",
{
scopes: scopes
},
baseurl
).then((appData: any) => {
let saveSessionForCrashing: SaveClientSession = {
clientId: appData.clientId,
clientSecret: appData.clientSecret,
@ -260,7 +269,7 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
localStorage.setItem("access_token", tokenData.access_token);
window.location.href=`https://${window.location.host}/#/`;
}).catch((err: Error) => {
this.props.enqueueSnackbar("Couldn't authorize 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);
})
}
@ -323,7 +332,7 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
return (
<div>
<Typography variant="h5">Howdy, {this.state.user? this.state.user.split("@")[0]: "user"}</Typography>
<Typography>To continue, finish signing in on your instance's website and authorize Hyperspace.</Typography>
<Typography>To continue, finish signing in on your instance's website and authorize {this.state.brandName? this.state.brandName: "Hyperspace"}.</Typography>
<div className={classes.middlePadding}/>
<div style={{ display: "flex" }}>
<div className={classes.flexGrow}/>

View File

@ -2,12 +2,14 @@ import Mastodon from 'megalodon';
/**
* Creates the Hyperspace app with the appropriate Redirect URI
* @param name The name of the app (if not Hyperspace, will use `name (Hyperspace-like)`)
* @param scopes The scopes that the app needs
* @param baseurl The base URL of the instance
* @param redirect_uri The URL to redirect to when authorizing
*/
export function createHyperspaceApp(scopes: string, baseurl: string, redirect_uri: string) {
return Mastodon.createApp("Hyperspace", {
export function createHyperspaceApp(name: string, scopes: string, baseurl: string, redirect_uri: string) {
let appName = name === "Hyperspace"? "Hyperspace": `${name} (Hyperspace-like)`
return Mastodon.createApp(appName, {
scopes: scopes,
redirect_uris: redirect_uri,
website: 'https://hyperspace.marquiskurt.net',