OLD | NEW |
(Empty) | |
| 1 <h1 id="lab_2_work_with_code">Lab 2 - Work with code</h1> |
| 2 |
| 3 <h2 id="create_your_first_chrome_app">Create your first Chrome app</h2> |
| 4 |
| 5 <p>There are three core pieces to any Chrome app:</p> |
| 6 |
| 7 <ul> |
| 8 <li>The manifest that descibes meta-information about your applicaiton: name, de
scription, version number and how to launch your application</li> |
| 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> |
| 10 <li>The view (which is optional, but you normally need to show the user somethin
g)</li> |
| 11 </ul> |
| 12 |
| 13 <p>Let's look at each of these components at their simplest level. </p> |
| 14 |
| 15 <ol> |
| 16 <li><p>In an empty directory (let's call it <code><myappdir></code>),
create three files:</p> |
| 17 |
| 18 <ul> |
| 19 <li>Manifest: <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/m
aster/lab2_basic/manifest.json">manifest.json</a> |
| 20 <pre> |
| 21 { |
| 22 "manifest_version": 2, |
| 23 "name": "My first app", |
| 24 "version": "1", |
| 25 "app": { |
| 26 "background": { |
| 27 "scripts": ["main.js"] |
| 28 } |
| 29 } |
| 30 } |
| 31 </pre></li> |
| 32 <li>Background script: <a href="https://github.com/GoogleChrome/chrome-app-codel
ab/blob/master/lab2_basic/main.js">main.js</a> |
| 33 <pre> |
| 34 chrome.app.runtime.onLaunched.addListener(function() { |
| 35 chrome.app.window.create('index.html', |
| 36 {width: 500, height: 309}); |
| 37 }); |
| 38 </pre></li> |
| 39 <li>User interface: <a href="https://github.com/GoogleChrome/chrome-app-codelab/
blob/master/lab2_basic/index.html">index.html</a> |
| 40 <pre> |
| 41 <html> |
| 42 <head> |
| 43 <meta charset="utf-8"> |
| 44 <title>Hello World</title> |
| 45 </head> |
| 46 <body> |
| 47 <h1>Hello, World!</h1> |
| 48 </body> |
| 49 </html> |
| 50 </pre></li> |
| 51 </ul></li> |
| 52 <li><p>Install and execute your sample app: </p> |
| 53 |
| 54 <ul> |
| 55 <li>Go to <code>chrome://extensions</code>.</li> |
| 56 <li>Load unpacked extension...</li> |
| 57 <li>Select the <code><myappdir></code> directory.</li> |
| 58 <li>Open a new Chrome tab.</li> |
| 59 <li>Click on the "My First App" icon.</li> |
| 60 </ul></li> |
| 61 </ol> |
| 62 |
| 63 <h2 id="you_should_also_read">You should also read</h2> |
| 64 |
| 65 <ul> |
| 66 <li><a href="http://developer.chrome.com/trunk/apps/first_app.html">Create Your
First App</a></li> |
| 67 <li><a href="http://developer.chrome.com/trunk/apps/app.runtime.html">chrome.app
.runtime</a></li> |
| 68 <li><a href="http://developer.chrome.com/trunk/apps/app.window.html">chrome.app.
window</a></li> |
| 69 </ul> |
| 70 |
| 71 <h2 id="debug_fix_and_reload_app">Debug, fix, and reload app</h2> |
| 72 |
| 73 <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> |
| 74 |
| 75 <ol> |
| 76 <li><p>Change the text "Hello world" to "My first app" in in
dex.html.</p></li> |
| 77 <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> |
| 78 <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> |
| 79 <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> |
| 80 </ol> |
| 81 |
| 82 <h1 id="takeaways">Takeaways</h1> |
| 83 |
| 84 <ul> |
| 85 <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
> |
| 86 <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> |
| 87 </ul> |
| 88 |
| 89 <h1 id="what_39_s_next_">What's next?</h1> |
| 90 |
| 91 <p>In <a href="app_codelab3_mvc.html">lab3_mvc</a>, |
| 92 you will use the <a href="http://angularjs.org/">AngluarJS framework</a> to buil
d your app.</p> |
OLD | NEW |