5.2 KiB
Use Share With Me for Mobile Chrome Apps
Getting started
Share With Me could be fully adapted to Mobile Chrome Apps through mobile-friendly features. Mobile Chrome Apps, is based on Apache Cordova, and requires mobile application SDKs such as Android and iOS. so please make sure that installation development tool by following installation guide of Mobile Chrome Apps. And then, You do some further steps to resolve some of restrictions and configurations to use Share With Me on Cordova. Looking for a guide video below to better understand.
Download Share With Me into your workspace
To download and preparation, follow this guide of Share With Me. Make sure that install all of dependencies of npm and Bower.
Create a Cordova project
Create a Cordova project in path polymer-starter-kit by following command. platform is the path for Cordova project files, com.your.app is the project name/id and next following string is the description for your app.
cca create platform com.your.app "Your Share With Me App"
If you have no problems while creating a project you will seeing the message of installing successful coming from Cordova and have the tree of the project below.
└── polymer-starter-kit
└── app
│ ├── elements
│ ├── images
│ ├── index.html
│ ├── manifest.json
│ ├── scripts
│ ├── styles
│ └── test
├── bower.json
├── bower_components
├── docs
├── gulpfile.js
├── node_modules
├── package.json
├── platform
│ ├── config.xml
│ ├── hooks
│ ├── platforms
│ ├── plugins
│ └── www
For further informations of Cordova, please visit corodova document
Configuration
You need to have some changes of configuration to fit for Mobile Chrome Apps as it was mentioned above.
Configure path for app built by gulp
-
Change the path
distingulpfile.jsfromdisttoplatform/www/app, then the app built with Share With Me will be placed underplatform/wwwwill be used by Cordova.var DIST = 'platform/www/app'; -
Change the path in
platform/www/background.jsinto new pathchrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('app/index.html', { width: 244, height: 380, }); }); -
Add path
/apptoapp.baseURLinapp/scripts/app.js'.platform/www` is root path of app that will prevent errors coming from page routing.app.baseUrl = '/app';
Update gulp tasks
- Using
polybuild(vulcanize + crisper)task is mandatory because of Chrome Apps doesn't allow inline script blocks according to CSP. You should replace currentvulcanizetask with new task below. To do this installpolybuildfirst withnpm install --save-dev polybuildcommand// load polybuild var polybuild = require('polybuild'); // Vulcanize granular configuration gulp.task('vulcanize', function() { return gulp.src('app/elements/elements.html') .pipe(polybuild({maximumCrush: true})) .pipe($.rename(function(file) { if (file.extname === '.html') { file.basename = file.basename.replace('.build', ''); } })) .pipe(gulp.dest(dist('elements'))) .pipe($.size({title: 'vulcanize'})); });
More updates
-
Remove useless files generated from Cordova.
rm platform/www/index.* -
To complete first route for
homeyou need to put try/catch block into the first route code on starting app, inapp/elements/routing.html, because Chrome Apps doesn't allow usinghistoryAPIs which related to error messagehistory.pushState/replaceState is not available in packaged apps.try { page({ hashbang: true }); } catch (e) { app.route = 'home'; } -
Using
@importinstead oflinkto download external Google robot fonts which is related toRefused to load the stylesheeterrors. Update code inbower_components/font-roboto/roboto.htmlto using@importcode below@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,500italic,700,700italic); @import url(https://fonts.googleapis.com/css?family=Roboto+Mono:400,700);
Build and run app
After done of above steps. run this command on root path that let you see Chrome Apps built with Share With Me.
gulp && cd platform && cca run chrome
or to run on Android emulator or devices
gulp && cd platform && cca run android