SlideShare uma empresa Scribd logo
1 de 27
JAVASCRIPT ON   Building desktop apps in

 THE DESKTOP    HTML5 and JavaScript



                      @DOMENIC
DOMENIC
DENICOLA

• https://github.com/domenic
• https://npmjs.org/~domenic
• http://slideshare.net/domenicdenicola


Things I’ve done recently:
• http://es6isnigh.com
• Promises/A+
• Real-World Windows 8 Apps in JS



                                          @DOMENIC
WHY DESKTOP APPS?
Two reasons:




                     @DOMENIC
WHY DESKTOP APPS?




                    @DOMENIC
WHY DESKTOP APPS?




                    @DOMENIC
WHY DESKTOP APPS?




                    @DOMENIC
WHY DESKTOP APPS?




                    @DOMENIC
IN THE WILD




              @DOMENIC
IN THE WILD




              @DOMENIC
HOW?




http://www.chromium.org/developers/content-
module                                        @DOMENIC
THE CHROME CONTENT
API




                @DOMENIC
CHROMIUM EMBEDDED
FRAMEWORK




http://code.google.com/p/chromiumembedded/
                                             @DOMENIC
CHROMIUM EMBEDDED
 FRAMEWORK
• Windows, Mac OS X, Linux
• Create objects in C++, expose them through JS
• Integrate NPAPI plugins
• Intercept HTTP requests, including custom schemes
• Completely customizable browser settings, restrictions, and
  flags
• … and it’s C++, so do whatever you want!




                                                         @DOMENIC
CHROMIUM EMBEDDED
 FRAMEWORK
// Create an instance of our CefClient implementation. Various
// methods in the MyClient instance will be called to notify
// about and customize browser behavior.
CefRefPtr<CefClient> client(new MyClient());

// Information about the parent window, client rectangle, etc.
CefWindowInfo info;
info.SetAsChild(...);

// Browser initialization settings.
CefBrowserSettings settings;

// Create the new browser window object.
CefBrowser::CreateBrowser(info, client, "http://www.google.com",
                          settings);
                                                   @DOMENIC
BUT I DON’T LIKE C++…




          TO THE RESCUE

                   @DOMENIC
TWO PROJECTS, BOTH
ALIKE IN DIGNITY
AppJS     Node-WebKit




                        @DOMENIC
APPJS
var appjs = require('appjs');
appjs.serveFilesFrom(__dirname + '/content');
appjs.router.post('/', function (req, res, next) {
  res.send('Hello, World!');
});
var window = appjs.createWindow({
  url: '/',
  width: 640,
  height: 480,
  fullscreen: false,
  showChrome: true, // border and title bar
  disableSecurity: true // allow cross-origin requests
});


                                                         @DOMENIC
APPJS: CONTROL NODE
 FROM YOUR APP
window.on('ready', function () {
  window.frame.show();
  window.require = require;
  window.process = process;
  window.module = module;
});




                                   @DOMENIC
APPJS: CONTROL YOUR
 APP FROM NODE
window.on('close', ...);
window.on('resize', ...);
window.on('minimize', ...);
window.on('fullscreen', ...);

window.frame.show();
window.frame.hide();
window.frame.fullscreen();
window.frame.openDevTools();

window.dispatchEvent(new window.Event('custom'));




                                                    @DOMENIC
APPJS: MENU BARS
var menu = appjs.createMenu([{
  label: '&File',
  submenu: [
    {
      label: 'E&xit',
      action: function () {
        window.close();
      }
    }
  ]
}]);

window.frame.setMenuBar(menu);


                                 @DOMENIC
APPJS: MORE COOL
 STUFF
• Add tray icons and tray menus
• Add a require that works for modules on both the Node side
  and the browser side
• Redirect Node’s stdout/stderr to the Chromium dev console
• Use Express to handle routes, render views, etc.
• Use any third-party Node package to do anything!




                                                       @DOMENIC
NODE-WEBKIT
<html>
 <head>
  <title>Hello World!</title>
 </head>
 <body>
  <h1>Hello World!</h1>
  <p>We are using node.js
    <script>document.write(process.version);</script>
  </p>
 </body>
</html>




                                                        @DOMENIC
NODE-WEBKIT: A
 TECHNICAL MARVEL
• Not built on CEF; they did the work themselves
• Merged Node and Chromium’s event loops by implementing
  Chromium’s in terms of libuv
  • For example: modal dialogs like alert() block Node’s event loop

• Node objects and DOM objects reside in the same V8 heap:
  no inter-process communication, serialization, or thread
  issues. Direct access!
• Apps can have multiple windows; distinct window
  variables, but shared global variable.
• Great plugin integration: just drop NPAPI plugins into a plugins
  folder.
• Package apps by concatenating them with the nw executable
  (!)                                                @DOMENIC
NODE-WEBKIT:
    PACKAGE.JSON
{
    "name": "nw-demo",
    "main": "index.html",
    "node-main": "start.js",
    "window": {
      "title": "Node-WebKit Demo",
      "icon": "demo.ico",
      "width": 640,
      "height": 480,
      "toolbar": false,
      "fullscreen": false
    }
}


                                     @DOMENIC
NODE-WEBKIT:
 PLATFORM
 INTEGRATION
window.minimize();
window.enterFullscreen();
window.showDevTools();
window.requestAttention(true);
var gui = require('nw.gui');
var menu = new gui.Menu();
menu.append(new gui.MenuItem({
  label: 'Item A',
  icon: 'images/a.png',
  click: function () { }
}));
window.addEventListener('contextmenu', function (event) {
  menu.popup(event.clientX, event.clientY);
});

                                                        @DOMENIC
NODE-WEBKIT:
 PLATFORM
 INTEGRATION
var gui = require('nw.gui');

var clipboard = gui.Clipboard.get();
clipboard.get('text');
clipboard.set('I <3 Node-WebKit', 'text');
clipboard.clear();


<input type="file" />
<input type="file" multiple />
<input type="file" nwdirectory />
<input type="file" nwsaveas />

$('input[type=file]').click();

                                             @DOMENIC
DEMO TIME




            @DOMENIC

Mais conteúdo relacionado

Mais procurados

The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
rajivmordani
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
Domenic Denicola
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yet
Tom Croucher
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
Josh Glover
 

Mais procurados (20)

Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
 
New Design of OneRing
New Design of OneRingNew Design of OneRing
New Design of OneRing
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume LaforgeGroovy Ecosystem - JFokus 2011 - Guillaume Laforge
Groovy Ecosystem - JFokus 2011 - Guillaume Laforge
 
Javascript is your (Auto)mate
Javascript is your (Auto)mateJavascript is your (Auto)mate
Javascript is your (Auto)mate
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
The promise of asynchronous PHP
The promise of asynchronous PHPThe promise of asynchronous PHP
The promise of asynchronous PHP
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Server Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yetServer Side JavaScript - You ain't seen nothing yet
Server Side JavaScript - You ain't seen nothing yet
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
 

Destaque

How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
Domenic Denicola
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
Domenic Denicola
 
Establecimientos comerciales de la manzana 3
Establecimientos comerciales de la manzana 3Establecimientos comerciales de la manzana 3
Establecimientos comerciales de la manzana 3
Cristian Sanchez
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
Solution4Future
 
Folio tahun 5 penjajahan dan tokoh
Folio tahun 5 penjajahan dan tokohFolio tahun 5 penjajahan dan tokoh
Folio tahun 5 penjajahan dan tokoh
Ginny Gouri
 

Destaque (20)

How to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards BodiesHow to Win Friends and Influence Standards Bodies
How to Win Friends and Influence Standards Bodies
 
Real World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScriptReal World Windows 8 Apps in JavaScript
Real World Windows 8 Apps in JavaScript
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
 
The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
 
Client-Side Packages
Client-Side PackagesClient-Side Packages
Client-Side Packages
 
Establecimientos comerciales de la manzana 3
Establecimientos comerciales de la manzana 3Establecimientos comerciales de la manzana 3
Establecimientos comerciales de la manzana 3
 
Estrategia de Desarrollo Local Participativo-AGUJAMA
Estrategia de Desarrollo Local Participativo-AGUJAMAEstrategia de Desarrollo Local Participativo-AGUJAMA
Estrategia de Desarrollo Local Participativo-AGUJAMA
 
Safe Creative qué hacemos y cómo lo hacemos
Safe Creative qué hacemos y cómo lo hacemosSafe Creative qué hacemos y cómo lo hacemos
Safe Creative qué hacemos y cómo lo hacemos
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
e-Marke Checkliste für Wohnungen
e-Marke Checkliste für Wohnungene-Marke Checkliste für Wohnungen
e-Marke Checkliste für Wohnungen
 
Async Frontiers
Async FrontiersAsync Frontiers
Async Frontiers
 
ES6 - Next Generation Javascript
ES6 - Next Generation JavascriptES6 - Next Generation Javascript
ES6 - Next Generation Javascript
 
Domains!
Domains!Domains!
Domains!
 
Oribi deck
Oribi deckOribi deck
Oribi deck
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
The New JavaScript: ES6
The New JavaScript: ES6The New JavaScript: ES6
The New JavaScript: ES6
 
ES2015 (ES6) Overview
ES2015 (ES6) OverviewES2015 (ES6) Overview
ES2015 (ES6) Overview
 
ES6: The Awesome Parts
ES6: The Awesome PartsES6: The Awesome Parts
ES6: The Awesome Parts
 
Folio tahun 5 penjajahan dan tokoh
Folio tahun 5 penjajahan dan tokohFolio tahun 5 penjajahan dan tokoh
Folio tahun 5 penjajahan dan tokoh
 

Semelhante a JavaScript on the Desktop

Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
Robert Nyman
 
Native client
Native clientNative client
Native client
zyc901016
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
維佋 唐
 

Semelhante a JavaScript on the Desktop (20)

Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
 
Sanjeev ghai 12
Sanjeev ghai 12Sanjeev ghai 12
Sanjeev ghai 12
 
Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - Frontmania
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 Apps
 
Intro To webOS
Intro To webOSIntro To webOS
Intro To webOS
 
Txjs
TxjsTxjs
Txjs
 
Node azure
Node azureNode azure
Node azure
 
Intro to jQuery @ Startup Institute
Intro to jQuery @ Startup InstituteIntro to jQuery @ Startup Institute
Intro to jQuery @ Startup Institute
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDK
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 
Native client
Native clientNative client
Native client
 
HTML5 on Mobile
HTML5 on MobileHTML5 on Mobile
HTML5 on Mobile
 
Web versus Native: round 1!
Web versus Native: round 1!Web versus Native: round 1!
Web versus Native: round 1!
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applicationsDisrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
 
Parse cloud code
Parse cloud codeParse cloud code
Parse cloud code
 
NativeScript and Angular
NativeScript and AngularNativeScript and Angular
NativeScript and Angular
 
HTML5 for Rich User Experience
HTML5 for Rich User ExperienceHTML5 for Rich User Experience
HTML5 for Rich User Experience
 

Mais de Domenic Denicola

Mais de Domenic Denicola (7)

ES6 in Real Life
ES6 in Real LifeES6 in Real Life
ES6 in Real Life
 
Streams for the Web
Streams for the WebStreams for the Web
Streams for the Web
 
After Return of the Jedi
After Return of the JediAfter Return of the Jedi
After Return of the Jedi
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
The Extensible Web
The Extensible WebThe Extensible Web
The Extensible Web
 
The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

JavaScript on the Desktop

  • 1. JAVASCRIPT ON Building desktop apps in THE DESKTOP HTML5 and JavaScript @DOMENIC
  • 2. DOMENIC DENICOLA • https://github.com/domenic • https://npmjs.org/~domenic • http://slideshare.net/domenicdenicola Things I’ve done recently: • http://es6isnigh.com • Promises/A+ • Real-World Windows 8 Apps in JS @DOMENIC
  • 3. WHY DESKTOP APPS? Two reasons: @DOMENIC
  • 4. WHY DESKTOP APPS? @DOMENIC
  • 5. WHY DESKTOP APPS? @DOMENIC
  • 6. WHY DESKTOP APPS? @DOMENIC
  • 7. WHY DESKTOP APPS? @DOMENIC
  • 8. IN THE WILD @DOMENIC
  • 9. IN THE WILD @DOMENIC
  • 13. CHROMIUM EMBEDDED FRAMEWORK • Windows, Mac OS X, Linux • Create objects in C++, expose them through JS • Integrate NPAPI plugins • Intercept HTTP requests, including custom schemes • Completely customizable browser settings, restrictions, and flags • … and it’s C++, so do whatever you want! @DOMENIC
  • 14. CHROMIUM EMBEDDED FRAMEWORK // Create an instance of our CefClient implementation. Various // methods in the MyClient instance will be called to notify // about and customize browser behavior. CefRefPtr<CefClient> client(new MyClient()); // Information about the parent window, client rectangle, etc. CefWindowInfo info; info.SetAsChild(...); // Browser initialization settings. CefBrowserSettings settings; // Create the new browser window object. CefBrowser::CreateBrowser(info, client, "http://www.google.com", settings); @DOMENIC
  • 15. BUT I DON’T LIKE C++… TO THE RESCUE @DOMENIC
  • 16. TWO PROJECTS, BOTH ALIKE IN DIGNITY AppJS Node-WebKit @DOMENIC
  • 17. APPJS var appjs = require('appjs'); appjs.serveFilesFrom(__dirname + '/content'); appjs.router.post('/', function (req, res, next) { res.send('Hello, World!'); }); var window = appjs.createWindow({ url: '/', width: 640, height: 480, fullscreen: false, showChrome: true, // border and title bar disableSecurity: true // allow cross-origin requests }); @DOMENIC
  • 18. APPJS: CONTROL NODE FROM YOUR APP window.on('ready', function () { window.frame.show(); window.require = require; window.process = process; window.module = module; }); @DOMENIC
  • 19. APPJS: CONTROL YOUR APP FROM NODE window.on('close', ...); window.on('resize', ...); window.on('minimize', ...); window.on('fullscreen', ...); window.frame.show(); window.frame.hide(); window.frame.fullscreen(); window.frame.openDevTools(); window.dispatchEvent(new window.Event('custom')); @DOMENIC
  • 20. APPJS: MENU BARS var menu = appjs.createMenu([{ label: '&File', submenu: [ { label: 'E&xit', action: function () { window.close(); } } ] }]); window.frame.setMenuBar(menu); @DOMENIC
  • 21. APPJS: MORE COOL STUFF • Add tray icons and tray menus • Add a require that works for modules on both the Node side and the browser side • Redirect Node’s stdout/stderr to the Chromium dev console • Use Express to handle routes, render views, etc. • Use any third-party Node package to do anything! @DOMENIC
  • 22. NODE-WEBKIT <html> <head> <title>Hello World!</title> </head> <body> <h1>Hello World!</h1> <p>We are using node.js <script>document.write(process.version);</script> </p> </body> </html> @DOMENIC
  • 23. NODE-WEBKIT: A TECHNICAL MARVEL • Not built on CEF; they did the work themselves • Merged Node and Chromium’s event loops by implementing Chromium’s in terms of libuv • For example: modal dialogs like alert() block Node’s event loop • Node objects and DOM objects reside in the same V8 heap: no inter-process communication, serialization, or thread issues. Direct access! • Apps can have multiple windows; distinct window variables, but shared global variable. • Great plugin integration: just drop NPAPI plugins into a plugins folder. • Package apps by concatenating them with the nw executable (!) @DOMENIC
  • 24. NODE-WEBKIT: PACKAGE.JSON { "name": "nw-demo", "main": "index.html", "node-main": "start.js", "window": { "title": "Node-WebKit Demo", "icon": "demo.ico", "width": 640, "height": 480, "toolbar": false, "fullscreen": false } } @DOMENIC
  • 25. NODE-WEBKIT: PLATFORM INTEGRATION window.minimize(); window.enterFullscreen(); window.showDevTools(); window.requestAttention(true); var gui = require('nw.gui'); var menu = new gui.Menu(); menu.append(new gui.MenuItem({ label: 'Item A', icon: 'images/a.png', click: function () { } })); window.addEventListener('contextmenu', function (event) { menu.popup(event.clientX, event.clientY); }); @DOMENIC
  • 26. NODE-WEBKIT: PLATFORM INTEGRATION var gui = require('nw.gui'); var clipboard = gui.Clipboard.get(); clipboard.get('text'); clipboard.set('I <3 Node-WebKit', 'text'); clipboard.clear(); <input type="file" /> <input type="file" multiple /> <input type="file" nwdirectory /> <input type="file" nwsaveas /> $('input[type=file]').click(); @DOMENIC
  • 27. DEMO TIME @DOMENIC

Notas do Editor

  1. Hook: I started with C++, wrote desktop apps, moved to JS, etc.
  2. I work at Barnes &amp; Noble.com in the Digital Education division.We produce NOOK Study, an e-textbook reader designed to help students read and annotate their books, as a desktop app for Mac and PC
  3. Everyone still uses computers!
  4. Also: file system access, integration with native code, etc.
  5. Control over your environment
  6. The old problems with desktop apps are disappearing
  7. Chrome Content API: “content” not “Chrome” - Contains only the core code needed to render a page: HTML5, GPU accelerated compositing, etc. - Underlies Chrome’s multiprocess architecture: “chrome” talks to “content” over inter-process communication
  8. You can do this yourself: it’s not fun and it’s not pretty, but you can. Both NOOK Study up through the current version and the original Brackets have done so.But that’s a lot of work, you say. Can’t somebody do that for me??
  9. Hmm. A familiar problem. Wanting to use JavaScript to do something complicated that usually requires a lot of C++. Wanting to do it cross platform. Integrating with the V8 JavaScript engine…
  10. It gives you the raw tools to do things manually