Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6fd61b

Browse files
authoredJul 16, 2017
Improves window chrome and demos dragging. (#11)
1 parent 14a6878 commit c6fd61b

File tree

9 files changed

+75
-10
lines changed

9 files changed

+75
-10
lines changed
 

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@
7171
"postinstall": "Used by electron-builder to build native dependencies.",
7272
"start": "Starts the app in dev mode."
7373
},
74-
"version": "0.5.0"
74+
"version": "0.6.0"
7575
}

‎src/main/create-window.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ const DIMENSIONS = { width: 800, height: 500 }
1212
* @return The main BrowserWindow.
1313
*/
1414
export function createWindow(appPath: string) {
15-
const window = new BrowserWindow(DIMENSIONS)
16-
15+
const window = new BrowserWindow({
16+
...DIMENSIONS,
17+
show: false,
18+
useContentSize: true,
19+
titleBarStyle: 'hidden'
20+
})
21+
1722
// load entry html page in the renderer.
1823
window.loadURL(
1924
format({
@@ -23,5 +28,12 @@ export function createWindow(appPath: string) {
2328
})
2429
)
2530

31+
// only appear once we've loaded
32+
window.webContents.on('did-finish-load', () => {
33+
window.show()
34+
window.focus()
35+
})
36+
37+
2638
return window
2739
}

‎src/renderer/app/app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { Text, Logo, FunDog } from '../platform'
2+
import { Text, Logo, FunDog, Vignette } from '../platform'
33
// import * as log from 'electron-log'
44

55
const appStyle = {
@@ -19,6 +19,7 @@ const appStyle = {
1919
cursor: 'default'
2020
}
2121

22+
2223
const textStyle = {
2324
paddingTop: 20,
2425
paddingBottom: 20
@@ -37,6 +38,7 @@ export class App extends React.Component<{}, {}> {
3738
render() {
3839
return (
3940
<div style={appStyle}>
41+
<Vignette opacity={0.3} />
4042
<Logo />
4143
<Text style={textStyle}>Wake up and smell the electrons.</Text>
4244
<FunDog />

‎src/renderer/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ import * as ReactDOM from 'react-dom'
33
import { App } from './app/app'
44

55
ReactDOM.render(<App />, document.getElementById('root'))
6+
7+
// prevent drag & drop replacing the whole browser window
8+
document.addEventListener('dragover', event => event.preventDefault())
9+
document.addEventListener('drop', event => event.preventDefault())

‎src/renderer/platform/components/fun-dog/fun-dog.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,12 @@ const style = {
99
}
1010

1111
export function FunDog() {
12-
return <img src={dogImage} style={style} alt="Photo by Braydon Anderson on Unsplash" />
12+
return (
13+
<img
14+
draggable={false}
15+
src={dogImage}
16+
style={style}
17+
alt="Photo by Braydon Anderson on Unsplash"
18+
/>
19+
)
1320
}

‎src/renderer/platform/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
export * from './text/text'
44
export * from './logo/logo'
55
export * from './fun-dog/fun-dog'
6+
export * from './vignette/vignette'
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import * as React from 'react'
22
import icon from './electron-icon.svg'
3+
import { Text } from '..'
34

4-
const style = {
5-
width: 80,
6-
height: 80,
7-
animation: 'spin360 infinite 5s linear'
5+
const containerStyle = {
6+
WebkitAppRegion: 'drag',
7+
display: 'flex',
8+
flexDirection: 'column',
9+
alignItems: 'center'
810
}
11+
const imageStyle = { width: 80, height: 80, animation: 'spin360 infinite 5s linear' }
12+
const textStyle = { WebkitAppRegion: 'no-drag', fontSize: '0.6rem' }
913

1014
export function Logo() {
11-
return <img src={icon} style={style} />
15+
return (
16+
<div style={containerStyle}>
17+
<img draggable={false} src={icon} style={imageStyle} />
18+
<Text style={textStyle}>Drag the logo to move the window.</Text>
19+
</div>
20+
)
1221
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react'
2+
3+
export interface VignetteProps {
4+
/** the intensity of the shadow from 0.0 to 1.0 */
5+
opacity?: number
6+
/** the size of the shadow (default '200px') */
7+
size?: number | string
8+
}
9+
10+
/**
11+
* Draws a shadowed subtle border.
12+
*/
13+
export function Vignette(props: VignetteProps) {
14+
const opacity = props.opacity || 0.3
15+
const size = props.size || '200px'
16+
17+
const vignetteStyle = {
18+
position: 'fixed',
19+
top: 0,
20+
left: 0,
21+
width: '100%',
22+
height: '100%',
23+
boxShadow: `0 0 ${size} rgba(0,0,0,${opacity}) inset`
24+
}
25+
26+
return <div style={vignetteStyle} />
27+
}

‎src/renderer/reset.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*:focus {
44
outline: 0;
55
}
6+
html, body {
7+
user-select: none;
8+
}
69

710
body,
811
h1,

0 commit comments

Comments
 (0)
This repository has been archived.