Mozilla Addon SDK - Possible to save changes programmatically via simple-prefs? - mozilla

Is it possible to update a firefox addon's preferences programmatically?
Given the following:
const prefs = require("sdk/simple-prefs");
prefs.stringPreference = "some random string";
It seems that my update to stringPreference doesn't get persisted, and will revert back to the value in about:addons when reloaded, new tabs are opened, etc.
Is this possible? The docs imply changes are saved automatically but this doesn't seem to be the case..

You have missed the .prefs attribute. It should be:
var prefs = require("sdk/simple-prefs").prefs;
Notice the .prefs at the end of the line.

Related

VSCode extension - access timeline tab

Is there a way for a VSCode extension to access the timeline tab? I searched the docs but I couldn't find anything?
To be more specific, I'd like to watch for changes in certain files and get the diff of that change. I managed to register a listener on file changes, but I also want the actual change. This is what I have so far:
const vscode = require("vscode");
function activate(context) {
const workspacePath = vscode.workspace.workspaceFolders[0];
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(workspacePath, "**/package.json")
);
watcher.onDidChange((e) => {
console.log(e); # this only prints the file path, not the content.
}
}
module.exports = {activate};
There is no Timeline API available yet. There is however, a proposed API being discussed for a while (https://github.com/microsoft/vscode/issues/84297), but the last comment is one year old.
But, if you need to detect file changes (not necessarily the file being edited by the user, but any file in the workspace) and compare its content, you need not only the FileSystemWatcher but also some lib that provides you text differencing algorithm, like jsdiff.
Hope this helps

Modify security.enterprise_roots.enabled (or other about:config) in nodejs with selenium-webdriver using geckodriver

For my automation testing in NodeJS, I have the following script that creates a new instance of firefox and runs my script there
const firefox = require('selenium-webdriver/firefox');
let options = new firefox.Options().setBinary(os.homedir() + '/AppData/Local/Mozilla Firefox/firefox.exe');
let driver = new webDr.Builder()
.forBrowser('firefox').setFirefoxOptions(options).build();
However, the page I am automating needs an additional requirement... I need to set security.enterprise_roots.enabled to "true" (located in about:config)
I have changed the setting on my non-automated firefox browser. However, it seems that whenever I run the code above the driver reverts it back to "false".
How can I change this programmatically?
I saw this answer but it is in Python. How do you write the same code in NodeJS with selenium-webdriver?
The answer for me was that I had to use a different profile instead.
Before building the automation, I set .Options().setProfile() as follows:
let options = new firefox.Options().setBinary(os.homedir() +
'/AppData/Local/Mozilla Firefox/firefox.exe').setProfile(os.homedir() +
'/AppData/Roaming/Mozilla/Firefox/Profiles/(your profile.. it's a folder)');
let driver = new webDr.Builder().forBrowser('firefox').setFirefoxOptions(options).build();
This would run my firefox with the current settings I have with the profile, which includes security.enterprise_roots.enabled = true
(or other about:config settings)

#material material-component-web Invalid tab component given as activeTab

firstly let my say that the mdc documentation is difficult for non-pros like me.
I'm using Elixir Phoenix and Brunch.
I import and everything is fine.
import {MDCTab, MDCTabFoundation} from '#material/tabs'; import
{MDCTabBar, MDCTabBarFoundation} from '#material/tabs'; import
{MDCTabBarScroller, MDCTabBarScrollerFoundation} from
'#material/tabs';
I manually instantiate the tab bar in a separate function that I export
export var Tabbable = {
run: function(MDCTabBar, el){
var myDynamicTabBar = window.myDynamicTabBar = new MDCTabBar(document.querySelector('#' + el));
Which is following the documentation like this
const tabBar = new MDCTabBar(document.querySelector('#my-mdc-tab-bar'));
but is slightly different to the documentation's use of the tab bar in their code snippet
var dynamicTabBar = window.dynamicTabBar = new mdc.tabs.MDCTabBar(document.querySelector('#dynamic-tab-bar'));
But, whenever I try to use mdc I get a 'not defined' error. Therefore, I'm not using it :-)
Now, when the user clicks the tab bar I capture that like this:
myDynamicTabBar.listen('MDCTabBar:change', function ({detail: tabs}) {
var nthChildIndex = tabs.activeTabIndex;
updatePanel(nthChildIndex);
});
The subtle difference is that my myDynamicTabBar is MDCTabBar but the documentation's dynamicTabBar is mdc.tabs.MDCTabBar
My tab control works, but it throws an error only visible in the console:
Uncaught Error: Invalid tab component given as activeTab: Tab not
found within this component's tab list
which is likely because I'm not using mdc.tabs? The documentation notes the change event happens on the MDCTabBar.
Therefore, how do I get rid of this annoying error in the console?
And why can I not access the global mdc? I have tried this in my Brunch file
globals: { mdc: "#material"}
But no good.
I'm right behind you on this! I'm frustrated with the docs too :(
You answered your own question in this Elixir thread which is very informative.
I found the real solution in this thread https://github.com/hyperapp/hyperapp/issues/546
MDCTabBar automatically initiates its children. So initiating tabs will result in that error.
The fix is to just initiate MDCTabBar

Firefox Add-on SDK equivalent to Chrome's chrome.storage.sync? [duplicate]

I'm currently converting a Chrome extension into a Firefox add-on and would appreciate to replicate the chrome.storage.sync feature.
However, I cannot manage to find whether the data stored by a Firefox add-on using simple-storage will be automatically synced whenever a user of the add-on is signed into Firefox Sync.
Given that all the pieces of data stored via the latter method can be found in the user profile, I presume it will... as long as the add-on is available at https://addons.mozilla.org ?
Any information on the topic would be greatly appreciated.
simple-storage is not synced. But you can sync it with little effort.
The trick it to store the storage object, it is serializable by definition, as a string preference and tell to the sync service to synchronize it.
Lets name that preference syncstorage and mark it as synchronizable.
var self = require("sdk/self");
var prefs = require("sdk/preferences/service");
prefs.set("services.sync.prefs.sync.extensions." + self.id + ".syncstorage", true);
When storing something to simple-storage reflect the change to syncstorage.
var sp = require("sdk/simple-prefs");
var ss = require("sdk/simple-storage");
sp.prefs["syncstorage"] = JSON.stringify(ss.storage);
For the opposite effect watch syncstorage for changes
sp.on("syncstorage", function(prefname){
ss.storage = JSON.parse(sp.prefs["syncstorage"]);
})
Last but not least, It would nice and perhaps mandatory to sync only with the explicit consent of the user.

Flex - how to download a string variable as a file to the local machine?

I have a String variable in my flex (flash builder 4) application containing CSV data. I need to allow the user to download this data to a local file. For example, giving them a "csv" button to click and it might present them with a save file dialog (and I would be sending the contents of my string variable).
Is this possible / how ?
I am using the ResuableFX component for the datagrid to csv. This the code I ended up with that works to save the string to a text file for the user (in a web browser):
var dg2CSV:DataGrid2CSV = new DataGrid2CSV();
dg2CSV.includeHeader=true;
dg2CSV.target=adgEncounters;
var csvText:String=dg2CSV.getCSV();
var MyFile:FileReference = new FileReference();
var csvFileNameDT:String = QuickDateFormatter.format(new Date().toString(),"YYYYMMDDJJNNSS");
MyFile.save(csvText,"Encounters"+csvFileNameDT+".csv");
If you're in an AIR App you can use File.browseForSave().
If you're in a web app, you can use FileReference.save() . The FileReference docs have a lot more info on this.
In many cases, I would recommend using navigateToURL() to open the file outside of Flash and let the browser deal with it.
I'm not sure if there is a way to do this without user interaction.

Resources