Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32541 from Cwiiis/bug1191745-bug1202422-reland
Browse files Browse the repository at this point in the history
Bug 1191745 - Switch to new home screen by default + Bug 1202422 - Migrate from verticalhome to homescreen
  • Loading branch information
Cwiiis committed Oct 19, 2015
2 parents b86bffe + 1fb8834 commit 497143e
Show file tree
Hide file tree
Showing 65 changed files with 748 additions and 258 deletions.
9 changes: 5 additions & 4 deletions apps/homescreen/js/app.js
Expand Up @@ -156,10 +156,10 @@
// won't save, but it's better than showing a blank screen.
// If this is the first run, get the app order from the first-run script
// after initialising the metadata database.
this.metadata.init().then(this.settings.firstRun ?
LazyLoader.load(['js/firstrun.js'],
this.metadata.init().then(this.settings.firstRun ? () => {
return LazyLoader.load('js/firstrun.js').then(
() => {
FirstRun().then((results) => {
return FirstRun().then((results) => {
this.toggleSmall(results.small);
this.startupMetadata = results.order;
this.settings.save();
Expand All @@ -172,7 +172,8 @@
(e) => {
console.error('Failed to load first-run script');
return Promise.resolve();
}) :
});
} :
() => {
return this.metadata.getAll(result => {
// Process results as they come in
Expand Down
118 changes: 116 additions & 2 deletions apps/homescreen/js/firstrun.js
Expand Up @@ -5,10 +5,124 @@

const COLS_PREF = 'grid.cols';

const VERTICALHOME_APPS = 'verticalhome_items_migration';

const VERTICALHOME_SETTINGS = 'vertical_preferences_store';

function FirstRun() {
return importVerticalHome().then(Promise.resolve(),
(e) => {
console.warn('Loading default settings, import failed:', e);
return loadDefault();
});
}

function importVerticalHome() {
return new Promise((resolve, reject) => {
if (!navigator.getDataStores) {
reject('DataStore API is unavailable');
return;
}

navigator.getDataStores(VERTICALHOME_APPS).then(
stores => {
if (stores.length < 1) {
reject('verticalhome datastores inaccessible');
return;
}

stores[0].getLength().then(length => {
if (length === 0) {
reject('No verticalhome app order to import');
return;
}

var cursor = stores[0].sync();

var items = {};
var iterateItems = () => {
cursor.next().then(task => {
switch (task.operation) {
case 'done':
// Convert from verticalhome storage format to something
// homescreen can use, skipping over features that aren't
// supported.
var id;
var order = [];
for (var prop in items) {
var item = items[prop];
switch (item.type) {
case 'app':
id = item.manifestURL + '/' +
(item.entryPoint ? item.entryPoint : '');
break;

case 'bookmark':
id = item.id;
break;

default:
continue;
}

order.push({ id: id, order: item.index });
}

// Sort by order
order.sort((a, b) => { return a.order - b.order; });

// Rewrite order so there are no gaps
order.forEach((entry, index) => {
entry.order = index;
});

// Load columns setting and resolve
navigator.getDataStores(VERTICALHOME_SETTINGS).then(
stores => {
stores[0].get(COLS_PREF).then(cols => {
resolve({ order: order, small: cols >= 4 });
}, () => {
resolve({ order: order, small: false });
});
},
(e) => {
console.error('Error retrieving columns preference', e);
resolve({ order: order, small: false });
});
return;

case 'clear':
items = {};
break;

case 'put':
case 'add':
items[task.id] = task.data;
break;

case 'remove':
delete items[task.id];
break;

default:
reject('Unhandled datastore operation: ' + task.operation);
return;
}

iterateItems();
}, reject);
};

iterateItems();
}, reject);
}, reject);
});
}

function loadDefault() {
return new Promise((resolve, reject) => {
LazyLoader.getJSON('js/init.json').then(
(json) => {
json => {
if (!json) {
resolve({ order: [], small: false});
return;
Expand Down Expand Up @@ -38,7 +152,7 @@

resolve({ order: order, small: small});
},
(e) => {
e => {
reject(e);
}
);
Expand Down
31 changes: 29 additions & 2 deletions apps/homescreen/manifest.webapp
@@ -1,6 +1,6 @@
{
"name": "New Home Screen",
"description": "Vertical paged home screen.",
"name": "Default Home Screen",
"description": "Gaia home screen.",
"launch_path": "/index.html",
"type": "privileged",
"role": "homescreen",
Expand All @@ -24,6 +24,25 @@
"moz-extremely-unstable-and-will-change-webcomponents": {},
"systemXHR": {}
},
"default_locale": "en-US",
"locales": {
"ar": {
"name": "الشاشة الرئيسية",
"description": "Gaia الشاشة الرئيسية"
},
"en-US": {
"name": "Default Home Screen",
"description": "Gaia Home Screen."
},
"fr": {
"name": "Écran d’accueil",
"description": "Écran d’accueil Gaia"
},
"zh-TW": {
"name": "主畫面",
"description": "Gaia 主畫面"
}
},
"datastores-access": {
"bookmarks_store": {
"readonly": true,
Expand All @@ -40,6 +59,14 @@
"homescreen_settings": {
"readonly": true,
"description": "Read home screen settings."
},
"vertical_preferences_store": {
"readonly": true,
"description": "Import settings from old home screen."
},
"verticalhome_items_migration": {
"readonly": true,
"description": "Import settings from old home screen."
}
},
"orientation": "default"
Expand Down
13 changes: 13 additions & 0 deletions apps/homescreen/test/marionette/client_options_verticalhome.js
@@ -0,0 +1,13 @@
module.exports = {
prefs: {
'dom.webcomponents.enabled': true,
'dom.mozApps.homescreenURL':
'app://homescreen.gaiamobile.org/manifest.webapp'
},
settings: {
'devtools.qps.enabled': false,
'language.current': 'en-US',
'homescreen.manifestURL':
'app://verticalhome.gaiamobile.org/manifest.webapp'
}
};
34 changes: 34 additions & 0 deletions apps/homescreen/test/marionette/lib/homescreen.js
Expand Up @@ -83,6 +83,18 @@ Homescreen.prototype = {
this.client.apps.switchToApp(Homescreen.URL);
},

/**
* Find and return every id for all the items on the grid... Each element
* can be used with `.getIcon` to find the element for a given id.
*
* @return {Array[String]}
*/
getIconIdentifiers: function() {
return this.visibleIcons.map(function(el) {
return this.getIconId(el);
}, this);
},

/**
* Fetch an icon element on the homescreen by its identifier.
* For apps, the identifier is the manifestURL, or its manifestURL,
Expand Down Expand Up @@ -118,6 +130,17 @@ Homescreen.prototype = {
return null;
},

/**
* Returns a homescreen icon element's identifier.
*
* @param {Marionette.Element} icon A homescreen icon element reference.
*/
getIconId: function(icon) {
return icon.scriptWith(function(el) {
return el.dataset.identifier;
});
},

/**
* Returns a homescreen icon element's text.
*
Expand Down Expand Up @@ -304,6 +327,17 @@ Homescreen.prototype = {
});
},

/**
* Emulates pressing of the hardware home button.
*/
pressHomeButton: function() {
this.client.executeScript(function() {
var home = new CustomEvent('home');
window.dispatchEvent(home);
});
this.client.apps.switchToApp(Homescreen.URL);
},

/**
* Gets a localized application name from a manifest.
* @param {String} app to open
Expand Down
1 change: 1 addition & 0 deletions apps/homescreen/test/marionette/manifest.ini
Expand Up @@ -27,3 +27,4 @@
[layout_test.js]
[localization_test.js]
[pinning_the_web_test.js]
[verticalhome_migration_test.js]
60 changes: 60 additions & 0 deletions apps/homescreen/test/marionette/verticalhome_migration_test.js
@@ -0,0 +1,60 @@
'use strict';
/* global __dirname */

var assert = require('assert');

marionette('Homescreen - verticalhome migration', function() {
var client = marionette.client({
profile: require(__dirname + '/client_options_verticalhome.js')
});
var actions, verticalhome, home, system;

setup(function() {
actions = client.loader.getActions();
verticalhome = client.loader.getAppClass('verticalhome');
home = client.loader.getAppClass('homescreen');
system = client.loader.getAppClass('system');
system.waitForFullyLoaded();
verticalhome.waitForLaunch();
});

test('App order is imported from verticalhome', function() {
// Drag the second icon to the first position so we differ from the
// default settings.
var icon1 = verticalhome.getNthIcon(1);
var icon2 = verticalhome.getNthIcon(2);
actions.press(icon2).wait(1).move(icon1).release().wait(1).perform();
verticalhome.exitEditMode();

// Restart the home screen so that icon DOM order corresponds with actual
// order.
verticalhome.restart();

// Record the names of all the apps and bookmarks (these are the only
// items that are migrated)
var iconNames =
client.findElements('#icons div.icon:not(.placeholder):not(.collection)').
map(function(icon) {
return icon.findElement('.title').text();
});

// Request migration to new home screen
client.executeScript(function() {
window.wrappedJSObject.app.itemStore.migrate(
'app://homescreen.gaiamobile.org/manifest.webapp');
});
client.switchToFrame();
home.waitForLaunch();

// Verify icon order matches
var importedIconNames = home.visibleIcons.map(function(icon) {
return home.getIconText(icon);
});

var nIcons = iconNames.length;
assert.equal(importedIconNames.length, nIcons);
for (var i = 0; i < nIcons; i++) {
assert.equal(importedIconNames[i], iconNames[i]);
}
});
});

0 comments on commit 497143e

Please sign in to comment.