| OLD | NEW |
| 1 <h1 id="lab_2_work_with_code">Lab 2 - Work with code</h1> | 1 <h1 id="lab_2_work_with_code">Create Basic App</h1> |
| 2 | 2 |
| 3 <h2 id="create_your_first_chrome_app">Create your first Chrome app</h2> | 3 <p>There are three core pieces to any Chrome packaged app:</p> |
| 4 | |
| 5 <p>There are three core pieces to any Chrome app:</p> | |
| 6 | 4 |
| 7 <ul> | 5 <ul> |
| 8 <li>The manifest that descibes meta-information about your applicaiton: name, de
scription, version number and how to launch your application</li> | 6 <li>The manifest that describes meta-information about your application: |
| 9 <li>The background script, which sets up how your application responds to system
events such as the user installing and launching the app and the system suspend
ing it</li> | 7 name, description, version number and how to launch your application</li> |
| 10 <li>The view (which is optional, but you normally need to show the user somethin
g)</li> | 8 <li>The background script, |
| 9 which sets up how your application responds to system events |
| 10 such as the user installing and launching the app and the system suspending it</
li> |
| 11 <li>The view |
| 12 (which is optional, but you normally need to show the user something)</li> |
| 11 </ul> | 13 </ul> |
| 12 | 14 |
| 13 <p>Let's look at each of these components at their simplest level. </p> | 15 <p>Let's look at each of these components at their simplest level.</p> |
| 14 | 16 |
| 15 <ol> | 17 <p class="note"><b>Tip:</b> |
| 16 <li><p>In an empty directory (let's call it <code><myappdir></code>),
create three files:</p> | 18 If you use the Sublime Text editor with |
| 19 <a href="http://www.youtube.com/watch?v=x_FTILqlbsg&hd=1">our plugin</a>, |
| 20 you can create these three files with a click (Chrome -> New App -> Hello
World). |
| 21 </p> |
| 17 | 22 |
| 18 <ul> | 23 <h2 id="manifest">Create manifest</h2> |
| 19 <li>Manifest: <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/m
aster/lab2_basic/manifest.json">manifest.json</a> | 24 |
| 25 <p>In an empty directory (let's call it <code><myappdir></code>), |
| 26 create the manifest file: <a href="https://github.com/GoogleChrome/chrome-app-co
delab/blob/master/lab2_basic/manifest.json">manifest.json</a> |
| 27 </p> |
| 28 |
| 20 <pre> | 29 <pre> |
| 21 { | 30 { |
| 22 "manifest_version": 2, | 31 "manifest_version": 2, |
| 23 "name": "My first app", | 32 "name": "My first app", |
| 24 "version": "1", | 33 "version": "1", |
| 25 "app": { | 34 "app": { |
| 26 "background": { | 35 "background": { |
| 27 "scripts": ["main.js"] | 36 "scripts": ["main.js"] |
| 28 } | 37 } |
| 29 } | 38 } |
| 30 } | 39 } |
| 31 </pre></li> | 40 </pre> |
| 32 <li>Background script: <a href="https://github.com/GoogleChrome/chrome-app-codel
ab/blob/master/lab2_basic/main.js">main.js</a> | 41 |
| 42 <h2 id="background">Create background script</h2> |
| 43 |
| 44 <p>In the same directory, |
| 45 create the background script: <a href="https://github.com/GoogleChrome/chrome-ap
p-codelab/blob/master/lab2_basic/main.js">main.js</a> |
| 46 |
| 33 <pre> | 47 <pre> |
| 34 chrome.app.runtime.onLaunched.addListener(function() { | 48 chrome.app.runtime.onLaunched.addListener(function() { |
| 35 chrome.app.window.create('index.html', { | 49 chrome.app.window.create('index.html', { |
| 36 bounds: { | 50 bounds: { |
| 37 width: 500, | 51 width: 500, |
| 38 height: 309 | 52 height: 309 |
| 39 } | 53 } |
| 40 }); | 54 }); |
| 41 }); | 55 }); |
| 42 </pre></li> | 56 </pre> |
| 43 <li>User interface: <a href="https://github.com/GoogleChrome/chrome-app-codelab/
blob/master/lab2_basic/index.html">index.html</a> | 57 |
| 58 <h2 id="view">Create view</h2> |
| 59 |
| 60 <p>Create the user interface: <a href="https://github.com/GoogleChrome/chrome-ap
p-codelab/blob/master/lab2_basic/index.html">index.html</a> |
| 61 |
| 44 <pre> | 62 <pre> |
| 45 <html> | 63 <html> |
| 46 <head> | 64 <head> |
| 47 <meta charset="utf-8"> | 65 <meta charset="utf-8"> |
| 48 <title>Hello World</title> | 66 <title>Hello World</title> |
| 49 </head> | 67 </head> |
| 50 <body> | 68 <body> |
| 51 <h1>Hello, World!</h1> | 69 <h1>Hello, World!</h1> |
| 52 </body> | 70 </body> |
| 53 </html> | 71 </html> |
| 54 </pre></li> | 72 </pre> |
| 55 </ul></li> | 73 |
| 56 <li><p>Install and execute your sample app: </p> | 74 <h2 id="install">Install and execute sample app</h2> |
| 57 | 75 |
| 58 <ul> | 76 <ul> |
| 59 <li>Go to <code>chrome://extensions</code>.</li> | 77 <li>Go to <code>chrome://extensions</code>.</li> |
| 60 <li>Load unpacked extension...</li> | 78 <li>Load unpacked extension...</li> |
| 61 <li>Select the <code><myappdir></code> directory.</li> | 79 <li>Select the <code><myappdir></code> directory.</li> |
| 62 <li>Open a new Chrome tab.</li> | 80 <li>Open a new Chrome tab.</li> |
| 63 <li>Click on the "My First App" icon.</li> | 81 <li>Click on the "My First App" icon.</li> |
| 64 </ul></li> | 82 </ul> |
| 83 |
| 84 <h2 id="debug_fix_and_reload_app">Debug, fix, and reload</h2> |
| 85 |
| 86 <p class="note"><b>Tip:</b> |
| 87 If you have enabled Developer mode in <code>chrome://extensions</code>, |
| 88 your apps can be inspected and debugged using the Chrome Developer Tools. |
| 89 Just like any standard web page, right-click on page and select Inspect Element. |
| 90 For the background page which doesn't have UI, |
| 91 you can either right-click on any app window and |
| 92 select <code>Inspect Background Page</code> or |
| 93 go to <code>chrome://extensions</code> and click on Inspect Views...</p> |
| 94 |
| 95 <ol> |
| 96 <li><p>Change the text "Hello world" |
| 97 to "My first app" in index.html.</p></li> |
| 98 <li><p>Change the |
| 99 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab2_bas
ic/main.js">main.js</a> background script to create two windows instead of one. |
| 100 Don't bother to create another html. |
| 101 For now, you can open index.html on both.</p></li> |
| 102 <li><p>After changing code, |
| 103 right-click on your app and select Reload App to reload the changed files. |
| 104 All Developer Tools windows will be reopened when you reload your app.</p></li> |
| 105 <li><p>Launch the app in a new tab page. |
| 106 Move the top window and you will see the second window behind it.</p></li> |
| 65 </ol> | 107 </ol> |
| 66 | 108 |
| 109 <h2 id="takeaways">Takeaways</h2> |
| 110 |
| 111 <ul> |
| 112 <li>Chrome packaged apps have three basic pieces. |
| 113 The first and foremost is the manifest, which describes your app, |
| 114 requests special permissions, defines important meta information and much more. |
| 115 The second part is the background script, |
| 116 which contains all logic not tied to a specific user interface. |
| 117 The last part is the user interface: HTML, CSS, JavaScripts related to the inter
face, images, etc.</li> |
| 118 <li>Chrome packaged apps can be debugged just like standard web pages |
| 119 using the Chrome Developer Tools. |
| 120 But since an app doesn't have the Reload control of a browser, |
| 121 a Reload App option has been added when you run in Developer mode.</li> |
| 122 </ul> |
| 123 |
| 67 <h2 id="you_should_also_read">You should also read</h2> | 124 <h2 id="you_should_also_read">You should also read</h2> |
| 68 | 125 |
| 69 <ul> | 126 <ul> |
| 70 <li><a href="http://developer.chrome.com/trunk/apps/first_app.html">Create Your
First App</a></li> | 127 <li><a href="http://developer.chrome.com/trunk/apps/first_app.html">Create Your
First App</a> tutorial</li> |
| 71 <li><a href="http://developer.chrome.com/trunk/apps/app.runtime.html">chrome.app
.runtime</a></li> | 128 <li><a href="http://developer.chrome.com/trunk/apps/app.runtime.html">chrome.app
.runtime</a> reference</li> |
| 72 <li><a href="http://developer.chrome.com/trunk/apps/app.window.html">chrome.app.
window</a></li> | 129 <li><a href="http://developer.chrome.com/trunk/apps/app.window.html">chrome.app.
window</a> reference</li> |
| 73 </ul> | 130 </ul> |
| 74 | 131 |
| 75 <h2 id="debug_fix_and_reload_app">Debug, fix, and reload app</h2> | 132 <h2 id="what_39_s_next_">What's next?</h2> |
| 76 | 133 |
| 77 <p class="note"><b>Tip:</b> If you have enabled Developer mode in <code>chrome:
//extensions</code>, your apps can be inspected and debugged using the Chrome De
veloper Tools just like any standard web page: right-click on page, select Inspe
ct Element. For the background page, which doesn't have UI, you can either r
ight-click on any app window and select <code>Inspect Background Page</code> or
go to <code>chrome://extensions</code> and click on Inspect Views...</p> | 134 <p>In <a href="app_codelab3_mvc.html">3 - Create MVC</a>, |
| 78 | 135 you will use either pure JavaScript or |
| 79 <ol> | 136 <a href="http://angularjs.org/">AngluarJS</a> |
| 80 <li><p>Change the text "Hello world" to "My first app" in in
dex.html.</p></li> | 137 to build your app's model, view, and controller.</p> |
| 81 <li><p>Change the <a href="https://github.com/GoogleChrome/chrome-app-codelab/bl
ob/master/lab2_basic/main.js">main.js</a> background script to create two window
s instead of one. Don't bother to create another html. For now, you can open
index.html on both.</p></li> | |
| 82 <li><p>After changing code, right-click on your app and select Reload App to rel
oad the changed files. All Developer Tools windows will be reopened when you rel
oad your app.</p></li> | |
| 83 <li><p>Launch the app in a new tab page. Move the top window and you will see th
e second window behind it. </p></li> | |
| 84 </ol> | |
| 85 | |
| 86 <h1 id="takeaways">Takeaways</h1> | |
| 87 | |
| 88 <ul> | |
| 89 <li>Chrome apps have three basic pieces. The first and foremost is the manifest.
json, which describes your app, requests special permissions, defines important
meta information and much more. The second part is the background script, which
contains all logic not tied to a specific user interface. The last part is the u
ser interface: HTML, CSS, JavaScripts related to the interface, images, etc.</li
> | |
| 90 <li>Chrome apps can be debugged just like standard web pages using the Chrome De
veloper Tools. But since an app doesn't have the Reload control of a browser
, a Reload App option has been added when you run in Developer mode.</li> | |
| 91 </ul> | |
| 92 | |
| 93 <h1 id="what_39_s_next_">What's next?</h1> | |
| 94 | |
| 95 <p>In <a href="app_codelab3_mvc.html">lab3_mvc</a>, | |
| 96 you will use the <a href="http://angularjs.org/">AngluarJS framework</a> to buil
d your app.</p> | |
| OLD | NEW |