I'm using localStorage in my Firefox add-on in this way:
var ioService = Components.classes['#mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
var scriptSecManager = Components.classes['#mozilla.org/scriptsecuritymanager;1'].getService(Components.interfaces.nsIScriptSecurityManager);
var domStorageManager = Components.classes['#mozilla.org/dom/storagemanager;1'].getService(Components.interfaces.nsIDOMStorageManager);
var uri = ioService.newURI('http://example.com/addon/', null, null);
var principal = scriptSecManager.getNoAppCodebasePrincipal ? scriptSecManager.getNoAppCodebasePrincipal(uri) : scriptSecManager.getCodebasePrincipal(uri);
var localStorage = domStorageManager.getLocalStorageForPrincipal(principal, '');
All works fine, but when user removes "offline data" storage is cleared. How can i workround it?
Use the preferences service to store the data in the user's profile.
var prefService = Cc["#mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService),
prefs = prefService.getBranch("extensions.YOUREXTENSIONABBREVIATIONHERE.");
var stringValue = "My Name",
booleanValue = true,
numberValue = 55;
prefs.setCharPref("stringParam", stringValue);
prefs.setBoolPref("booleanParam", booleanValue);
prefs.setCharPref("numberParam", ''+numberValue);
prefService.savePrefFile(null); // only to force an immediate save
stringValue = prefs.getCharPref("stringParam");
booleanValue = prefs.getBoolPref("booleanParam");
numberValue = parseInt(prefs.getCharPref("numberParam"), 10);
Put a defaults.js file in your defaults/preferences folder and initialize preferences for a new user. You'll get an error if you try to retrieve a preference that doesn't exist and there's no way to check if it exists.
Look here:
https://developer.mozilla.org/en-US/docs/Adding_preferences_to_an_extension
Related
I have some problem with move incoming email to junk folder. I'm writing Thunderbird extension and I use function CopyMessage() from nsIMsgMessageService to move incoming mail to junk folder.
I have problem with use this function. In documentation of this function, is writing "Pass in the URI for the message you want to have copied. aCopyListener already knows about the destination folder." Variable aCopyListener is a interface from nsIStreamListener and i don't see any properties who would have information about the destination incoming mail. How to properly use this function and copy message to junky folder?
Link for documentation: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgMessageService#CopyMessage()
function listMessages(aFolder) {
Components.utils.import("resource:///modules/iteratorUtils.jsm");
let database = aFolder.msgDatabase;
for each (let msgHdr in fixIterator(database.EnumerateMessages(),
Components.interfaces.nsIMsgDBHdr)) {
let title = msgHdr.mime2DecodedSubject;
let messenger = Components.classes["#mozilla.org/messenger;1"].createInstance(Components.interfaces.nsIMessenger);
let listener = Components.classes["#mozilla.org/network/sync-stream-listener;1"].createInstance(Components.interfaces.nsISyncStreamListener);
let uri = msgHdr.folder.getUriForMsg(msgHdr);
var messageService = messenger.messageServiceFromURI(uri);
messenger.messageServiceFromURI(uri).streamMessage(uri, listener, null, null, false, "");
let folder = msgHdr.folder;
let messageBody = folder.getMsgTextFromStream(listener.inputStream,
msgHdr.Charset,
65536,
32768,
false,
true,
{ });
var incomingMail = folder.server.rootFolder.getChildNamed("Odebrane");
var junkyMail = folder.server.rootFolder.getChildNamed("Niechciane");
messageService.CopyMessage(incomingMail.URI, listener, true, null, null, new Object);
}
aFolder.msgDatabase = null;
database.forceFolderDBClosed(aFolder);
}
Here's what I use to copy the currently selected message to another folder:
Components.utils.import("resource:///modules/mailServices.js");
var msgs = Cc["#mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
msgs.appendElement(gFolderDisplay.selectedMessage, false);
var isMove = false;
var copyService = MailServices.copy; // nsIMsgCopyService
let destFolder = gFolderDisplay.displayedFolder.rootFolder;
copyService.CopyMessages(gFolderDisplay, msgs, destFolder, isMove, CopyListener, null, false);
I have this code
var englishSubtitle = new chrome.cast.media.Track(2,chrome.cast.media.TrackType.TEXT);
englishSubtitle.trackContentId = 'english.vtt';
englishSubtitle.trackContentType = 'text/vtt';
englishSubtitle.subtype = chrome.cast.media.TextTrackType.CAPTIONS;
englishSubtitle.name = 'English';
englishSubtitle.language = 'en-US';
englishSubtitle.customData = null;
var tracks = englishSubtitle;
var mediaInfo = new chrome.cast.media.MediaInfo(app.streamState_.manifest);
mediaInfo.contentType = app.streamState_.type;
mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
mediaInfo.customData = null;
mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;
mediaInfo.textTrackStyle = new chrome.cast.media.TextTrackStyle();
mediaInfo.tracks = tracks;
mediaInfo.metadata.metadataType = chrome.cast.media.MetadataType.GENERIC;
var activeTrackIds = [2];
var request = new chrome.cast.media.LoadRequest(mediaInfo);
request.autoplay = true;
request.currentTime = 0;
request.activeTrackIds = activeTrackIds;
session.loadMedia(request,onMediaDiscovered.bind( this, 'loadedMedia'), onMediaError);
I want to show subtitle on chromecast. When I want to set activeTracks on the request, I receive an error
Object {code: "session_error", description: "INVALID_PARAMS", details: Object}
The subtitle it doesn't show and the video doesn't play it at all, because of that error.
Am I doing something wrong?
tracks should be an array when you set
mediaInfo.tracks = tracks;
In your case, you should try
var tracks = [englishSubtitle];
and as was said earlier, use SUBTITLES instead of CAPTIONS. Finally make sure you have CORS headers present from your web server even if you are using mp4.
tracks should be stored inside an array
https://developers.google.com/cast/docs/reference/chrome/chrome.cast.media.MediaInfo#tracks
Array of non-null chrome.cast.media.Track
Array of Track objects.
mediaInfo.tracks = [englishSubtitle, frenchSubtitle, germanSubtitle]
I've created a simple javascript wrapper for the chromecast SDK:
https://github.com/Fenny/ChromecastJS
Might be worth to check out if you stumble upon more problems, good luck!
So I wanted to use the $.now() along with the persons IP address as a type of random number generator to attach to the front of file names to insure that if a file with the same name was uploaded it would not overwrite the first one.
the code I came up with was as follows:
var ipadd = '';
var filename = 'name';
var militime = 't';
var uploadname = '';
var ipid = '';
$(window).load(function() {
militime = $.now();
console.log(militime);
$('a.next-btn').on('click', function() {
$.get("https://ipinfo.io", function(response) {
ipadd = response.ip;
ipid = ipadd + militime;
}, "jsonp");
});
$('.file-uploader-form input[name="floor_plan_upload"]').live('change', function() {
var filename = $('.flow-section input[name="floor_plan_upload"]').val().split('\\').pop();
uploadname = ipid + filename;
$('input[name="file_path"]').val(uploadname).change();
});
});
I tested it in chrome on mac and it worked fine, it also works fine in firefox on windows but not chrome or microsoft edge on windows, it only displays the IP address.
Ive also tryed using Date.now(); and new Date().getTime(); to the same ends.
I did notice though that when I remove the militime = $.now(); from after the $(window).load(function(){ that it doesn't even print what I made the default value for militime 't', so that suggests that there is something else wrong here, I just don't know what.
You should not use the user provided filename as the filename on the server. So, generate the unique filename on the server instead.
OK this doesn't solve the problem, but then again you're solving it wrong...
My problem is that I need in the key_client variable is loaded variable md5 obtained through a module called nodejs get-mac.
The way I'm working it can not get it work.
Always runs before key_client to get mac.
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
});
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
Try:
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
someFunction();
});
function someFunction() {
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
}
Hallo,
i would like to do something that i thought would be fairly simple:
get the loginName of the current user using the SharePoint2010 Client OM with ECMAScript.
Here is my code:
var currentcontext = new SP.ClientContext.get_current();
var currentweb = currentcontext.get_web();
currentcontext.load(currentweb);
var currentuser = currentweb.get_currentUser();
currentcontext.load(currentuser);
var loginName = currentuser.get_loginName();
the last line throws an exception:
"The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."
But why? I've loaded the 'currentuser', so why is the 'property or field' not initialized?
Here is a more complete example with executeQueryAsync:
SP.SOD.executeOrDelayUntilScriptLoaded(runMyCode, "SP.js");
function runMyCode() {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
//only in the success case you can work with user login
doSomethingWithUserLogin(user.get_loginName());
},
function (data) {
//notify the failure
});
}
You need to retrieve the user first and load the web, not the user.
The following should work:
var currentcontext = new SP.ClientContext.get_current();
var currentweb = currentcontext.get_web();
currentcontext.load(currentweb);
var currentuser = currentweb.get_currentUser();
currentuser.retrieve();
currentcontext.load(currentweb);
var loginName = currentuser.get_loginName();
For an even better example using an asynchronous query check the following tutorial:
SharePoint 2010 ECMAScript - How to know logged in user information