├── .gitignore ├── LICENSE ├── README.md ├── camera-capture ├── README.md ├── pubspec.yaml ├── screenshot.png └── web │ ├── background.js │ ├── camera.png │ ├── camera_capture.css │ ├── camera_capture.dart │ ├── camera_capture.html │ └── manifest.json ├── chrome-app-with-polymer-dart ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.dart ├── lib │ ├── main_app.dart │ └── main_app.html ├── pubspec.yaml └── web │ ├── apple-touch-icon-precomposed.png │ ├── background.js │ ├── favicon.ico │ ├── images │ └── touch │ │ ├── chrome-touch-icon-192x192.png │ │ └── ms-touch-icon-144x144-precomposed.png │ ├── index.html │ ├── manifest.json │ ├── robots.txt │ └── styles.css ├── context-menu ├── README.md ├── pubspec.yaml ├── screenshot.png └── web │ ├── a.dart │ ├── a.html │ ├── b.dart │ ├── b.html │ ├── background.js │ ├── common.dart │ ├── context_menu.css │ ├── dart_icon.png │ └── manifest.json ├── desktop-capture ├── README.md ├── pubspec.yaml ├── screenshot.png └── web │ ├── background.js │ ├── desktop.png │ ├── desktop_capture.css │ ├── desktop_capture.dart │ ├── desktop_capture.html │ └── manifest.json ├── filesystem-access ├── README.md ├── pubspec.yaml ├── screenshot.png └── web │ ├── background.js │ ├── dart_icon.png │ ├── dnd.dart │ ├── filesystem_access.css │ ├── filesystem_access.dart │ ├── filesystem_access.html │ └── manifest.json ├── media-gallery ├── README.md ├── pubspec.yaml ├── screenshot.png └── web │ ├── background.js │ ├── manifest.json │ ├── mediagallery.css │ ├── mediagallery.dart │ ├── mediagallery.html │ └── mga-128color.png └── windows ├── README.md ├── pubspec.yaml ├── screenshot.png └── web ├── background.js ├── copycat.dart ├── copycat.html ├── img ├── copycat.png └── original.png ├── manifest.json ├── original.dart ├── original.html ├── script └── update.dart └── styles └── windows.css /.gitignore: -------------------------------------------------------------------------------- 1 | # Don’t commit the following directories created by pub. 2 | build/ 3 | packages/ 4 | 5 | # Or the files created by dart2js. 6 | *.dart.js 7 | *.dart.precompiled.js 8 | *.js_ 9 | *.js.deps 10 | *.js.map 11 | 12 | # Include when developing application packages. 13 | pubspec.lock 14 | 15 | .idea 16 | .pub 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Shared Projects for Dart GDE's 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | dart-chrome-app-samples 2 | ======================= 3 | 4 | Chrome App Samples in Dart 5 | -------------------------------------------------------------------------------- /camera-capture/README.md: -------------------------------------------------------------------------------- 1 | # Camera Capture 2 | 3 | Shows how to grab a camera and microphone feed using getUserMedia. Requires 4 | the appropriate permissions (`audioCapture` and `videoCapture`) 5 | to be set in the manifest file. 6 | 7 | ## APIs 8 | 9 | * [Runtime](http://developer.chrome.com/apps/app.runtime.html) 10 | * [Window](http://developer.chrome.com/apps/app.window.html) 11 | * [videoCapture and audioCapture](http://developer.chrome.com/apps/manifest.html#permissions) 12 | 13 | 14 | ## Screenshot 15 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/camera-capture/screenshot.png) -------------------------------------------------------------------------------- /camera-capture/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: camera-capture 2 | description: A sample Chrome packaged application 3 | dependencies: 4 | chrome: any 5 | transformers: 6 | - chrome 7 | -------------------------------------------------------------------------------- /camera-capture/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/camera-capture/screenshot.png -------------------------------------------------------------------------------- /camera-capture/web/background.js: -------------------------------------------------------------------------------- 1 | 2 | chrome.app.runtime.onLaunched.addListener(function(launchData) { 3 | chrome.app.window.create('camera_capture.html', { 4 | 'id': '_mainWindow', 'bounds': {'width': 800, 'height': 600 } 5 | }); 6 | }); 7 | -------------------------------------------------------------------------------- /camera-capture/web/camera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/camera-capture/web/camera.png -------------------------------------------------------------------------------- /camera-capture/web/camera_capture.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: white; 3 | display: -webkit-flex; 4 | -webkit-justify-content: center; 5 | -webkit-align-items: center; 6 | -webkit-flex-direction: column; 7 | } 8 | video { 9 | width: 640px; 10 | height: 480px; 11 | background: rgba(0,0,0,0.25); 12 | } 13 | button { 14 | display: inline-block; 15 | background: -webkit-linear-gradient(#F9F9F9 40%, #E3E3E3 70%); 16 | background: linear-gradient(#F9F9F9 40%, #E3E3E3 70%); 17 | border: 1px solid #999; 18 | -webkit-border-radius: 3px; 19 | border-radius: 3px; 20 | padding: 5px 8px; 21 | outline: none; 22 | white-space: nowrap; 23 | -webkit-user-select: none; 24 | user-select: none; 25 | cursor: pointer; 26 | text-shadow: 1px 1px #fff; 27 | font-weight: 700; 28 | font-size: 10pt; 29 | } 30 | button:hover, 31 | button.active { 32 | border-color: black; 33 | } 34 | button:active, 35 | button.active { 36 | background: -webkit-linear-gradient(#E3E3E3 40%, #F9F9F9 70%); 37 | background: linear-gradient(#E3E3E3 40%, #F9F9F9 70%); 38 | } 39 | 40 | video { 41 | background: white url(camera.png) center no-repeat; 42 | border: 1px solid #e2e2e2; 43 | box-shadow: 0 1px 1px rgba(0,0,0,0.2); 44 | } -------------------------------------------------------------------------------- /camera-capture/web/camera_capture.dart: -------------------------------------------------------------------------------- 1 | import 'dart:html'; 2 | 3 | void main() { 4 | document.querySelector("button").onClick.listen((MouseEvent mouse_event) { 5 | window.navigator.getUserMedia(audio: true, video: true).then((MediaStream media_stream) { 6 | VideoElement video = document.querySelector("video"); 7 | video.src = Url.createObjectUrlFromStream(media_stream); 8 | }).catchError((e) => window.console.error(e)); 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /camera-capture/web/camera_capture.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Camera capture 7 | 8 | 9 | 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /camera-capture/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Camera capture", 3 | "version": "1", 4 | 5 | "manifest_version": 2, 6 | 7 | "icons": { 8 | "16": "camera.png", 9 | "128": "camera.png" 10 | }, 11 | 12 | "app": { 13 | "background": { 14 | "scripts": ["background.js"] 15 | } 16 | }, 17 | "permissions": [ 18 | "audioCapture", 19 | "videoCapture" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.1.0 4 | 5 | - Example work correctly 6 | 7 | ## 0.0.1 8 | 9 | - Initial version, created by Stagehand 10 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, . 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/README.md: -------------------------------------------------------------------------------- 1 | # Dart Chrome apps with PolymerDart 2 | 3 | This is an example of how to use PolymerDart in a chrome apps. 4 | 5 | ## How to get all work together 6 | 7 | ### Step 1 8 | 9 | First create a polymer dart project using stagehand. 10 | 11 | ### Step 2 12 | 13 | When you have that open your pubspec.yaml and add the chrome dependencies you should have something like that : 14 | 15 | ```yaml 16 | dependencies: 17 | browser: any 18 | polymer: '>=0.15.4 <0.16.0' 19 | paper_elements: '>=0.6.1 <0.7.0' 20 | chrome: any 21 | ``` 22 | 23 | ### Step 3 24 | 25 | After that add the chrome transformer and the dart2js transformer : 26 | 27 | ```yaml 28 | - chrome 29 | - $dart2js: 30 | csp: true 31 | ``` 32 | 33 | ### Step 4 34 | 35 | Don't forget to add the background.js and the manifest.json inside your web directory. 36 | 37 | ### Step 5 38 | 39 | Build your application 40 | 41 | 42 | ### Step 6 43 | 44 | Load your unpacked extension from your build folder and launch it. 45 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/build.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, . All rights reserved. Use of this source code 2 | // is governed by a BSD-style license that can be found in the LICENSE file. 3 | 4 | // This file is only used by Dart Editor. It displays errors and warnings after 5 | // analyzing a polymer.dart app. 6 | 7 | export 'package:polymer/default_build.dart'; 8 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/lib/main_app.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, . All rights reserved. Use of this source code 2 | // is governed by a BSD-style license that can be found in the LICENSE file. 3 | 4 | import 'dart:html'; 5 | 6 | import 'package:chrome/chrome_app.dart' as chrome; 7 | 8 | import 'package:polymer/polymer.dart'; 9 | 10 | @CustomTag('main-app') 11 | class MainApp extends PolymerElement { 12 | int _boundsChange = 100; 13 | 14 | 15 | /// Constructor used to create instance of MainApp. 16 | MainApp.created() : super.created(); 17 | 18 | void resizeWindow() { 19 | chrome.ContentBounds bounds = chrome.app.window.current().getBounds(); 20 | 21 | bounds.width += this._boundsChange; 22 | bounds.left -= this._boundsChange ~/ 2; 23 | 24 | chrome.app.window.current().setBounds(bounds); 25 | 26 | this._boundsChange *= -1; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/lib/main_app.html: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: 'chrome_app_with_polymer' 2 | version: 0.1.0 3 | description: > 4 | A starter template for a polymer.dart web app. 5 | #author: 6 | #homepage: https://www.example.com 7 | environment: 8 | sdk: '>=1.0.0 <2.0.0' 9 | dependencies: 10 | browser: any 11 | polymer: '>=0.15.4 <0.16.0' 12 | paper_elements: '>=0.6.1 <0.7.0' 13 | chrome: any 14 | transformers: 15 | - polymer: 16 | entry_points: web/index.html 17 | csp: true 18 | - chrome 19 | - $dart2js: 20 | csp: true -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/chrome-app-with-polymer-dart/web/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/background.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by kevin on 3/24/2015. 3 | */ 4 | 5 | chrome.app.runtime.onLaunched.addListener(function(launchData) { 6 | chrome.app.window.create('index.html', { 7 | 'id': '_mainWindow', 'bounds': {'width': 800, 'height': 600 } 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/chrome-app-with-polymer-dart/web/favicon.ico -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/images/touch/chrome-touch-icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/chrome-app-with-polymer-dart/web/images/touch/chrome-touch-icon-192x192.png -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/images/touch/ms-touch-icon-144x144-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/chrome-app-with-polymer-dart/web/images/touch/ms-touch-icon-144x144-precomposed.png -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | chrome_app_with_polymer 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "PolymerDart in Chrome apps", 3 | "version": "1", 4 | 5 | "manifest_version": 2, 6 | 7 | "icons": { 8 | }, 9 | 10 | "app": { 11 | "background": { 12 | "scripts": ["background.js"] 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/robots.txt: -------------------------------------------------------------------------------- 1 | # www.robotstxt.org/ 2 | 3 | # Allow crawling of all content 4 | User-agent: * 5 | Disallow: 6 | -------------------------------------------------------------------------------- /chrome-app-with-polymer-dart/web/styles.css: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, . All rights reserved. Use of this source code */ 2 | /* is governed by a BSD-style license that can be found in the LICENSE file. */ 3 | 4 | body { 5 | font-family: RobotoDraft, sans-serif; 6 | color: #333; 7 | -webkit-user-select: none; 8 | -moz-user-select: none; 9 | -ms-user-select: none; 10 | user-select: none; 11 | -webkit-tap-highlight-color: rgba(0,0,0,0); 12 | -webkit-touch-callout: none; 13 | } 14 | -------------------------------------------------------------------------------- /context-menu/README.md: -------------------------------------------------------------------------------- 1 | # Context menus 2 | 3 | Sample that shows how to use the [context menu API](http://developer.chrome.com/apps/contextMenus.html) in an app to manage various application context menus, such as menus that only apply to particular windows, menus that apply to selections or media types, and context menus that work on the app launcher. 4 | 5 | A single context menu structure is normally global to the entire app, and thus all windows would have the same menu. This sample uses a `focus` event handler in each window to detect when a window is brought to the foreground. When it is, the contents of the context menu are updated with that window's commands, while leaving the other menus intact. The `chrome.contextMenus.onClicked` event handler also only handles events that occur in that window. 6 | 7 | ## APIs 8 | 9 | * [Context menu API](http://developer.chrome.com/apps/contextMenus.html) 10 | * [Runtime](http://developer.chrome.com/apps/app.runtime.html) 11 | * [Window](http://developer.chrome.com/apps/app.window.html) 12 | 13 | 14 | 15 | ## Screenshot 16 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/context-menu/screenshot.png) -------------------------------------------------------------------------------- /context-menu/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: context-menu 2 | description: A sample Chrome packaged application 3 | dependencies: 4 | chrome: any 5 | transformers: 6 | - chrome 7 | -------------------------------------------------------------------------------- /context-menu/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/context-menu/screenshot.png -------------------------------------------------------------------------------- /context-menu/web/a.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:html'; 3 | 4 | import "package:chrome/chrome_app.dart" as chrome; 5 | 6 | import "common.dart"; 7 | 8 | 9 | void main() { 10 | bool focus = false; 11 | window.onLoad.listen((event) { 12 | log('Window A is loaded'); 13 | setupContextMenu("windowA"); 14 | }); 15 | 16 | window.onBlur.listen((event) { 17 | log("Window A is blur"); 18 | focus = false; 19 | }); 20 | 21 | window.onFocus.listen((event) { 22 | log('Window A is focus'); 23 | focus = true; 24 | setupContextMenu("windowA"); 25 | }); 26 | 27 | chrome.contextMenus.onClicked.listen((chrome.OnClickedEvent info) { 28 | clickOnContext(focus, 'A', info); 29 | }); 30 | } 31 | -------------------------------------------------------------------------------- /context-menu/web/a.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Context menu 7 | 8 | 9 | 10 |

Window A

11 |

Right click to see the context menu.

12 |

Select this text and then right-click

13 |

Log:

14 |

15 | 
16 |     
17 |         
18 |   
19 | 
20 | 


--------------------------------------------------------------------------------
/context-menu/web/b.dart:
--------------------------------------------------------------------------------
 1 | 
 2 | import 'dart:html';
 3 | 
 4 | import "package:chrome/chrome_app.dart" as chrome;
 5 | 
 6 | import "common.dart";
 7 | 
 8 | void main() {
 9 |   bool focus = false;
10 |   window.onLoad.listen((event) {
11 |     log('Window B is loaded');
12 |     setupContextMenu("windowB");
13 |   });
14 |   
15 |   window.onBlur.listen((event) {
16 |     log("Window B is blur");
17 |     focus = false;
18 |   });
19 |   
20 |   window.onFocus.listen((event) {
21 |     log('Window B is focus');
22 |     focus = true;
23 |     setupContextMenu("windowB");
24 |   });
25 |   
26 |   chrome.contextMenus.onClicked.listen((chrome.OnClickedEvent info) {
27 |     clickOnContext(focus, 'B', info);
28 |   });
29 | }
30 | 


--------------------------------------------------------------------------------
/context-menu/web/b.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 |   
 5 |     
 6 |     Context menu
 7 |     
 8 |   
 9 |   
10 |     

Window B

11 |

Right click to see the context menu.

12 |

Log:

13 |

14 | 
15 |     
16 |         
17 |   
18 | 
19 | 


--------------------------------------------------------------------------------
/context-menu/web/background.js:
--------------------------------------------------------------------------------
 1 | chrome.app.runtime.onLaunched.addListener(function() {
 2 |   chrome.app.window.create('a.html', {bounds:{top: 0, left: 0, width: 300, height: 300}});
 3 |   chrome.app.window.create('b.html', {bounds:{top: 0, left: 310, width: 300, height: 300}});
 4 | });
 5 | 
 6 | chrome.runtime.onInstalled.addListener(function() {
 7 |   chrome.contextMenus.create({
 8 |     title: 'Launcher Window "A"',
 9 |     id: "launcher1",
10 |     contexts: ['launcher']
11 |   });
12 |   
13 |   chrome.contextMenus.create({
14 |     title: 'Launcher Window "B"',
15 |     id: "launcher2",
16 |     contexts: ['launcher']
17 |   });
18 |   
19 |   chrome.contextMenus.create({
20 |     type: "separator",
21 |     id: 'launcher3',
22 |     contexts: ['launcher']
23 |   });
24 | });
25 | 
26 | chrome.contextMenus.onClicked.addListener(function(itemClicked) {
27 |   if (itemClicked.menuItemId == "launcher1")
28 |     chrome.app.window.create('a.html', {bounds:{top: 0, left: 0, width: 300, height: 300}});
29 |   if (itemClicked.menuItemId == "launcher2")
30 |     chrome.app.window.create('b.html', {bounds:{top: 0, left: 310, width: 300, height: 300}});
31 | });


--------------------------------------------------------------------------------
/context-menu/web/common.dart:
--------------------------------------------------------------------------------
 1 | import 'dart:html';
 2 | 
 3 | import 'package:chrome/chrome_app.dart' as chrome;
 4 | 
 5 | void log(String message) {
 6 |   PreElement logger = document.querySelector('#log');
 7 |   logger.text += "$message\n";
 8 | }
 9 | 
10 | void clickOnContext(bool focus, String aOrB, chrome.OnClickedEvent info) {
11 |   if (!focus) {
12 |     log("Ignoring context menu click that happened in another window");
13 |     return;
14 |   }
15 |     
16 |   log('Item selected in $aOrB: ${info.info.menuItemId}');
17 | }
18 | 
19 | void setupContextMenu(String sContext) {
20 |   chrome.contextMenus.removeAll().then((value) {
21 |     var options = ["foo", "bar", "baz"];
22 |     if (sContext == "windowA") {
23 |       options.forEach((String option) {
24 |         chrome.contextMenus.create(new chrome.ContextMenusCreateParams(title: "A: $option", id: option, type: "radio", contexts: ['all']));
25 |       });
26 |       chrome.contextMenus.create(new chrome.ContextMenusCreateParams(id: "sep1", type: "separator", contexts: ['selection']));
27 |       chrome.contextMenus.create(new chrome.ContextMenusCreateParams(title: "Selection context menu: '%s'", id: "Selection context menu", contexts: ['selection']));
28 |     }
29 |     else if (sContext == "windowB") {
30 |       options.forEach((String option) {
31 |         chrome.contextMenus.create(new chrome.ContextMenusCreateParams(title: "B: $option", id: option, type: "checkbox", contexts: ['all']));
32 |       });
33 |     }
34 |   });
35 | }


--------------------------------------------------------------------------------
/context-menu/web/context_menu.css:
--------------------------------------------------------------------------------
 1 | body {
 2 |   background-color: #F8F8F8;
 3 |   font-family: 'Open Sans', sans-serif;
 4 |   font-size: 14px;
 5 |   font-weight: normal;
 6 |   line-height: 1.2em;
 7 |   margin: 15px;
 8 | }
 9 | 
10 | h1, p {
11 |   color: #333;
12 | }
13 | 
14 | #container_id {
15 |   height: 400px;
16 |   position: relative;
17 |   border: 1px solid #ccc;
18 |   background-color: #fff;
19 | }
20 | 
21 | #text_id {
22 |   font-size: 24pt;
23 |   text-align: center;
24 |   margin-top: 140px;
25 | }
26 | 


--------------------------------------------------------------------------------
/context-menu/web/dart_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/context-menu/web/dart_icon.png


--------------------------------------------------------------------------------
/context-menu/web/manifest.json:
--------------------------------------------------------------------------------
 1 | {
 2 |   "name": "Context menu",
 3 |   "version": "1",
 4 |   
 5 |   "manifest_version": 2,
 6 |   
 7 |   "icons": {"128": "dart_icon.png"},
 8 |   
 9 |   "app": {
10 |     "background": {
11 |       "scripts": ["background.js"]
12 |     }
13 |   },
14 |   "permissions": [
15 |     "contextMenus"
16 |   ]
17 | }
18 | 


--------------------------------------------------------------------------------
/desktop-capture/README.md:
--------------------------------------------------------------------------------
 1 | # Desktop Capture
 2 | 
 3 | Shows how to grab a desktop capture feed using getUserMedia. Requires
 4 | the appropriate permissions (`desktopCapture`) to be set in the manifest file.
 5 | 
 6 | ## APIs
 7 | 
 8 | * [Runtime](http://developer.chrome.com/apps/app.runtime.html)
 9 | * [Window](http://developer.chrome.com/apps/app.window.html)
10 | * [desktopCapture](https://developer.chrome.com/extensions/desktopCapture)
11 | 
12 | 
13 | ## Screenshot
14 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/desktop-capture/screenshot.png)


--------------------------------------------------------------------------------
/desktop-capture/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: desktop-capture
2 | description: A sample Chrome packaged application
3 | dependencies:
4 |   chrome: any
5 | transformers:
6 | - chrome
7 | 


--------------------------------------------------------------------------------
/desktop-capture/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/desktop-capture/screenshot.png


--------------------------------------------------------------------------------
/desktop-capture/web/background.js:
--------------------------------------------------------------------------------
1 | 
2 | chrome.app.runtime.onLaunched.addListener(function(launchData) {
3 |   chrome.app.window.create('desktop_capture.html', {
4 |     'id': '_mainWindow', 'bounds': {'width': 800, 'height': 600 }
5 |   });
6 | });
7 | 


--------------------------------------------------------------------------------
/desktop-capture/web/desktop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/desktop-capture/web/desktop.png


--------------------------------------------------------------------------------
/desktop-capture/web/desktop_capture.css:
--------------------------------------------------------------------------------
 1 | body {
 2 |     background: white;
 3 |     display: -webkit-flex;
 4 |     -webkit-justify-content: center;
 5 |     -webkit-align-items: center;
 6 |     -webkit-flex-direction: column;
 7 |   }
 8 |   video {
 9 |     width: 640px;
10 |     height: 480px;
11 |     background: rgba(0,0,0,0.25);
12 |   }
13 |   button {
14 |     display: inline-block;
15 |     background: -webkit-linear-gradient(#F9F9F9 40%, #E3E3E3 70%);
16 |     background: linear-gradient(#F9F9F9 40%, #E3E3E3 70%);
17 |     border: 1px solid #999;
18 |     -webkit-border-radius: 3px;
19 |     border-radius: 3px;
20 |     padding: 5px 8px;
21 |     outline: none;
22 |     white-space: nowrap;
23 |     -webkit-user-select: none;
24 |     user-select: none;
25 |     cursor: pointer;
26 |     text-shadow: 1px 1px #fff;
27 |     font-weight: 700;
28 |     font-size: 10pt;
29 |   }
30 |   button:hover,
31 |   button.active {
32 |     border-color: black;
33 |   }
34 |   button:active,
35 |   button.active {
36 |     background: -webkit-linear-gradient(#E3E3E3 40%, #F9F9F9 70%);
37 |     background: linear-gradient(#E3E3E3 40%, #F9F9F9 70%);
38 |   }
39 | 
40 |   video {
41 |     background: white url(desktop.png) center no-repeat;
42 |     border: 1px solid #e2e2e2;
43 |     box-shadow: 0 1px 1px rgba(0,0,0,0.2);
44 |   }


--------------------------------------------------------------------------------
/desktop-capture/web/desktop_capture.dart:
--------------------------------------------------------------------------------
 1 | 
 2 | import 'dart:html';
 3 | import "dart:convert";
 4 | 
 5 | import 'package:chrome/chrome_ext.dart' as chrome;
 6 | 
 7 | var desktop_sharing = false;
 8 | var local_stream = null;
 9 | 
10 | void onAcceptApproved(desktop_id) {
11 |   print(desktop_id.runtimeType);
12 |   if (desktop_id == null) {
13 |     print('Desktop Capture access rejected.');
14 |     return;
15 |   }
16 |   
17 |   desktop_sharing = true;
18 |   document.querySelector('button').innerHtml = "Disable Capture";
19 |   print("Desktop sharing started.. desktop_id: $desktop_id");
20 |   
21 |   window.navigator.getUserMedia(audio: false, video: { 
22 |     "mandatory": {
23 |       "chromeMediaSource": 'desktop',
24 |       "chromeMediaSourceId": desktop_id,
25 |       "minWidth": 1280,
26 |       "maxWidth": 1280,
27 |       "minHeight": 720,
28 |       "maxHeight": 720
29 |     }
30 |   }).then((MediaStream media_stream) {
31 |     local_stream = media_stream;
32 |     VideoElement video = document.querySelector('video');
33 |     video.src = Url.createObjectUrl(media_stream);
34 |     media_stream.onEnded.listen((Event event) {
35 |       if (desktop_sharing) {
36 |         toggle();
37 |       }
38 |     });
39 |     
40 |   }).catchError((e) => print('getUserMediaError: $e'));
41 | }
42 | 
43 | void toggle() {
44 |   if (!desktop_sharing) 
45 |     chrome.desktopCapture.chooseDesktopMedia(['screen', 'window'], onAcceptApproved);
46 |   else {
47 |     desktop_sharing = false;
48 |     if (local_stream != null) 
49 |       local_stream.stop();
50 |     local_stream = null;
51 |     document.querySelector('button').innerHtml = "Enable Capture";
52 |     print('Desktop sharing stopped...');
53 |   }
54 | }
55 | 
56 | void main() {
57 |   document.querySelector("button").onClick.listen((event) {
58 |     toggle();
59 |   });
60 | }


--------------------------------------------------------------------------------
/desktop-capture/web/desktop_capture.html:
--------------------------------------------------------------------------------
 1 | 
 2 | 
 3 | 
 4 |   
 5 |     
 6 |     Desktop capture
 7 |     
 8 |   
 9 |   
10 |     
11 |     

12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /desktop-capture/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Desktop capture", 3 | "version": "1", 4 | 5 | "manifest_version": 2, 6 | 7 | "icons": { 8 | "16": "desktop.png", 9 | "128": "desktop.png" 10 | }, 11 | 12 | "app": { 13 | "background": { 14 | "scripts": ["background.js"] 15 | } 16 | }, 17 | "permissions": [ 18 | "desktopCapture" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /filesystem-access/README.md: -------------------------------------------------------------------------------- 1 | # Not finish 2 | 3 | 4 | # Filesystem access 5 | 6 | Shows basic usage of accessing (read/write) files and directories using the `chrome.fileSystem` API. 7 | 8 | NOTE: This sample requires Milestone 31 or later of Chrome, since it uses the new directory permission. 9 | 10 | ## APIs 11 | 12 | * [chrome.fileSystem](http://developer.chrome.com/apps/fileSystem.html) 13 | 14 | ## Screenshot 15 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/filesystem-access/screenshot.png) 16 | -------------------------------------------------------------------------------- /filesystem-access/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: filesystem-access 2 | description: A sample Chrome packaged application 3 | dependencies: 4 | chrome: any 5 | transformers: 6 | - chrome 7 | -------------------------------------------------------------------------------- /filesystem-access/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/filesystem-access/screenshot.png -------------------------------------------------------------------------------- /filesystem-access/web/background.js: -------------------------------------------------------------------------------- 1 | chrome.app.runtime.onLaunched.addListener(function(launchData) { 2 | chrome.app.window.create('filesystem_access.html', { 3 | 'id': 'fileWin', 'bounds': {'width': 800, 'height': 600 } 4 | }); 5 | }); -------------------------------------------------------------------------------- /filesystem-access/web/dart_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/filesystem-access/web/dart_icon.png -------------------------------------------------------------------------------- /filesystem-access/web/dnd.dart: -------------------------------------------------------------------------------- 1 | import "dart:html"; 2 | 3 | class DnDFileController { 4 | Element _el; 5 | Function _onDrop; 6 | num _over_count; 7 | 8 | DnDFileController(String id_selector, void this._onDrop(DataTransfer data_transfer)) { 9 | this._el = document.querySelector("$id_selector"); 10 | this._over_count = 0; 11 | 12 | this._el.onDragEnter.listen(this._dragEnter); 13 | this._el.onDragOver.listen(this._dragOver); 14 | this._el.onDragLeave.listen(this._dragLeave); 15 | this._el.onDrop.listen(this._drop); 16 | } 17 | 18 | void _dragEnter(MouseEvent e) { 19 | e.stopPropagation(); 20 | e.preventDefault(); 21 | this._over_count++; 22 | this._el.classes.add("dropping"); 23 | } 24 | 25 | void _dragOver(MouseEvent e) { 26 | e.stopPropagation(); 27 | e.preventDefault(); 28 | } 29 | 30 | void _dragLeave(MouseEvent e) { 31 | e.stopPropagation(); 32 | e.preventDefault(); 33 | if (--this._over_count <= 0) { 34 | this._el.classes.remove("dropping"); 35 | this._over_count = 0; 36 | } 37 | } 38 | 39 | void _drop(MouseEvent e) { 40 | e.stopPropagation(); 41 | e.preventDefault(); 42 | this._el.classes.remove("dropping"); 43 | 44 | this._onDrop(e.dataTransfer); 45 | } 46 | } -------------------------------------------------------------------------------- /filesystem-access/web/filesystem_access.css: -------------------------------------------------------------------------------- 1 | body { 2 | display: -webkit-flex; 3 | -webkit-flex-direction: column; 4 | } 5 | .dropping { 6 | background: #ffcc00; 7 | } 8 | nav { 9 | display: -webkit-flex; 10 | -webkit-justify-content: center; 11 | -webkit-align-items: center; 12 | } 13 | video { 14 | width: 640px; 15 | height: 480px; 16 | background: rgba(0,0,0,0.25); 17 | } 18 | button { 19 | display: inline-block; 20 | background: -webkit-linear-gradient(#F9F9F9 40%, #E3E3E3 70%); 21 | background: linear-gradient(#F9F9F9 40%, #E3E3E3 70%); 22 | border: 1px solid #999; 23 | -webkit-border-radius: 3px; 24 | border-radius: 3px; 25 | padding: 5px 8px; 26 | outline: none; 27 | white-space: nowrap; 28 | -webkit-user-select: none; 29 | user-select: none; 30 | cursor: pointer; 31 | text-shadow: 1px 1px #fff; 32 | font-weight: 700; 33 | font-size: 10pt; 34 | } 35 | button:not(:disabled):hover { 36 | border-color: black; 37 | } 38 | button:not(:disabled):active { 39 | background: -webkit-linear-gradient(#E3E3E3 40%, #F9F9F9 70%); 40 | background: linear-gradient(#E3E3E3 40%, #F9F9F9 70%); 41 | } 42 | input { 43 | width: 100%; 44 | -webkit-user-select: none; 45 | } 46 | input, textarea { 47 | box-shadow: 1px 1px 5px #ccc inset; 48 | border: none; 49 | padding: 1em; 50 | } 51 | [readonly] { 52 | background: #eee; 53 | } 54 | [hidden] { 55 | display: none; 56 | } 57 | textarea { 58 | width: 100%; 59 | height: 200px; 60 | outline: none; 61 | padding: 1px; 62 | font-size: 14pt; 63 | padding: 1em; 64 | } 65 | output { 66 | text-align: center; 67 | padding: 1em; 68 | display: block; 69 | } -------------------------------------------------------------------------------- /filesystem-access/web/filesystem_access.dart: -------------------------------------------------------------------------------- 1 | import 'dart:html'; 2 | import "dart:async"; 3 | 4 | import 'package:chrome/chrome_app.dart' as chrome; 5 | 6 | import "dnd.dart"; 7 | 8 | void errorHandler(message) { 9 | window.console.error(message); 10 | } 11 | 12 | void displayEntryData(Entry entry) { 13 | InputElement file_path = document.querySelector("#file_path"); 14 | SpanElement file_size = document.querySelector("#file_size"); 15 | if (entry.isFile) { 16 | file_path.value = ""; 17 | entry.getMetadata().then((Metadata metadata) { 18 | file_size.text = metadata.size.toString(); 19 | }).catchError((e) => print("getMetadata error: $e")); 20 | try { 21 | chrome.fileSystem.getDisplayPath(entry).then((String path) { 22 | file_path.value = path; 23 | }).catchError((e) => print("$e")); 24 | } 25 | catch (e) { 26 | print("bug getDisplayPath $e"); 27 | } 28 | } 29 | else { 30 | TextAreaElement textarea = document.querySelector("textarea"); 31 | textarea.innerHtml = ""; 32 | file_path.value = entry.fullPath; 33 | file_size.text = "N/A"; 34 | } 35 | } 36 | 37 | Future readAsText(FileEntry entry) { 38 | Completer completer = new Completer(); 39 | entry.file().then((File file) { 40 | var reader = new FileReader(); 41 | reader.onError.listen(errorHandler); 42 | reader.onLoadEnd.listen((ProgressEvent progress_event) { 43 | completer.complete((progress_event.target as FileReader).result); 44 | }); 45 | reader.readAsText(file); 46 | }); 47 | return (completer.future); 48 | } 49 | 50 | void onDrop(DataTransfer data_transfer) { 51 | Entry entry = null; 52 | for (int i = 0; i < data_transfer.items.length; i++) { 53 | var item = data_transfer.items[i]; 54 | if ((item.kind == "file" 55 | && item.type.startsWith("text/")) 56 | || item.type == "") { 57 | entry = item.getAsEntry(); 58 | break; 59 | } 60 | } 61 | if (entry != null) 62 | displayEntryData(entry); 63 | OutputElement output = document.querySelector("output");; 64 | if (entry == null || entry.isDirectory) { 65 | output.value = "Sorry. That's not a text file."; 66 | return; 67 | } 68 | else if (entry.isFile) { 69 | output.value = ""; 70 | readAsText(entry).then((result) { 71 | TextAreaElement textarea = document.querySelector("textarea"); 72 | textarea.innerHtml = result; 73 | }); 74 | ButtonElement saveFileButton = document.querySelector("#save_file"); 75 | saveFileButton.disabled = false; 76 | } 77 | } 78 | 79 | void main() { 80 | var dnd = new DnDFileController("body", onDrop); 81 | } -------------------------------------------------------------------------------- /filesystem-access/web/filesystem_access.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Filesystem access 7 | 8 | 9 | 10 | 14 | Path: 15 | Size: bytes 16 | 17 | 18 |

19 | 20 |

21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /filesystem-access/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Filesystem Access Sample", 3 | "version": "1", 4 | 5 | "manifest_version": 2, 6 | "minimum_chrome_version": "31", 7 | 8 | "icons": {"128": "dart_icon.png"}, 9 | 10 | "app": { 11 | "background": { 12 | "scripts": ["background.js"] 13 | } 14 | }, 15 | 16 | "permissions": [ 17 | { "fileSystem": ["write", "retainEntries", "directory"] }, 18 | "storage" 19 | ], 20 | 21 | "file_handlers": { 22 | "text": { 23 | "types": [ 24 | "text/*" 25 | ], 26 | "title": "Text editor" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /media-gallery/README.md: -------------------------------------------------------------------------------- 1 | # Media Gallery 2 | 3 | This is a sample application that uses the [media gallery](http://developer.chrome.com/apps/mediaGalleries.html) API to read and show user's media without requiring direct filesystem permission. 4 | 5 | ## APIs 6 | 7 | * [Media gallery](http://developer.chrome.com/apps/mediaGalleries.html) 8 | * [Runtime](http://developer.chrome.com/apps/app.runtime.html) 9 | * [Window](http://developer.chrome.com/apps/app.window.html) 10 | 11 | 12 | ## Screenshot 13 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/media-gallery/screenshot.png) -------------------------------------------------------------------------------- /media-gallery/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: MediaGallery 2 | description: A sample Chrome packaged application 3 | dependencies: 4 | chrome: any 5 | transformers: 6 | - chrome 7 | -------------------------------------------------------------------------------- /media-gallery/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/media-gallery/screenshot.png -------------------------------------------------------------------------------- /media-gallery/web/background.js: -------------------------------------------------------------------------------- 1 | 2 | chrome.app.runtime.onLaunched.addListener(function(data) { 3 | chrome.app.window.create('mediagallery.html', 4 | {bounds: {width:900, height:600}, minWidth:900, maxWidth: 900, minHeight:600, maxHeight: 600, id:"MGExp"}, 5 | function(app_win) { 6 | app_win.__MGA__bRestart = false; 7 | } 8 | ); 9 | console.log("app launched"); 10 | }); 11 | 12 | chrome.app.runtime.onRestarted.addListener(function() { 13 | chrome.app.window.create('mediagallery.html', 14 | {bounds: {width:900, height:600}, minWidth:900, maxWidth: 900, minHeight:600, maxHeight: 600, id:"MGExp"}, 15 | function(app_win) { 16 | app_win.__MGA__bRestart = true; 17 | } 18 | ); 19 | console.log("app restarted"); 20 | }); -------------------------------------------------------------------------------- /media-gallery/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Media Gallery Sample", 3 | "version": "0.1.0", 4 | "manifest_version": 2, 5 | "minimum_chrome_version": "36", 6 | "description": "Used to test Media Gallery API", 7 | "permissions": [{ 8 | "mediaGalleries": ["read", "scan", "allAutoDetected"] 9 | }], 10 | "icons": { 11 | "128": "mga-128color.png" 12 | }, 13 | "app": { 14 | "background": { 15 | "scripts": ["background.js"] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /media-gallery/web/mediagallery.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #555; 3 | color: #eee; 4 | font-family: "Open Sans", Arial, sans-serif; 5 | } 6 | 7 | h1 { 8 | font-weight: 200; 9 | color: white; 10 | } 11 | 12 | #content { 13 | max-width: 74%; 14 | overflow-y: scroll; 15 | border: 1px solid #aaa; 16 | border-radius: 5px; 17 | display: inline-block; 18 | background-color: #777; 19 | } 20 | 21 | img, video, audio { 22 | max-width: 100%; 23 | max-height: 75%; 24 | } 25 | 26 | #list { 27 | height: 400px; 28 | width: 25%; 29 | border: 1px solid #aaa; 30 | border-radius: 5px; 31 | display: inline-block; 32 | vertical-align: top; 33 | background-color: #777; 34 | } 35 | 36 | #GalleryList { 37 | width: 100%; 38 | height: 100%; 39 | } 40 | 41 | #info { 42 | border: 1px solid #aaa; 43 | background-color: #777; 44 | width: auto; 45 | border-radius: 5px; 46 | overflow: hidden; 47 | padding: 5px; 48 | } -------------------------------------------------------------------------------- /media-gallery/web/mediagallery.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:html'; 3 | 4 | import 'package:chrome/chrome_app.dart' as chrome; 5 | 6 | num gGalleryIndex = 0; 7 | DirectoryReader gGalleryReader = null; 8 | var gDirectories = []; 9 | var gGalleryArray = []; 10 | List gGalleryData = []; 11 | Element gCurOptGrp = null; 12 | var imgFormats = ['png', 'bmp', 'jpeg', 'jpg', 'gif', 'png', 'svg', 'xbm', 'webp']; 13 | var audFormats = ['wav', 'mp3']; 14 | var vidFormats = ['3gp', '3gpp', 'avi', 'flv', 'mov', 'mpeg', 'mpeg4', 'mp4', 'ogg', 'webm', 'wmv', 'mkv']; 15 | 16 | void errorPrintFactory(e, String custom) { 17 | var sb = new StringBuffer(); 18 | sb.write("$custom : "); 19 | if (!(e is FileError)) { 20 | return; 21 | } 22 | sb.write(e.name); 23 | print(sb.toString()); 24 | } 25 | 26 | class GalleryData { 27 | var _id; 28 | String path = ""; 29 | num sizeBytes = 0; 30 | num numFiles = 0; 31 | num numDirs = 0; 32 | 33 | GalleryData(this._id); 34 | } 35 | 36 | void clearContentDiv() { 37 | var content_div = document.querySelector("#content"); 38 | while (content_div.children.length >= 1) 39 | content_div.children.removeAt(0); 40 | } 41 | 42 | void clearList() { 43 | document.querySelector("#GalleryList").innerHtml = ""; 44 | } 45 | 46 | Element addTypeToContentDiv(String type) { 47 | var content = document.querySelector("#content"); 48 | var elemType = document.createElement(type); 49 | content.append(elemType); 50 | return (elemType); 51 | } 52 | 53 | String getFileType(String path) { 54 | var ext = path.split(".")[path.split(".").length - 1]; 55 | if (imgFormats.indexOf(ext) != -1) 56 | return ("image"); 57 | else if (vidFormats.indexOf(ext) != -1) 58 | return ("video"); 59 | else if (audFormats.indexOf(ext) != -1) 60 | return ("audio"); 61 | return (null); 62 | } 63 | 64 | void updateSelection(Event event) { 65 | SelectElement selList = document.querySelector("#GalleryList"); 66 | var index = selList.selectedIndex; 67 | var fsId = selList.options[index].getAttribute("data-fsid"); 68 | FileSystem fs = null; 69 | 70 | for (int i = 0; i < gGalleryArray.length; i++) { 71 | var mData = chrome.mediaGalleries.getMediaFileSystemMetadata(gGalleryArray[i]); 72 | if (mData.galleryId == fsId) { 73 | fs = gGalleryArray[i]; 74 | break; 75 | } 76 | } 77 | if (fs != null) { 78 | var path = selList.options[index].getAttribute("data-fullpath"); 79 | fs.root.getFile(path).then((FileEntry file_entry) { 80 | Element newElem = null; 81 | clearContentDiv(); 82 | var type = getFileType(path); 83 | if (type == "image") 84 | newElem = addTypeToContentDiv('img'); 85 | else if (type == "audio") 86 | newElem = addTypeToContentDiv('audio'); 87 | else if (type == "video") 88 | newElem = addTypeToContentDiv('video'); 89 | if (newElem != null) { 90 | file_entry.file().then((File file) { 91 | chrome.mediaGalleries.getMetadata(file).then((chrome.MediaMetadata metadata) { 92 | if (metadata.toJs()["attachedImages"].length > 0) { 93 | var blob = metadata.toJs()["attachedImages"][0]; 94 | var posterBlob = Url.createObjectUrl(blob); 95 | newElem.setAttribute("poster", posterBlob); 96 | } 97 | newElem.setAttribute("src", file_entry.toUrl()); 98 | }).catchError((e) { 99 | print("Error getMetadata: $e"); 100 | print("Use old way to put item in the dom"); 101 | newElem.setAttribute("src", file_entry.toUrl()); 102 | }); 103 | }); 104 | } 105 | }).catchError((e) => print("new File or file does not exist: $e")); 106 | } 107 | } 108 | 109 | void addItem(Entry itemEntry) { 110 | var opt = document.createElement('option'); 111 | if (itemEntry.isFile) { 112 | opt.setAttribute("data-fullpath", itemEntry.fullPath); 113 | 114 | var mData = chrome.mediaGalleries.getMediaFileSystemMetadata(itemEntry.filesystem); 115 | opt.setAttribute("data-fsid", mData.galleryId); 116 | } 117 | opt.innerHtml = itemEntry.name; 118 | gCurOptGrp.append(opt); 119 | } 120 | 121 | Element addGallery(name, id) { 122 | var optGrp = document.createElement("optgroup") 123 | ..setAttribute("label", name) 124 | ..setAttribute("id", id); 125 | document.querySelector("#GalleryList").append(optGrp); 126 | return (optGrp); 127 | } 128 | 129 | void scanGallery(List entries) { 130 | if (entries.length == 0) { 131 | if (gDirectories.length > 0) { 132 | DirectoryEntry dir_entry = gDirectories.removeAt(0); 133 | print('Doing subdir: ' + dir_entry.fullPath); 134 | gGalleryReader = dir_entry.createReader(); 135 | gGalleryReader.readEntries().then(scanGallery).catchError((e) => errorPrintFactory(e, 'readEntries')); 136 | return; 137 | } 138 | else { 139 | gGalleryIndex++; 140 | if (gGalleryIndex < gGalleryArray.length) { 141 | print("Doing next Gallery: ${gGalleryArray[gGalleryIndex].name}"); 142 | scanGalleries(gGalleryArray[gGalleryIndex]); 143 | } 144 | return; 145 | } 146 | } 147 | 148 | for (int index = 0; index < entries.length; index++) { 149 | print(entries[index].name); 150 | if (entries[index].isFile) { 151 | addItem(entries[index]); 152 | gGalleryData[gGalleryIndex].numFiles++; 153 | entries[index].getMetadata().then((metadata) { 154 | if (gGalleryData.length > gGalleryIndex) { 155 | gGalleryData[gGalleryIndex].sizeBytes = metadata.size; 156 | } 157 | }); 158 | } 159 | else if (entries[index].isDirectory) 160 | gDirectories.add(entries[index]); 161 | else 162 | print("Got something other than a file or directory."); 163 | } 164 | gGalleryReader.readEntries().then(scanGallery).catchError((e) => errorPrintFactory(e, 'readMoreEntries')); 165 | } 166 | 167 | void scanGalleries(FileSystem fs) { 168 | var mData = chrome.mediaGalleries.getMediaFileSystemMetadata(fs); 169 | print("Reading gallery: ${mData.name}"); 170 | 171 | gCurOptGrp = addGallery(mData.name, mData.galleryId); 172 | gGalleryData.add(new GalleryData(mData.galleryId)); 173 | gGalleryReader = fs.root.createReader(); 174 | gGalleryReader.readEntries().then(scanGallery).catchError((e) => errorPrintFactory(e, 'readEntries')); 175 | } 176 | 177 | void getGalleriesInfo(List results) { 178 | clearContentDiv(); 179 | if (results.isNotEmpty) { 180 | var sb = new StringBuffer(); 181 | sb.write("Gallery count: ${results.length} ( "); 182 | for (int index = 0; index < results.length; index++) { 183 | var result = results[index]; 184 | var mData = chrome.mediaGalleries.getMediaFileSystemMetadata(result); 185 | if (mData != null) { 186 | sb.write(mData.name); 187 | if (index < results.length - 1) 188 | sb.write(", "); 189 | sb.write(" "); 190 | } 191 | } 192 | sb.write(")"); 193 | document.querySelector("#status").innerHtml = sb.toString(); 194 | gGalleryArray = results; 195 | gGalleryIndex = 0; 196 | (document.querySelector("#read-button") as ButtonElement).disabled = false; 197 | } 198 | else { 199 | document.querySelector("#status").innerHtml = "No galleries found"; 200 | (document.querySelector("#read-button") as ButtonElement).disabled = true; 201 | } 202 | } 203 | 204 | void main() { 205 | var win = chrome.app.window.current(); 206 | if (win.toJs().hasProperty("__MGA__bRestart")) { 207 | if (win.toJs()["__MGA__bRestart"]) { 208 | print("app was restarted"); 209 | 210 | chrome.MediaFileSystemsDetails mfsd = new chrome.MediaFileSystemsDetails(interactive: chrome.GetMediaFileSystemsInteractivity.IF_NEEDED); 211 | chrome.mediaGalleries.getMediaFileSystems(mfsd).then(getGalleriesInfo); 212 | } 213 | } 214 | 215 | document.querySelector("#gallery-button").onClick.listen((event) { 216 | chrome.MediaFileSystemsDetails mfsd = new chrome.MediaFileSystemsDetails(interactive: chrome.GetMediaFileSystemsInteractivity.IF_NEEDED); 217 | chrome.mediaGalleries.getMediaFileSystems(mfsd).then(getGalleriesInfo); 218 | }); 219 | 220 | document.querySelector("#configure-button").onClick.listen((event) { 221 | chrome.MediaFileSystemsDetails mfsd = new chrome.MediaFileSystemsDetails(interactive: chrome.GetMediaFileSystemsInteractivity.YES); 222 | chrome.mediaGalleries.getMediaFileSystems(mfsd).then(getGalleriesInfo); 223 | }); 224 | 225 | document.querySelector("#add-folder-button").onClick.listen((event) { 226 | chrome.mediaGalleries.addUserSelectedFolder().then((chrome.AddUserSelectedFolderResult add_user_selected_folder) => getGalleriesInfo(add_user_selected_folder.mediaFileSystems)); 227 | }); 228 | 229 | document.querySelector("#read-button").onClick.listen((event) { 230 | clearContentDiv(); 231 | clearList(); 232 | if (gGalleryArray.length > 0) { 233 | gGalleryIndex = 0; 234 | gGalleryData.clear(); 235 | scanGalleries(gGalleryArray[0]); 236 | } 237 | }); 238 | document.querySelector("#GalleryList").onChange.listen((event) { 239 | updateSelection(event); 240 | }); 241 | 242 | ButtonElement scan_button = document.querySelector("#scan-button"); 243 | scan_button.onClick.listen((event) { 244 | if (scan_button.innerHtml == "Cancel Scan") 245 | chrome.mediaGalleries.cancelMediaScan(); 246 | else { 247 | scan_button.innerHtml = "Cancel Scan"; 248 | chrome.mediaGalleries.startMediaScan(); 249 | } 250 | }); 251 | document.querySelector("#add-scan-results-button").onClick.listen((event) { 252 | chrome.mediaGalleries.addScanResults().then(getGalleriesInfo); 253 | }); 254 | 255 | chrome.mediaGalleries.onScanProgress.listen((chrome.ScanProgressDetails scan_progress_details) { 256 | if (scan_progress_details.type.value == "finish") { 257 | document.querySelector("#status").innerHtml = 'Scan found ${scan_progress_details.galleryCount} galleries'; 258 | } 259 | else { 260 | document.querySelector('#status').innerHtml = 'Scanning: ${scan_progress_details.type}'; 261 | } 262 | 263 | if (scan_progress_details.type.value != "start") { 264 | document.querySelector('#scan-button').innerHtml = 'Search for Galleries'; 265 | } 266 | }); 267 | } 268 | 269 | 270 | -------------------------------------------------------------------------------- /media-gallery/web/mediagallery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Media Gallery API Sample 5 | 6 | 7 | 8 |

Media Gallery Explorer

9 | 10 | 11 | 12 | 13 | 14 | 15 |

16 |   17 |

18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /media-gallery/web/mga-128color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/media-gallery/web/mga-128color.png -------------------------------------------------------------------------------- /windows/README.md: -------------------------------------------------------------------------------- 1 | # Copycat Window 2 | 3 | Sample that shows how to use the [window API](http://developer.chrome.com/apps/app.window.html) to create a window with a custom frame and manipulate its properties. 4 | 5 | The app creates two windows, an "original" window and a "copycat" window. The copycat window mimics the position and minimize state of the original window, but it displays itself in an inverted fashion. 6 | 7 | ## APIs 8 | 9 | * [Window](http://developer.chrome.com/apps/app.window.html) 10 | 11 | ## Screenshot 12 | ![screenshot](https://raw.github.com/dart-gde/dart-chrome-app-samples/master/windows/screenshot.png) -------------------------------------------------------------------------------- /windows/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: windows 2 | description: Windowing API Sample 3 | dependencies: 4 | chrome: any 5 | transformers: 6 | - chrome 7 | -------------------------------------------------------------------------------- /windows/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/windows/screenshot.png -------------------------------------------------------------------------------- /windows/web/background.js: -------------------------------------------------------------------------------- 1 | function launch() { 2 | 3 | 4 | // create the original window 5 | chrome.app.window.create('original.html', { 6 | id: "mainwin", 7 | bounds: { 8 | top: 128, 9 | left: 128, 10 | width: 300, 11 | height: 300 12 | }, 13 | minHeight: 300, 14 | maxWidth: 500, 15 | minWidth: 300, 16 | frame: 'none' 17 | }); 18 | } 19 | 20 | chrome.app.runtime.onLaunched.addListener(launch); -------------------------------------------------------------------------------- /windows/web/copycat.dart: -------------------------------------------------------------------------------- 1 | import "script/update.dart"; 2 | 3 | void main() { 4 | update(); 5 | } 6 | -------------------------------------------------------------------------------- /windows/web/copycat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | CopyCat Windows 7 | 8 | 9 | 10 | 11 |

I'm a copycat

12 | 13 |
14 |

15 | Position: (, ) 16 |

17 | 18 |

19 | Size: (, ) 20 |

21 |
22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /windows/web/img/copycat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/windows/web/img/copycat.png -------------------------------------------------------------------------------- /windows/web/img/original.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dart-gde/dart-chrome-app-samples/44ba20283aee00137277ddaf60abbd3e047a225b/windows/web/img/original.png -------------------------------------------------------------------------------- /windows/web/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Windowing API Sample", 3 | "version": "1", 4 | 5 | "manifest_version": 2, 6 | 7 | "icons": {"128": "./img/original.png"}, 8 | 9 | "app": { 10 | "background": { 11 | "scripts": ["background.js"] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /windows/web/original.dart: -------------------------------------------------------------------------------- 1 | 2 | import 'dart:html'; 3 | 4 | import 'package:chrome/chrome_app.dart' as chrome; 5 | import "script/update.dart"; 6 | 7 | // kill all windows onClosed event 8 | void reset(windows) { 9 | windows.forEach((win) { 10 | win.close(); 11 | }); 12 | } 13 | 14 | void main() { 15 | var windows = []; 16 | // get original window 17 | var original = chrome.app.window.current(); 18 | windows.add(original); 19 | 20 | // create copycat window 21 | var bounds = original.getBounds(); 22 | bounds.left += bounds.width + 5; 23 | chrome.CreateWindowOptions cwo = new chrome.CreateWindowOptions(bounds: bounds, minWidth: 300, minHeight: 300, maxWidth: 500, frame: 'none'); 24 | chrome.app.window.create("copycat.html", cwo).then((chrome.AppWindow copycat) { 25 | windows.add(copycat); 26 | 27 | // original event 28 | original 29 | ..onBoundsChanged.listen((event) { 30 | var bounds = original.getBounds(); 31 | bounds.left = bounds.left + bounds.width + 5; 32 | copycat.setBounds(bounds); 33 | }) 34 | ..onRestored.listen((event) { 35 | print('original restored'); 36 | if (copycat.isMinimized()) { 37 | copycat.restore(); 38 | } 39 | }) 40 | ..onClosed.listen((event) => reset(windows)); 41 | 42 | // copycat event 43 | copycat 44 | ..onRestored.listen((event) { 45 | print('copy restored'); 46 | if (original.isMinimized()) { 47 | original.restore(); 48 | } 49 | }) 50 | ..onClosed.listen((event) => reset(windows)); 51 | 52 | var minimizeNode = document.querySelector("#minimize-button"); 53 | if (minimizeNode != null) { 54 | minimizeNode.onClick.listen((event) { 55 | windows.forEach((win) { 56 | win.minimize(); 57 | }); 58 | }); 59 | } 60 | 61 | update(); 62 | }); 63 | } 64 | -------------------------------------------------------------------------------- /windows/web/original.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Original Windows 7 | 8 | 9 | 10 | 11 |

Move me

12 | 13 |
14 |

15 | Position: (, ) 16 |

17 | 18 |

19 | Size: (, ) 20 |

21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /windows/web/script/update.dart: -------------------------------------------------------------------------------- 1 | import "dart:html"; 2 | 3 | void update([num coef = 0]) { 4 | document 5 | ..querySelector("#screenX").text = window.screenX.toString() 6 | ..querySelector("#screenY").text = window.screenX.toString() 7 | ..querySelector("#innerWidth").text = window.innerWidth.toString() 8 | ..querySelector("#innerHeight").text = window.innerHeight.toString(); 9 | 10 | window.requestAnimationFrame(update); 11 | } -------------------------------------------------------------------------------- /windows/web/styles/windows.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | padding: 0; 3 | margin: 0; 4 | width: 100%; 5 | height: 100%; 6 | font-family: Helvetica, Arial; 7 | } 8 | 9 | body.original { 10 | background: url("../img/original.png") center 75px no-repeat; 11 | position: relative; 12 | -webkit-app-region: drag; 13 | } 14 | 15 | button { 16 | -webkit-app-region: no-drag; 17 | } 18 | 19 | body.copycat { 20 | background: #333 url("../img/copycat.png") center 75px no-repeat; 21 | position: relative; 22 | color: #FFF; 23 | } 24 | 25 | h1 { 26 | padding: 0.6em 0; 27 | margin: 0; 28 | text-align: center; 29 | border-bottom: 1px solid #CCC; 30 | background: #F2F2F2; 31 | font-size: 24px; 32 | } 33 | 34 | button { 35 | width: 200px; 36 | height: 30px; 37 | font-size: 16px; 38 | position: absolute; 39 | bottom: 25px; 40 | left: 50%; 41 | margin-left: -100px; 42 | } 43 | 44 | #stats { 45 | position: absolute; 46 | top: 190px; 47 | width: 100%; 48 | } 49 | 50 | #stats p { 51 | text-align: center; 52 | margin: 0 0 0.5em; 53 | font-size: 12px; 54 | font-weight: bold; 55 | color: #888; 56 | } 57 | 58 | #stats p span { 59 | font-style: italic; 60 | font-weight: normal; 61 | } 62 | 63 | .copycat h1 { 64 | background: #444; 65 | } --------------------------------------------------------------------------------