Skip to content

Commit

Permalink
First
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed May 11, 2016
1 parent 7012c51 commit 23c7b47
Show file tree
Hide file tree
Showing 25 changed files with 812 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"presets": ["react", "es2015", "stage-0"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
}]
]
}
},
"plugins": ["transform-runtime"]
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
typings/
node_modules/
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
notifications:
email:
on_success: never
on_failure: change

language: node_js
node_js:
- "node"

env:
- CXX=g++-4.8

addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

before_script:
- export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Desktop tech proof-of-concept

Just playin around with some computering.

```
npm install
```

If you want hot loading:

```
# Start the dev server
npm start
# And in another Terminal, launch the app
npm run dev
```

Or if you don't care:

```
npm run build
npm run dev
```
24 changes: 24 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
environment:
nodejs_version: "5"

branches:
only:
- master

skip_tags: true

version: "{build}"

install:
- ps: Install-Product node $env:nodejs_version
- npm install

test_script:
- node --version
- npm --version
- npm test

build: off

cache:
- node_modules
22 changes: 22 additions & 0 deletions dev_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var express = require('express')
var webpack = require('webpack')
var config = require('./webpack.config')

var app = express()
var compiler = webpack(config)
var port = process.env.PORT || 3000

app.use(require('webpack-dev-middleware')(compiler, {
publicPath: config.output.publicPath
}))

app.use(require('webpack-hot-middleware')(compiler))

app.listen(port, 'localhost', err => {
if (err) {
console.log(err)
return
}

console.log(`Listening at http://localhost:${port}`)
})
52 changes: 52 additions & 0 deletions lib/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react'
import ThingList from './thing-list'
import Info from './info'

const Octokat = require('octokat')

type AppState = {
selectedRow: number
}

type AppProps = {
style?: Object
}

const AppStyle = {
display: 'flex',
flexDirection: 'row',
flexGrow: 1
}

export default class App extends React.Component<AppProps, AppState> {
private octo: any

public constructor(props: AppProps) {
super(props)

this.octo = new Octokat({
token: process.env.GITHUB_ACCESS_TOKEN
})

this.state = {selectedRow: -1}
}

public async componentDidMount() {
const zen = await this.octo.zen.read()
console.log('zen', zen)
}

public render() {
const completeStyle = Object.assign({}, this.props.style, AppStyle)
return (
<div style={completeStyle}>
<ThingList selectedRow={this.state.selectedRow} onSelectionChanged={row => this.handleSelectionChanged(row)}/>
<Info selectedRow={this.state.selectedRow}/>
</div>
)
}

private handleSelectionChanged(row: number) {
this.setState({selectedRow: row})
}
}
35 changes: 35 additions & 0 deletions lib/browser/app-window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {BrowserWindow} from 'electron'

import Stats from './stats'

export default class AppWindow extends BrowserWindow {
private stats: Stats

public constructor(stats: Stats) {
super({width: 800, height: 600, show: false, titleBarStyle: 'hidden'})

this.stats = stats
}

public load() {
let startLoad: number = null
this.webContents.on('did-finish-load', () => {
if (process.env.NODE_ENV === 'development') {
this.webContents.openDevTools()
}

this.show()

const now = Date.now()
this.rendererLog(`Loading: ${now - startLoad}ms`)
this.rendererLog(`Launch: ${now - this.stats.launchTime}ms`)
})

startLoad = Date.now()
this.loadURL(`file://${__dirname}/../../static/index.html`)
}

private rendererLog(msg: string) {
this.webContents.send('log', msg)
}
}
25 changes: 25 additions & 0 deletions lib/browser/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {app} from 'electron'

import AppWindow from './app-window'
import Stats from './stats'

const stats = new Stats()

let mainWindow: AppWindow = null

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

app.on('ready', () => {
stats.readyTime = Date.now()

mainWindow = new AppWindow(stats)
mainWindow.on('closed', () => {
mainWindow = null
})

mainWindow.load()
})
8 changes: 8 additions & 0 deletions lib/browser/stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default class Stats {
public launchTime: number
public readyTime: number

public constructor() {
this.launchTime = Date.now()
}
}
16 changes: 16 additions & 0 deletions lib/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from 'react'
import * as ReactDOM from 'react-dom'

import {ipcRenderer} from 'electron'

import App from './app'

ipcRenderer.on('log', (event, msg) => {
console.log(msg)
})

const style = {
paddingTop: process.platform === 'darwin' ? 20 : 0
}

ReactDOM.render(<App style={style}/>, document.getElementById('content'))
53 changes: 53 additions & 0 deletions lib/info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from 'react'

const LOLZ = [
'http://www.reactiongifs.com/r/drkrm.gif',
'http://www.reactiongifs.com/r/wvy1.gif',
'http://www.reactiongifs.com/r/ihniwid.gif',
'http://www.reactiongifs.com/r/dTa.gif',
'http://www.reactiongifs.com/r/didit.gif'
]

type InfoProps = {
selectedRow: number
}

const ContainerStyle = {
display: 'flex',
flexDirection: 'column',
flex: 1
}

const ImageStyle = {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
flex: 1
}

export default class Info extends React.Component<InfoProps, void> {
private renderNoSelection() {
return (
<div>No row selected!</div>
)
}

public render() {
const row = this.props.selectedRow
if (row < 0) {
return this.renderNoSelection()
}

const img = LOLZ[row % LOLZ.length]
return (
<div style={ContainerStyle}>
Row {row + 1} is selected!

<div style={ImageStyle}>
<img src={img}/>
</div>
</div>
)
}
}
Loading

0 comments on commit 23c7b47

Please sign in to comment.