-
Notifications
You must be signed in to change notification settings - Fork 10
/
client.js
151 lines (131 loc) · 3.8 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
const _ = require('lodash');
const Irken = require('irken');
const React = require('react');
const { Router, Route, History, Link } = require('react-router');
const memoryHistory = require('./src/lib/history');
const Layout = require('./src/views/layout');
const HelpOverlay = require('./src/views/help-overlay');
const SaveOverlay = require('./src/views/save-overlay');
const NewVersionOverlay = require('./src/views/new-version-overlay');
const ProjectOverlay = require('./src/views/project-overlay');
const DownloadOverlay = require('./src/views/download-overlay');
const OverwriteOverlay = require('./src/views/overwrite-overlay');
const DeleteFileOverlay = require('./src/views/delete-file-overlay');
const DeleteProjectOverlay = require('./src/views/delete-project-overlay');
const store = require('./src/store');
const app = new Irken();
const examples = _.reduce(EXAMPLES_LIST, function(result, name){
result[name] = require(`./examples/${name}`);
return result;
}, {});
const exampleFolder = 'examples';
const plugins = [
{
register: require('bs2-serial')
},
{
register: require('frylord'),
options: {
useTempFiles: true
}
},
{
register: require('snacks')
},
{
register: require('skrim')
},
{
register: require('iggins')
},
{
register: require('./src/plugins/handlers')
},
{
register: require('./src/plugins/examples'),
options: {
examples,
folder: exampleFolder
}
},
{
register: require('./src/plugins/keyboard-shortcuts')
},
{
register: require('./src/plugins/notifications')
}
];
function onRender(err){
console.log('rendered', err);
if(err){
return;
}
const {
userConfig,
handlers
} = app;
const {
newFile,
showNewVersionOverlay,
changeFile,
changeProject,
deviceAdded
} = handlers;
// Finish Loading Plugin
// TODO: encapsulate into a startup handler?
const config = userConfig.getState();
const cwd = config.cwd || exampleFolder;
const lastFile = config['last-file'];
console.log(cwd, lastFile);
changeProject(cwd)
.then(() => {
if(lastFile){
changeFile(lastFile);
} else {
newFile();
}
showNewVersionOverlay();
})
.catch(console.error.bind(console));
chrome.usb.onDeviceAdded.addListener(function(){
setTimeout(deviceAdded, 200);
});
}
function onRegister(err){
console.log('registered', err, app);
const addMountpoint = app.addMountpoint.bind(app);
const removeMountpoint = app.removeMountpoint.bind(app);
const { workspace, handlers } = app;
if(err){
return;
}
const RouterLayout = React.createClass({
render() {
console.log('render layout', this.props);
return (<Layout addMountpoint={addMountpoint} removeMountpoint={removeMountpoint} app={app}>
{this.props.children && React.cloneElement(this.props.children, { handlers, workspace, store })}
</Layout>
);
}
});
const Component = (
<Router history={memoryHistory}>
<Route path="/" component={RouterLayout}>
<Route path="overlay/help" component={HelpOverlay} />
<Route path="overlay/save" component={SaveOverlay} />
<Route path="overlay/newversion" component={NewVersionOverlay} />
<Route path="overlay/project" component={ProjectOverlay} />
<Route path="overlay/download" component={DownloadOverlay} />
<Route path="overlay/overwrite" component={OverwriteOverlay} />
<Route path="overlay/deletefile" component={DeleteFileOverlay} />
<Route path="overlay/deleteproject" component={DeleteProjectOverlay} />
</Route>
</Router>
);
React.render(Component, document.body.firstChild, onRender);
}
app.register(plugins, onRegister);
// for debugging purposes
window.app = app;
window.memoryHistory = memoryHistory;