Skip to content

Commit 37a4e8d

Browse files
committed
Simplified and unified layout for performance and maintainance reasons.
1 parent be4e333 commit 37a4e8d

File tree

21 files changed

+459
-397
lines changed

21 files changed

+459
-397
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"jsdoc": "^3.5.5",
1212
"npm": "^5.8.0",
1313
"npm-check-updates": "^2.14.1",
14-
"nw": "^0.29.3",
14+
"nw": "^0.29.4",
1515
"nw-builder": "^3.5.1",
1616
"rimraf": "^2.6.2"
1717
},

src/mode/default/mod.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,27 +191,20 @@ cwc.mode.default.Mod.prototype.decorateEditor = function() {
191191

192192

193193
/**
194-
* Decorates the Editor layout.
194+
* Decorates the Preview / Editor layout.
195195
*/
196196
cwc.mode.default.Mod.prototype.decorateLayout = function() {
197197
let layoutInstance = this.helper.getInstance('layout', true);
198+
layoutInstance.decorateDefault();
199+
if (this.blockly) {
200+
layoutInstance.renderEditorContent(cwc.soy.mode.default.Layout.blockly);
201+
} else {
202+
layoutInstance.renderEditorContent(cwc.soy.mode.default.Layout.editor);
203+
}
198204
if (this.runner) {
199-
layoutInstance.decorateDefault();
200-
layoutInstance.setFixRightComponentSize(400);
201-
if (this.blockly) {
202-
layoutInstance.renderMiddleContent(cwc.soy.mode.default.Layout.blockly);
203-
} else {
204-
layoutInstance.renderMiddleContent(cwc.soy.mode.default.Layout.editor);
205-
}
206-
layoutInstance.renderRightContent(cwc.soy.mode.default.Layout.runner);
207-
} else if (this.blockly) {
208-
layoutInstance.decorateDefault(400);
209-
layoutInstance.renderMiddleContent(cwc.soy.mode.default.Layout.preview);
210-
layoutInstance.renderRightContent(cwc.soy.mode.default.Layout.blockly);
205+
layoutInstance.renderPreviewContent(cwc.soy.mode.default.Layout.runner);
211206
} else {
212-
layoutInstance.decorateDefault(700);
213-
layoutInstance.renderMiddleContent(cwc.soy.mode.default.Layout.editor);
214-
layoutInstance.renderRightContent(cwc.soy.mode.default.Layout.preview);
207+
layoutInstance.renderPreviewContent(cwc.soy.mode.default.Layout.preview);
215208
}
216209
};
217210

src/protocol/low-level/tcp/http_server.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ cwc.protocol.tcp.HTTPServer.prototype.listen = function(port, address) {
9292
}
9393
if (this.port && this.address) {
9494
this.database_.open();
95-
chrome.sockets.tcpServer.create({}, this.handleCreate_.bind(this));
95+
chrome.sockets.tcpServer.create({
96+
'persistent': false,
97+
}, this.handleCreate_.bind(this));
9698
}
9799
};
98100

@@ -168,6 +170,15 @@ cwc.protocol.tcp.HTTPServer.prototype.getRootURL = function() {
168170
};
169171

170172

173+
/**
174+
* Close tcp server.
175+
*/
176+
cwc.protocol.tcp.HTTPServer.prototype.close = function() {
177+
this.closeSocket_(this.socketId_);
178+
this.unlisten();
179+
};
180+
181+
171182
/**
172183
* HTTP response handler
173184
* @param {!string} content
@@ -187,7 +198,7 @@ cwc.protocol.tcp.HTTPServer.prototype.httpResponse_ = function(content,
187198
chrome.sockets.tcp.getInfo(clientSocketId, function(socketInfo) {
188199
if (!socketInfo['connected']) {
189200
this.log_.error('Socket is no longer connected', socketInfo);
190-
this.disconnectClientSocket_(clientSocketId);
201+
this.disconnectSocket_(clientSocketId);
191202
return;
192203
}
193204

@@ -288,6 +299,15 @@ cwc.protocol.tcp.HTTPServer.prototype.handleCreate_ = function(createInfo) {
288299
* @private
289300
*/
290301
cwc.protocol.tcp.HTTPServer.prototype.handleListen_ = function(result) {
302+
if (chrome.runtime.lastError) {
303+
this.log_.error('Unable to connect to server',
304+
chrome.runtime.lastError.message);
305+
if (chrome.runtime.lastError.message.includes('ERR_ADDRESS_IN_USE')) {
306+
this.port++;
307+
this.listen();
308+
}
309+
return;
310+
}
291311
if (result < 0) {
292312
this.log_.error('Unable to connect to server', result);
293313
return;
@@ -378,7 +398,7 @@ cwc.protocol.tcp.HTTPServer.prototype.handleRecieve_ = function(receiveInfo) {
378398
}
379399
} else {
380400
this.log_.info('Unsupported request', data);
381-
this.disconnectClientSocket_(receiveInfo['socketId']);
401+
this.disconnectSocket_(receiveInfo['socketId']);
382402
}
383403
};
384404

@@ -389,7 +409,7 @@ cwc.protocol.tcp.HTTPServer.prototype.handleRecieve_ = function(receiveInfo) {
389409
*/
390410
cwc.protocol.tcp.HTTPServer.prototype.handleRecieveError_ = function(error) {
391411
if (error['resultCode'] === -100) {
392-
this.closeClientSocket_(error['socketId']);
412+
this.closeSocket_(error['socketId']);
393413
} else {
394414
this.log_.error('Receive Error Handler', error);
395415
}
@@ -399,17 +419,21 @@ cwc.protocol.tcp.HTTPServer.prototype.handleRecieveError_ = function(error) {
399419
/**
400420
* @param {!number} socketId
401421
*/
402-
cwc.protocol.tcp.HTTPServer.prototype.closeClientSocket_ = function(socketId) {
422+
cwc.protocol.tcp.HTTPServer.prototype.closeSocket_ = function(socketId) {
423+
if (chrome.runtime.lastError) {
424+
this.log_.error('Unable to close socket: ',
425+
chrome.runtime.lastError.message);
426+
return;
427+
}
403428
chrome.sockets.tcp.close(socketId);
404429
};
405430

406431

407432
/**
408433
* @param {!number} socketId
409434
*/
410-
cwc.protocol.tcp.HTTPServer.prototype.disconnectClientSocket_ = function(
411-
socketId) {
435+
cwc.protocol.tcp.HTTPServer.prototype.disconnectSocket_ = function(socketId) {
412436
chrome.sockets.tcp.disconnect(socketId, function() {
413-
this.closeClientSocket_(socketId);
437+
this.closeSocket_(socketId);
414438
}.bind(this));
415439
};

src/server/server.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ cwc.server.Server = function(helper) {
4141
/** @type {cwc.protocol.tcp.HTTPServer} */
4242
this.httpServer = null;
4343

44-
/** @type {!string} */
45-
this.httpServerPrefix = 'http://localhost:8090';
46-
4744
/** @type {!string} */
4845
this.previewFile = '/preview.html';
4946
};
@@ -126,7 +123,7 @@ cwc.server.Server.prototype.setPreview = function(content) {
126123
* @return {!string}
127124
*/
128125
cwc.server.Server.prototype.getFrameworkFileURL = function(name) {
129-
return this.httpServerPrefix + name;
126+
return this.getRootURL() + name;
130127
};
131128

132129

@@ -142,6 +139,6 @@ cwc.server.Server.prototype.getRootURL = function() {
142139
* @return {!string}
143140
*/
144141
cwc.server.Server.prototype.getPreviewURL = function() {
145-
return this.httpServerPrefix + this.previewFile + '?' +
142+
return this.getRootURL() + this.previewFile + '?' +
146143
Math.floor(Math.random() * 100000000);
147144
};

src/ui/blockly/toolbar/blockly_toolbar.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,17 @@ cwc.ui.BlocklyToolbar.prototype.updateLibraryButton = function(has_files) {
281281

282282
/**
283283
* Toggles the current expand state.
284-
* @param {goog.events.EventLike} e
285284
*/
286-
cwc.ui.BlocklyToolbar.prototype.expand = function(e) {
287-
this.setExpand(true, e.target.closest('.goog-splitpane-second-container'));
285+
cwc.ui.BlocklyToolbar.prototype.expand = function() {
286+
this.setExpand(true);
288287
};
289288

290289

291290
/**
292291
* Toggles the current expand state.
293-
* @param {goog.events.EventLike} e
294292
*/
295-
cwc.ui.BlocklyToolbar.prototype.collapse = function(e) {
296-
this.setExpand(false, e.target.closest('.goog-splitpane-second-container'));
293+
cwc.ui.BlocklyToolbar.prototype.collapse = function() {
294+
this.setExpand(false);
297295
};
298296

299297

@@ -308,17 +306,12 @@ cwc.ui.BlocklyToolbar.prototype.toggleExpand = function() {
308306
/**
309307
* Expands or collapses the current window.
310308
* @param {boolean} expand
311-
* @param {boolean=} invert
312309
*/
313-
cwc.ui.BlocklyToolbar.prototype.setExpand = function(expand, invert = false) {
310+
cwc.ui.BlocklyToolbar.prototype.setExpand = function(expand) {
314311
this.expandState = expand;
315312
let layoutInstance = this.helper.getInstance('layout', true);
316313
if (layoutInstance) {
317-
if (invert) {
318-
layoutInstance.setFullscreen(expand, 0);
319-
} else {
320-
layoutInstance.setFullscreen(expand);
321-
}
314+
layoutInstance.setFullscreenEditor(expand);
322315
goog.style.setElementShown(this.nodeExpand, !expand);
323316
goog.style.setElementShown(this.nodeExpandExit, expand);
324317
}

src/ui/editor/toolbar/editor_toolbar.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,17 @@ cwc.ui.EditorToolbar.prototype.addView = function(name) {
437437

438438
/**
439439
* Toggles the current expand state.
440-
* @param {goog.events.EventLike} e
441440
*/
442-
cwc.ui.EditorToolbar.prototype.expand = function(e) {
443-
this.setExpand(true, e.target.closest('.goog-splitpane-second-container'));
441+
cwc.ui.EditorToolbar.prototype.expand = function() {
442+
this.setExpand(true);
444443
};
445444

446445

447446
/**
448447
* Toggles the current expand state.
449-
* @param {goog.events.EventLike} e
450448
*/
451-
cwc.ui.EditorToolbar.prototype.collapse = function(e) {
452-
this.setExpand(false, e.target.closest('.goog-splitpane-second-container'));
449+
cwc.ui.EditorToolbar.prototype.collapse = function() {
450+
this.setExpand(false);
453451
};
454452

455453

@@ -464,17 +462,12 @@ cwc.ui.EditorToolbar.prototype.toggleExpand = function() {
464462
/**
465463
* Expands or collapses the current window.
466464
* @param {boolean} expand
467-
* @param {boolean=} invert
468465
*/
469-
cwc.ui.EditorToolbar.prototype.setExpand = function(expand, invert = false) {
466+
cwc.ui.EditorToolbar.prototype.setExpand = function(expand) {
470467
this.expandState = expand;
471468
let layoutInstance = this.helper.getInstance('layout', true);
472469
if (layoutInstance) {
473-
if (invert) {
474-
layoutInstance.setFullscreen(expand, 0);
475-
} else {
476-
layoutInstance.setFullscreen(expand);
477-
}
470+
layoutInstance.setFullscreenEditor(expand);
478471
goog.style.setElementShown(this.nodeExpand, !expand);
479472
goog.style.setElementShown(this.nodeExpandExit, expand);
480473
}

src/ui/layout/layout.gss

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@
2121
}
2222

2323
#{$prefix}layout-content-overlay {
24-
top: 0;
2524
left: 0;
25+
overflow: auto;
2626
position: absolute;
27+
top: 0;
2728
z-index: 1000;
28-
overflow: auto;
2929
}
3030

31-
#{$prefix}layout-content-left-chrome,
32-
#{$prefix}layout-content-middle-chrome,
33-
#{$prefix}layout-content-right-chrome {
31+
#{$prefix}layout-content-editor-chrome,
32+
#{$prefix}layout-content-preview-chrome {
3433
display: flex;
3534
flex-direction: column;
3635
}

0 commit comments

Comments
 (0)