Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Better Desktop Apps With Ember

Build Better Desktop Apps With Ember

Talk from Wicked Good Ember 2015.

Abstract:

Ember.js describes itself as a framework for creating ambitious web applications. But “ambitious” doesn’t have to stop at the boundaries of the web world.

Projects such as NW.js have shown that it was possible to write cross-platform desktop applications using web technologies. NW.js goes even further, letting you interact with Node modules directly in the browser. But here’s the catch: without proper guards and good code organization, issues can arise quickly, leaving you fighting your way through an environment where Node and browser contexts don’t always play well together.

In this talk, we will explore some of the challenges you may face, and how you can overcome them with simple tools and techniques. You don’t have to look very far for answers. Ember and Ember CLI provide just the right hooks to make desktop applications a breeze to develop and test.

Wicked Good Ember: http://wickedgoodember.com
DockYard: https://dockyard.com/

Estelle DeBlois

June 16, 2015
Tweet

More Decks by Estelle DeBlois

Other Decks in Technology

Transcript

  1. nw-demo/
 —— app/
 —— bower_components/
 —— config/
 —— dist/
 ——

    node_modules/
 —— public/
 —— tests/
 —— vendor/
 —— bower.json
 —— Brocfile.js
 —— package.json ember new nw-demo
  2. nw-demo/
 —— app/
 —— bower_components/
 —— config/
 —— dist/
 ——

    node_modules/nw/
 —— public/
 —— tests/
 —— vendor/
 —— bower.json
 —— Brocfile.js
 —— package.json npm install —-save-dev nw
  3. nw-demo/
 —— app/
 —— bower_components/
 —— config/
 —— dist/
 ——

    node_modules/nw/
 —— public/
 —— tests/
 —— vendor/
 —— bower.json
 —— Brocfile.js
 —— package.json { “main”: “dist/index.html” }
  4. nw-demo/
 —— app/
 —— bower_components/
 —— config/environment.js
 —— dist/
 ——

    node_modules/nw/
 —— public/
 —— tests/
 —— vendor/
 —— bower.json
 —— Brocfile.js
 —— package.json ENV.locationType = ‘hash’;
  5. window.require function require(name) {
 if (name === ‘nw.gui’) {
 return

    nwDispatcher.requireNwGui();
 } else {
 return global.require(name);
 }
 } (NW.js)
  6. window.require window.require = function() { try { return requireAMD.apply(null, arguments);

    } catch () { return requireNode.apply(null, arguments); } }; (your own)
  7. const fileMenu = new gui.MenuItem({ label: ‘Save’, key: ’s’, modifiers:

    env.ctrlKey, click() { // ... } }); app/nw/menu.js
  8. const fileMenu = new gui.MenuItem({ label: ‘Save’, key: ’s’, modifiers:

    env.ctrlKey, click() { this.sendAction(‘fileSave’); } }); app/nw/menu.js
  9. const fileMenu = new gui.MenuItem({ label: ‘Save’, key: ’s’, modifiers:

    env.ctrlKey, click() { this.sendAction(‘fileSave’); } }); app/nw/menu.js
  10. const fileMenu = new gui.MenuItem({ label: ‘Save’, key: ’s’, modifiers:

    env.ctrlKey, click() { get(this, ‘nw’).trigger(‘fileSave’); } }); app/nw/menu.js
  11. setup: on(‘init’, function() { const nw = get(this, ‘nw’);
 nw.on(‘fileSave’,

    this, ‘doSomething’); }), doSomething() { // ... } app/components/document-pane.js
  12. setup: on(‘init’, function() {
 // Set up handlers from `menuEvents`

    }), menuEvents: { fileSave() { }, fileOpen() { } } app/components/document-pane.js
  13. app/adapter/document.js export default DS.Adapter.extend({ find(store, type, id, snapshot) { const

    fs = require(‘fs’); const path = require(‘path’); const wrench = require(‘wrench’); // ... } });
  14. app/adapter/document.js export default DS.Adapter.extend({ fileService: inject.service(‘file’), find(store, type, id, snapshot)

    { const fs = require(‘fs’); const path = require(‘path’); const wrench = require(‘wrench’); // ... } });
  15. • Configure Testem to launch NW.js. • Log test results

    to process output stream. • Terminate NW.js when all tests have run. ember nw:test
  16. ember nw:test —-server • Configure Testem to launch NW.js. •

    Open a web socket connection to Testem’s server. • Transmit test results to be displayed in the terminal.
  17. nw-demo/
 |_ app/
 |_ bower_components/
 |_ config/
 |_ dist/*
 |_

    node_modules/*
 |_ public/
 |_ tests/
 |_ vendor/
 |_ bower.json
 |_ Brocfile.js
 |_ package.json app.nw
  18. That’s all, Folks! Made with Love by @rwjblue’s wife Cupcakes

    specially ordered by @sugarpirate_… and you can’t have any!