Commit 43166f96 authored by Sören Hentzschel's avatar Sören Hentzschel

initial commit

parents
const PANEL_ID = 'panel.newsaboutmozilla@soeren-hentzschel.at';
const DATASET_ID = 'dataset.newsaboutmozilla@soeren-hentzschel.at';
const REF_ID = 'campaign=fx-android-home&version=1.0';
const DATA_URL = 'http://www.soeren-hentzschel.at/api/v1.0/latest-news.json';
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import('resource://gre/modules/Home.jsm');
Cu.import('resource://gre/modules/HomeProvider.jsm');
Cu.import('resource://gre/modules/Messaging.jsm');
Cu.import('resource://gre/modules/Services.jsm');
Cu.import('resource://gre/modules/Task.jsm');
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
XPCOMUtils.defineLazyGetter(this, 'Strings', function() {
return Services.strings.createBundle('chrome://newsaboutmozilla/locale/i18n.properties');
});
function optionsCallback() {
return {
title: Strings.GetStringFromName('title'),
views: [{
type: Home.panels.View.LIST,
dataset: DATASET_ID,
onrefresh : refreshDataset,
empty : {
text : Strings.GetStringFromName('empty_text')
}
}]
};
}
function fetchData (url, onFinish) {
let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Ci.nsIXMLHttpRequest);
try {
xhr.open('GET', url, true);
} catch (e) {
Cu.reportError('Error opening request to ' + url + ': ' + e);
return false;
}
xhr.onerror = function onerror (e) {
Cu.reportError('Error making request to ' + url + ': ' + e.error);
};
xhr.onload = function onload () {
if (xhr.status === 200) {
onFinish(xhr.responseText);
} else {
Cu.reportError('Request to ' + url + ' returned status ' + xhr.status);
}
};
xhr.send(null);
}
function refreshDataset () {
fetchData(DATA_URL, function (response) {
Task.spawn(function () {
let items = JSON.parse(response);
items.forEach(function (item) {
item.url += '?' + REF_ID;
});
let storage = HomeProvider.getStorage(DATASET_ID);
yield storage.deleteAll();
yield storage.save(items);
}).then(null, e => Cu.reportError('Error refreshing dataset ' + DATASET_ID + ': ' + e));
});
}
function deleteDataset() {
Task.spawn(function() {
let storage = HomeProvider.getStorage(DATASET_ID);
yield storage.deleteAll();
});
}
function openPanel () {
Services.wm.getMostRecentWindow('navigator:browser').BrowserApp.loadURI('about:home?panel=' + PANEL_ID);
}
function startup(data, reason) {
Home.panels.register(PANEL_ID, optionsCallback);
switch(reason) {
case ADDON_INSTALL:
case ADDON_ENABLE:
Home.panels.install(PANEL_ID);
HomeProvider.requestSync(DATASET_ID, refreshDataset);
break;
case ADDON_UPGRADE:
case ADDON_DOWNGRADE:
Home.panels.update(PANEL_ID);
break;
}
if (reason === ADDON_INSTALL) {
openPanel();
}
HomeProvider.addPeriodicSync(DATASET_ID, 3600, refreshDataset);
}
function shutdown(data, reason) {
if (reason == ADDON_UNINSTALL || reason == ADDON_DISABLE) {
HomeProvider.removePeriodicSync(DATASET_ID);
Home.panels.uninstall(PANEL_ID);
deleteDataset();
}
Home.panels.unregister(PANEL_ID);
}
function install(data, reason) {}
function uninstall(data, reason) {}
#!/bin/bash
# Replace this value with your add-on name
XPI=newsaboutmozilla.xpi
# Replace this value to push to different release channels.
# Nightly = org.mozilla.fennec
# Aurora = org.mozilla.fennec_aurora
# Beta = org.mozilla.firefox_beta
# Release = org.mozilla.firefox
ANDROID_APP_ID=org.mozilla.fennec
# List add-on files here
zip -r $XPI bootstrap.js \
install.rdf \
chrome.manifest \
locale \
-x *.DS_Store*
# Push the add-on to your device to test
adb push "$XPI" /sdcard/"$XPI" && \
adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.DEFAULT \
-d file:///mnt/sdcard/"$XPI" \
-n $ANDROID_APP_ID/.App && \
echo Pushed $XPI to $ANDROID_APP_ID
locale newsaboutmozilla de locale/de/
<?xml version='1.0' encoding='utf-8'?>
<RDF xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:em='http://www.mozilla.org/2004/em-rdf#'>
<Description about='urn:mozilla:install-manifest'>
<em:id>newsaboutmozilla@soeren-hentzschel.at</em:id>
<em:type>2</em:type>
<em:name>Neues aus der Mozilla-Welt</em:name>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>
<em:description>Aktuelles zu Mozilla auf der Startseite von Firefox Mobile für Android.</em:description>
<em:creator>Sören Hentzschel</em:creator>
<em:targetApplication>
<Description>
<em:id>{aa3c5121-dab2-40e2-81ca-7ea25febc110}</em:id>
<em:minVersion>30.0a1</em:minVersion>
<em:maxVersion>32.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
title = Neues aus der Mozilla-Welt
empty_text = Derzeit können leider keine Inhalte abgerufen werden. Bitte versuchen Sie es später erneut.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment