Skip to content

Commit

Permalink
Refactor window bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Jun 7, 2016
1 parent 5791279 commit 4c850d8
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 82 deletions.
61 changes: 43 additions & 18 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,63 @@
global.START_TIME = Date.now()
global.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {}

const decode = decodeURIComponent
const hash = window.location.hash.slice(1)
{
const decode = decodeURIComponent
const hash = window.location.hash.slice(1)

if (process.env.NODE_ENV !== 'test') {
global.args = Object.freeze(JSON.parse(decode(hash)))
if (process.env.NODE_ENV !== 'test') {
global.args = Object.freeze(JSON.parse(decode(hash)))

process.env.NODE_ENV = global.args.environment
process.env.DEBUG = global.args.debug
process.env.NODE_ENV = global.args.environment
process.env.DEBUG = global.args.debug

} else {
global.args = {
environment: 'test',
debug: process.env.DEBUG
} else {
global.args = {
environment: 'test',
debug: process.env.DEBUG
}
}
}


const { verbose } = require('./common/log')(global.args.home)
const { basename } = require('path')
const { release } = require('os')
const { ready, append, stylesheet, toggle } = require('./dom')

const PAGE = basename(window.location.pathname, '.html')

ready(() => {
verbose('%s ready after %dms', PAGE, Date.now() - global.START_TIME)

append(
stylesheet(`../lib/stylesheets/${process.platform}/${PAGE}.css`),
document.head)

if (!global.args.frame) {
toggle(document.body, 'frameless', true)
}

if (process.platform === 'darwin' && release() > '15') {
toggle(document.body, 'hidden-inset', true)
}
})


if (global.args.environment === 'development') {
if (process.platform !== 'linux') {
const props = Object.defineProperties
const { remote } = require('electron')
const props = Object.defineProperties

props(process, {
stdout: { value: remote.process.stdout },
stderr: { value: remote.process.stderr }
})
}

try {
require('devtron').install()
} catch (_) {
// ignore
}
// try {
// require('devtron').install()
// } catch (_) {
// // ignore
// }
}

require('./common/log')(global.args.home)
14 changes: 6 additions & 8 deletions src/browser/tropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ module.exports = class Tropy extends EventEmitter {

this.win = new Window()
.once('closed', () => { this.win = undefined })
.open('index.html', this.hash)
.open('project.html', this.hash)

this.dummy()
this.dummy(true)
this.dummy(os.platform() !== 'darwin')

return this
}

dummy(frame = false) {
this.dummies = this.dummies || []
if (this.dum) return this.dum.show(), this

const options = { width: 1440, height: 878 }

if (!frame) {
Expand All @@ -69,12 +69,10 @@ module.exports = class Tropy extends EventEmitter {
}
}

const idx = this.dummies.length
const dum = new Window(options)
.once('closed', () => { this.dummies.splice(idx, 1) })
this.dum = new Window(options)
.once('closed', () => { this.dum = undefined })
.open('dummy.html', { frame, ...this.hash })

this.dummies.push(dum)
return this
}

Expand Down
2 changes: 0 additions & 2 deletions src/stylesheets/darwin.scss

This file was deleted.

3 changes: 3 additions & 0 deletions src/stylesheets/darwin/dummy.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$platform: "darwin";
@import "../common";
@import "../dummy";
2 changes: 2 additions & 0 deletions src/stylesheets/darwin/project.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$platform: "darwin";
@import "../common";
3 changes: 0 additions & 3 deletions src/stylesheets/dummy-darwin.scss

This file was deleted.

3 changes: 0 additions & 3 deletions src/stylesheets/dummy-linux.scss

This file was deleted.

3 changes: 0 additions & 3 deletions src/stylesheets/dummy-win32.scss

This file was deleted.

2 changes: 0 additions & 2 deletions src/stylesheets/linux.scss

This file was deleted.

3 changes: 3 additions & 0 deletions src/stylesheets/linux/dummy.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$platform: "linux";
@import "../common";
@import "../dummy";
2 changes: 2 additions & 0 deletions src/stylesheets/linux/project.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$platform: "linux";
@import "../common";
2 changes: 0 additions & 2 deletions src/stylesheets/win32.scss

This file was deleted.

3 changes: 3 additions & 0 deletions src/stylesheets/win32/dummy.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$platform: "win32";
@import "../common";
@import "../dummy";
2 changes: 2 additions & 0 deletions src/stylesheets/win32/project.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$platform: "win32";
@import "../common";
2 changes: 1 addition & 1 deletion static/dummy.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="dummy.js"></script>
</head>
<body tabindex="-1">
<div class="container">
Expand All @@ -18,6 +19,5 @@
--><button tabindex="-1" class="maximize no-drag"></button>
</div>
</div>
<script src="dummy.js"></script>
</body>
</html>
23 changes: 4 additions & 19 deletions static/dummy.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
'use strict'

{
const { ready, append, stylesheet, $, on, toggle } = require('../lib/dom')
const { info } = require('../lib/common/log')
const { release } = require('os')
const { ready, $, on, toggle } = require('../lib/dom')

ready(() => {
info('dummy ready after %sms', Date.now() - global.START_TIME)
on($('.container'), 'click', function () {
toggle(this, 'item')
})
})

append(
stylesheet(`../lib/stylesheets/dummy-${process.platform}.css`),
document.head)

on($('.container'), 'click', function () {
toggle(this, 'item')
})

if (!global.args.frame) {
toggle(document.body, 'frameless', true)

if (process.platform === 'darwin' && release() > '10.10') {
toggle(document.body, 'hidden-inset', true)
}
}
}
20 changes: 0 additions & 20 deletions static/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion static/index.html → static/project.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="index.js"></script>
<script src="project.js"></script>
</head>
<body tabindex="-1">
</body>
Expand Down
13 changes: 13 additions & 0 deletions static/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

{
const { name } = require('../package')
const { ready } = require('../lib/dom')
const v = process.versions

ready(() => {
document.body.innerHTML =
`${name} ${process.env.NODE_ENV} ${v.electron} / ${v.node}`

})
}

0 comments on commit 4c850d8

Please sign in to comment.