Skip to content

Commit

Permalink
feat(app): Add application installation
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWaller committed Oct 18, 2019
1 parent 25f252b commit 479bd31
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 43 deletions.
21 changes: 21 additions & 0 deletions index.parcel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>PlayOS</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div id="app"></div>
<script src="./index.js" charset="utf-8"></script>
</body>
</html>
Empty file added manifest.json
Empty file.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:prod": "cross-env NODE_ENV=production webpack --config ./webpack.config.js",
"docs": "documentation build ./src > ./docs/codebase.md --shallow false --format md --sort-order alpha",
"release": "standard-version",
"start:parce": "parcel index.parcel.html",
"start": "cross-env NODE_ENV=development webpack-dev-server --config ./webpack.config.js --open true --port 3000 --inline",
"test": "jest",
"lint": "eslint ./src/ --cache --ignore-pattern .gitignore"
Expand Down
8 changes: 4 additions & 4 deletions src/js/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const config = {
domain: DEV_HOST + 'authentication/',
host: DEV_HOST,
homeUrl: DEV_HOST + 'home/',
provider: new RutileProvider('http://localhost:8545/', 101),
coreAddress: '0x776269e69e8fbee4746895ac4fb929139db828c7',
provider: new RutileProvider('http://localhost:8545/', 866, '0x00c7109eb8c03ad5f4383ed0ccbc4035f167aacc'),
coreAddress: '0xb8e0baafd907f3289dbdc0a5174ba786f4b78cf2',
},
production: {
appName: 'Authentication',
Expand All @@ -21,8 +21,8 @@ const config = {
domain: '/',
host: '/',
homeUrl: '#/home',
provider: new RutileProvider('http://localhost:8545/', 101),
coreAddress: '0x776269e69e8fbee4746895ac4fb929139db828c7',
provider: new RutileProvider('http://localhost:8545/', 866, '0x00c7109eb8c03ad5f4383ed0ccbc4035f167aacc'),
coreAddress: '0xb8e0baafd907f3289dbdc0a5174ba786f4b78cf2',
},
};

Expand Down
Empty file.
Empty file added src/js/apps/Explorer/index.ts
Empty file.
58 changes: 58 additions & 0 deletions src/js/components/molecules/SideNavigation/AppInstallDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import { connect } from 'react-redux';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogActions from '@material-ui/core/DialogActions';
import TextField from '@material-ui/core/TextField';
import useMedia from '../../../services/hooks/useMedia';
import { addApplication } from '../../../services/ApplicationService';
import { addSingleApplication } from '../../../store/ApplicationStore';

interface Props {
open: boolean;
onClose: () => void;
dispatch: Function;
}

function AppInstallDialog(props: Props) {
const [manifestTextFieldValue, setManifestTextFieldValue] = React.useState('');
const isDesktop = useMedia('(min-width: 960px)');

async function handleAppInstallClick() {
const app = await addApplication(manifestTextFieldValue);
props.dispatch(addSingleApplication(app));
}

function handleClose() {
setManifestTextFieldValue('');
props.onClose();
}

return (
<Dialog open={props.open} onClose={handleClose} fullScreen={!isDesktop}>
<DialogTitle>Install app via Manifest</DialogTitle>
<DialogContent>
<DialogContentText>
You can install Progressive Web Apps via the manifest.json. Please fill in the location of the manifest.
</DialogContentText>
<TextField
margin="dense"
fullWidth
label="Manifest.json"
value={manifestTextFieldValue}
onChange={(event) => setManifestTextFieldValue(event.target.value)}
/>
</DialogContent>
<DialogActions>
<Button onClick={handleClose}>Cancel</Button>
<Button onClick={handleAppInstallClick} color="primary">Install</Button>
</DialogActions>
</Dialog>
);
}

// @ts-ignore
export default connect()(AppInstallDialog);
47 changes: 31 additions & 16 deletions src/js/components/molecules/SideNavigation/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PowerSettingsNewIcon from '@material-ui/icons/PowerSettingsNew';
import GetAppIcon from '@material-ui/icons/GetApp';
import { setOpenSideBarNavigationState } from '../../../store/SideBarNavigationStore';
import UserService from '../../../services/UserService';
import AppInstallDialog from './AppInstallDialog';
const styles = require('./SideNavigation.scss');

interface Props {
Expand All @@ -17,6 +18,8 @@ interface Props {
}

function SideNavigation(props: Props) {
const [isAppInstallDialogOpen, setAppInstallDialogOpen] = React.useState(false);

function handleDrawerOnClose() {
props.dispatch(setOpenSideBarNavigationState(false));
}
Expand All @@ -26,23 +29,35 @@ function SideNavigation(props: Props) {
location.reload();
}

async function handleInstallAppClick() {
handleDrawerOnClose();
setAppInstallDialogOpen(true);
}

async function handleInstallAppDialogClose() {
setAppInstallDialogOpen(false);
}

return (
<Drawer className={styles.drawer} anchor="right" open={props.isOpen} onClose={handleDrawerOnClose}>
<List className={styles.drawerList}>
<ListItem button>
<ListItemIcon>
<GetAppIcon />
</ListItemIcon>
<ListItemText>Install App</ListItemText>
</ListItem>
<ListItem button onClick={handleLogoutClick}>
<ListItemIcon>
<PowerSettingsNewIcon />
</ListItemIcon>
<ListItemText>Logout</ListItemText>
</ListItem>
</List>
</Drawer>
<>
<Drawer className={styles.drawer} anchor="right" open={props.isOpen} onClose={handleDrawerOnClose}>
<List className={styles.drawerList}>
<ListItem button onClick={handleInstallAppClick}>
<ListItemIcon>
<GetAppIcon />
</ListItemIcon>
<ListItemText>Install App</ListItemText>
</ListItem>
<ListItem button onClick={handleLogoutClick}>
<ListItemIcon>
<PowerSettingsNewIcon />
</ListItemIcon>
<ListItemText>Logout</ListItemText>
</ListItem>
</List>
</Drawer>
<AppInstallDialog open={isAppInstallDialogOpen} onClose={handleInstallAppDialogClose} />
</>
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/js/components/organims/AppSection/AppSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ function AppSection(props: Props) {
<div className={styles.AppSection}>
<div className={styles.wrapper}>
<SwipeableViews enableMouseEvents resistance onChangeIndex={handleChangeIndex} index={viewIndex}>
{appGrids.map((appGrid, index) => {
return <AppGrid grid={appGrid} key={index} />
{appGrids.map((appGrid) => {
return <AppGrid grid={appGrid} key={appGrid.id} />
})}
</SwipeableViews>
<BulletNavigation amount={appGrids.length} activeIndex={viewIndex} onClick={handleChangeIndex} />
Expand All @@ -50,6 +50,7 @@ function AppSection(props: Props) {

const mapStateToProps = (store: any) => {
return {
ApplicationStore: store.ApplicationStore,
apps: store.ApplicationStore.apps,
};
};
Expand Down
10 changes: 5 additions & 5 deletions src/js/models/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ interface Application {
theme_color: string;
manifest_url: string;

properties?: ApplicationProperties,
status: ApplicationStatus,
isFolder?: boolean,
// properties?: ApplicationProperties,
// status: ApplicationStatus,
// isFolder?: boolean,
// isRemoteFolder?: boolean,
apps?: Application[],
// apps?: Application[],
// businessInfo: {
// name: string,
// id: string,
// },
supportedDeviceTypes: string[],
// supportedDeviceTypes: string[],
}

export default Application;
16 changes: 16 additions & 0 deletions src/js/services/ApplicationService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Application from "../models/Application";
import IProvider from "./providers/IProvider";
import Configuration from "../Configuration";

export async function addApplication(manifestUrl: string): Promise<Application> {
const provider: IProvider = Configuration.get('provider');
const response = await fetch(manifestUrl);
const app: Application = await response.json();

app.id = Math.random().toString();
app.manifest_url = manifestUrl;

await provider.addApplicationToStore(app);

return app;
}
7 changes: 6 additions & 1 deletion src/js/services/micro/sortAppsInGrids.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Application from "../../models/Application";

export interface AppGrid {
id: string;
apps: Application[];
}

Expand All @@ -15,6 +16,7 @@ export interface AppGrid {
export default function sortAppsInGrids(apps: Application[], amountPerGrid: number): AppGrid[] {
const result: AppGrid[] = [];
let gridItem: AppGrid = {
id: Math.random().toString(),
apps: [],
};

Expand All @@ -25,7 +27,10 @@ export default function sortAppsInGrids(apps: Application[], amountPerGrid: numb
result.push(gridItem);

// Rest the grid
gridItem = { apps: [] };
gridItem = {
id: Math.random().toString(),
apps: []
};
}
});

Expand Down
1 change: 1 addition & 0 deletions src/js/services/providers/IProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export default interface IProvider {
getPrivateKeyForApp(appId: string, nonce: number, userKeys: PrivateKey): PrivateKey;
storageSet(key: string, value: string): Promise<void>;
storageGet(key: string): Promise<string>;
addApplicationToStore(app: Application): Promise<void>;
}
25 changes: 25 additions & 0 deletions src/js/services/providers/RutileContract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as ethers from "ethers";
import Application from "../../models/Application";

class RutileContract {
contract: ethers.Contract;

constructor(address: string, provider: ethers.providers.JsonRpcProvider, wallet: ethers.Wallet) {
const abi: string[] = [
'function addApplicationToStore(string app)',
];

this.contract = new ethers.Contract(address, abi, wallet);
}

async addApplicationToStore(app: Application) {
const data = ethers.utils.toUtf8Bytes(JSON.stringify(app));
const encodedData = ethers.utils.hexlify(data);

console.log('[] this.contract -> ', this.contract);

await this.contract.addApplicationToStore(encodedData);
}
}

export default RutileContract;
Loading

0 comments on commit 479bd31

Please sign in to comment.