-Поиск по дневнику

Поиск сообщений в rss_planet_mozilla

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 19.06.2007
Записей:
Комментариев:
Написано: 7


Francois Marier: Settings v. Prefs in Gaia Development

Понедельник, 28 Апреля 2014 г. 12:30 + в цитатник

Jed and I got confused the other day when trying to add hidden prefs for a small Firefox OS application. We wanted to make a few advanced options configurable via preferences (like those found in about:config in Firefox) but couldn't figure out why it wasn't possible to access them from within our certified application.

The answer is that settings and prefs are entirely different things in FxOS land.

Preferences

This is how you set prefs in Gaia:

pref("devtools.debugger.forbid-certified-apps", false);
pref("dom.inter-app-communication-api.enabled", true);

from build/config/custom-prefs.js.

These will be used by the Gecko layer like this:

if (!Preferences::GetBool("dom.inter-app-communication-api.enabled", false)) {
  return false;
}

from within C++ code, and like this:

let restrictPrivileges = Services.prefs.getBoolPref("devtools.debugger.forbid-certified-apps");

from JavaScript code.

Preferences can be strings, integers or booleans.

Settings

Settings on the other hand are JSON objects which can be set like this:

"alarm.enabled": false,

in build/config/common-settings.json and can then be read like this:

var req = navigator.mozSettings.createLock().get('alarm.enabled');
req.onsuccess = function() {
  marionetteScriptFinished(req.result['alarm.enabled']);
};

as long as you have the following in your application manifest:

"permissions": {
  ...
  "settings":{ "access": "readwrite" },
  ...
}

In other words, if you set something in build/config/custom-prefs.js, don't expect to be able to read it using navigator.mozSettings or the SettingsHelper!

http://feeding.cloud.geek.nz/posts/settings_v_prefs_in_gaia_development/


 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку