1
0
mirror of https://github.com/hyperspacedev/hyperspace synced 2025-02-04 03:08:10 +01:00

Merge branch 'b2u3' of github.com:hyperspacedev/hyperspace into media-uploads

This commit is contained in:
Marquis Kurt 2019-04-29 14:58:24 -04:00
commit ad34581293
5 changed files with 67 additions and 19 deletions

View File

@ -177,10 +177,10 @@ export class AppLayout extends Component<any, IAppLayoutState> {
<Typography className={classes.titleBarText}>Careful: you're running in developer mode.</Typography> <Typography className={classes.titleBarText}>Careful: you're running in developer mode.</Typography>
</div> </div>
); );
} else if ((navigator.userAgent.includes("Hyperspace") || navigator.userAgent.includes("Electron")) && navigator.userAgent.includes("Macintosh")) { } else if ((navigator.userAgent.includes(this.state.brandName || "Hyperspace") || navigator.userAgent.includes("Electron")) && navigator.userAgent.includes("Macintosh")) {
return ( return (
<div className={classes.titleBarRoot}> <div className={classes.titleBarRoot}>
<Typography className={classes.titleBarText}>Hyperspace</Typography> <Typography className={classes.titleBarText}>{this.state.brandName? this.state.brandName: "Hyperspace"}</Typography>
</div> </div>
); );
} }
@ -376,10 +376,10 @@ export class AppLayout extends Component<any, IAppLayoutState> {
open={this.state.logOutOpen} open={this.state.logOutOpen}
onClose={() => this.toggleLogOutDialog()} onClose={() => this.toggleLogOutDialog()}
> >
<DialogTitle id="alert-dialog-title">Log out of Hyperspace?</DialogTitle> <DialogTitle id="alert-dialog-title">Log out of {this.state.brandName? this.state.brandName: "Hyperspace"}</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText id="alert-dialog-description"> <DialogContentText id="alert-dialog-description">
You'll need to remove Hyperspace from your list of authorized apps and log in again if you want to use Hyperspace. You'll need to remove {this.state.brandName? this.state.brandName: "Hyperspace"} from your list of authorized apps and log in again if you want to use {this.state.brandName? this.state.brandName: "Hyperspace"}.
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>

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

@ -43,6 +43,7 @@ interface ISettingsState {
resetSettingsDialog: boolean; resetSettingsDialog: boolean;
previewTheme: Theme; previewTheme: Theme;
defaultVisibility: Visibility; defaultVisibility: Visibility;
brandName: string;
federated: boolean; federated: boolean;
} }
@ -63,6 +64,7 @@ class SettingsPage extends Component<any, ISettingsState> {
resetSettingsDialog: false, resetSettingsDialog: false,
previewTheme: setHyperspaceTheme(getUserDefaultTheme()) || setHyperspaceTheme(defaultTheme), previewTheme: setHyperspaceTheme(getUserDefaultTheme()) || setHyperspaceTheme(defaultTheme),
defaultVisibility: getUserDefaultVisibility() || "public", defaultVisibility: getUserDefaultVisibility() || "public",
brandName: "Hyperspace",
federated: true federated: true
} }
@ -78,6 +80,13 @@ class SettingsPage extends Component<any, ISettingsState> {
} }
componentDidMount() { componentDidMount() {
getConfig().then((config: any) => {
this.setState({
brandName: config.branding.name
})
}).catch((err: Error) => {
console.error(err.message);
});
this.getFederatedStatus(); this.getFederatedStatus();
} }
@ -265,10 +274,10 @@ class SettingsPage extends Component<any, ISettingsState> {
open={this.state.resetHyperspaceDialog} open={this.state.resetHyperspaceDialog}
onClose={() => this.toggleResetDialog()} onClose={() => this.toggleResetDialog()}
> >
<DialogTitle id="alert-dialog-title">Reset Hyperspace?</DialogTitle> <DialogTitle id="alert-dialog-title">Reset {this.state.brandName}?</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText id="alert-dialog-description"> <DialogContentText id="alert-dialog-description">
Are you sure you want to reset Hyperspace? You'll need to sign in again and grant Hyperspace access to use it again. Are you sure you want to reset {this.state.brandName}? You'll need to re-authorize {this.state.brandName} access again.
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
@ -401,7 +410,7 @@ class SettingsPage extends Component<any, ISettingsState> {
</ListItemSecondaryAction> </ListItemSecondaryAction>
</ListItem> </ListItem>
<ListItem> <ListItem>
<ListItemText primary="Reset Hyperspace" secondary="Deletes all data and resets the app"/> <ListItemText primary={`Reset ${this.state.brandName}`} secondary="Deletes all data and resets the app"/>
<ListItemSecondaryAction> <ListItemSecondaryAction>
<Button onClick={() => this.toggleResetDialog()}> <Button onClick={() => this.toggleResetDialog()}>
Reset Reset

View File

@ -137,10 +137,16 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
} }
getLoginUser(user: string) { getLoginUser(user: string) {
if (this.state.federates || user.includes("@")) { if (user.includes("@")) {
let newUser = user; if (this.state.federates) {
this.setState({ user: newUser }) let newUser = user;
return "https://" + newUser.split("@")[1]; this.setState({ user: newUser });
return "https://" + newUser.split("@")[1];
} else {
let newUser = `${user}@${this.state.registerBase? this.state.registerBase: "mastodon.social"}`;
this.setState({ user: newUser });
return "https://" + (this.state.registerBase? this.state.registerBase: "mastodon.social");
}
} else { } else {
let newUser = `${user}@${this.state.registerBase? this.state.registerBase: "mastodon.social"}`; let newUser = `${user}@${this.state.registerBase? this.state.registerBase: "mastodon.social"}`;
this.setState({ user: newUser }); this.setState({ user: newUser });
@ -154,7 +160,12 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
const scopes = 'read write follow'; const scopes = 'read write follow';
const baseurl = this.getLoginUser(this.state.user); const baseurl = this.getLoginUser(this.state.user);
localStorage.setItem("baseurl", baseurl); 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 = { let saveSessionForCrashing: SaveClientSession = {
clientId: resp.clientId, clientId: resp.clientId,
clientSecret: resp.clientSecret, clientSecret: resp.clientSecret,
@ -178,9 +189,13 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
console.log("Creating an emergency login...") console.log("Creating an emergency login...")
const scopes = "read write follow"; const scopes = "read write follow";
const baseurl = localStorage.getItem('baseurl') || this.getLoginUser(this.state.user); const baseurl = localStorage.getItem('baseurl') || this.getLoginUser(this.state.user);
Mastodon.registerApp(this.state.brandName? this.state.brandName: "Hyperspace", { Mastodon.registerApp(
scopes: scopes this.state.brandName? this.state.brandName: "Hyperspace",
}, baseurl).then((appData: any) => { {
scopes: scopes
},
baseurl
).then((appData: any) => {
let saveSessionForCrashing: SaveClientSession = { let saveSessionForCrashing: SaveClientSession = {
clientId: appData.clientId, clientId: appData.clientId,
clientSecret: appData.clientSecret, clientSecret: appData.clientSecret,
@ -274,7 +289,7 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
localStorage.setItem("access_token", tokenData.access_token); localStorage.setItem("access_token", tokenData.access_token);
window.location.href=`https://${window.location.host}/#/`; window.location.href=`https://${window.location.host}/#/`;
}).catch((err: Error) => { }).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); console.error(err.message);
}) })
} }
@ -336,7 +351,7 @@ class WelcomePage extends Component<IWelcomeProps, IWelcomeState> {
return ( return (
<div> <div>
<Typography variant="h5">Howdy, {this.state.user? this.state.user.split("@")[0]: "user"}</Typography> <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 className={classes.middlePadding}/>
<div style={{ display: "flex" }}> <div style={{ display: "flex" }}>
<div className={classes.flexGrow}/> <div className={classes.flexGrow}/>

View File

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