Chromium Code Reviews| 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 <h2 id="manifest">Create manifest</h2> |
| 16 <li><p>In an empty directory (let's call it <code><myappdir></code>), create three files:</p> | |
| 17 | 18 |
| 18 <ul> | 19 <p>In an empty directory (let's call it <code><myappdir></code>), |
| 19 <li>Manifest: <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/m aster/lab2_basic/manifest.json">manifest.json</a> | 20 create the manifest file: <a href="https://github.com/GoogleChrome/chrome-app-co delab/blob/master/lab2_basic/manifest.json">manifest.json</a> |
| 21 </p> | |
| 22 | |
| 20 <pre> | 23 <pre> |
| 21 { | 24 { |
| 22 "manifest_version": 2, | 25 "manifest_version": 2, |
| 23 "name": "My first app", | 26 "name": "My first app", |
| 24 "version": "1", | 27 "version": "1", |
| 25 "app": { | 28 "app": { |
| 26 "background": { | 29 "background": { |
| 27 "scripts": ["main.js"] | 30 "scripts": ["main.js"] |
| 28 } | 31 } |
| 29 } | 32 } |
| 30 } | 33 } |
| 31 </pre></li> | 34 </pre> |
| 32 <li>Background script: <a href="https://github.com/GoogleChrome/chrome-app-codel ab/blob/master/lab2_basic/main.js">main.js</a> | 35 |
| 36 <h2 id="background">Create background script</h2> | |
| 37 | |
| 38 <p>In the same directory, | |
| 39 create the background script: <a href="https://github.com/GoogleChrome/chrome-ap p-codelab/blob/master/lab2_basic/main.js">main.js</a> | |
| 40 | |
| 33 <pre> | 41 <pre> |
| 34 chrome.app.runtime.onLaunched.addListener(function() { | 42 chrome.app.runtime.onLaunched.addListener(function() { |
| 35 chrome.app.window.create('index.html', { | 43 chrome.app.window.create('index.html', { |
| 36 bounds: { | 44 bounds: { |
| 37 width: 500, | 45 width: 500, |
| 38 height: 309 | 46 height: 309 |
| 39 } | 47 } |
| 40 }); | 48 }); |
| 41 }); | 49 }); |
| 42 </pre></li> | 50 </pre> |
| 43 <li>User interface: <a href="https://github.com/GoogleChrome/chrome-app-codelab/ blob/master/lab2_basic/index.html">index.html</a> | 51 |
| 52 <h2 id="view">Create view</h2> | |
| 53 | |
| 54 <p>Create the user interface: <a href="https://github.com/GoogleChrome/chrome-ap p-codelab/blob/master/lab2_basic/index.html">index.html</a> | |
| 55 | |
| 44 <pre> | 56 <pre> |
| 45 <html> | 57 <html> |
| 46 <head> | 58 <head> |
| 47 <meta charset="utf-8"> | 59 <meta charset="utf-8"> |
| 48 <title>Hello World</title> | 60 <title>Hello World</title> |
| 49 </head> | 61 </head> |
| 50 <body> | 62 <body> |
| 51 <h1>Hello, World!</h1> | 63 <h1>Hello, World!</h1> |
| 52 </body> | 64 </body> |
| 53 </html> | 65 </html> |
| 54 </pre></li> | 66 </pre> |
| 55 </ul></li> | 67 |
|
Renato Mangini (chromium)
2013/04/09 17:32:32
<p class="note"><b>Tip:</b>
If you use the Subli
mkearney1
2013/04/10 17:59:58
I moved this up to start of lab, as it makes the m
| |
| 56 <li><p>Install and execute your sample app: </p> | 68 <h2 id="install">Install and execute sample app</h2> |
| 57 | 69 |
| 58 <ul> | 70 <ul> |
| 59 <li>Go to <code>chrome://extensions</code>.</li> | 71 <li>Go to <code>chrome://extensions</code>.</li> |
| 60 <li>Load unpacked extension...</li> | 72 <li>Load unpacked extension...</li> |
| 61 <li>Select the <code><myappdir></code> directory.</li> | 73 <li>Select the <code><myappdir></code> directory.</li> |
| 62 <li>Open a new Chrome tab.</li> | 74 <li>Open a new Chrome tab.</li> |
| 63 <li>Click on the "My First App" icon.</li> | 75 <li>Click on the "My First App" icon.</li> |
| 64 </ul></li> | 76 </ul> |
| 77 | |
| 78 <h2 id="debug_fix_and_reload_app">Debug, fix, and reload</h2> | |
| 79 | |
| 80 <p class="note"><b>Tip:</b> | |
| 81 If you have enabled Developer mode in <code>chrome://extensions</code>, | |
| 82 your apps can be inspected and debugged using the Chrome Developer Tools. | |
| 83 Just like any standard web page, right-click on page and select Inspect Element. | |
| 84 For the background page which doesn't have UI, | |
| 85 you can either right-click on any app window and | |
| 86 select <code>Inspect Background Page</code> or | |
| 87 go to <code>chrome://extensions</code> and click on Inspect Views...</p> | |
| 88 | |
| 89 <ol> | |
| 90 <li><p>Change the text "Hello world" | |
| 91 to "My first app" in index.html.</p></li> | |
| 92 <li><p>Change the | |
| 93 <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. | |
| 94 Don't bother to create another html. | |
| 95 For now, you can open index.html on both.</p></li> | |
| 96 <li><p>After changing code, | |
| 97 right-click on your app and select Reload App to reload the changed files. | |
| 98 All Developer Tools windows will be reopened when you reload your app.</p></li> | |
| 99 <li><p>Launch the app in a new tab page. | |
| 100 Move the top window and you will see the second window behind it.</p></li> | |
| 65 </ol> | 101 </ol> |
| 66 | 102 |
| 103 <h2 id="takeaways">Takeaways</h2> | |
| 104 | |
| 105 <ul> | |
| 106 <li>Chrome packaged apps have three basic pieces. | |
| 107 The first and foremost is the manifest, which describes your app, | |
| 108 requests special permissions, defines important meta information and much more. | |
| 109 The second part is the background script, | |
| 110 which contains all logic not tied to a specific user interface. | |
| 111 The last part is the user interface: HTML, CSS, JavaScripts related to the inter face, images, etc.</li> | |
| 112 <li>Chrome packaged apps can be debugged just like standard web pages | |
| 113 using the Chrome Developer Tools. | |
| 114 But since an app doesn't have the Reload control of a browser, | |
| 115 a Reload App option has been added when you run in Developer mode.</li> | |
| 116 </ul> | |
| 117 | |
| 67 <h2 id="you_should_also_read">You should also read</h2> | 118 <h2 id="you_should_also_read">You should also read</h2> |
| 68 | 119 |
| 69 <ul> | 120 <ul> |
| 70 <li><a href="http://developer.chrome.com/trunk/apps/first_app.html">Create Your First App</a></li> | 121 <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> | 122 <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> | 123 <li><a href="http://developer.chrome.com/trunk/apps/app.window.html">chrome.app. window</a> reference</li> |
| 73 </ul> | 124 </ul> |
| 74 | 125 |
| 75 <h2 id="debug_fix_and_reload_app">Debug, fix, and reload app</h2> | 126 <h2 id="what_39_s_next_">What's next?</h2> |
| 76 | 127 |
| 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> | 128 <p>In <a href="app_codelab3_mvc.html">3 - Create MVC</a>, |
| 78 | 129 you will use either pure JavaScript or |
| 79 <ol> | 130 <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> | 131 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 |