I'd like to write an electron app, which is based on a number of windows.
Using this app, I'd like to be able to log in into a web-app using different roles in different windows.
Therefore, I need a feature to store cookies in different windows of the app at different locations. HTML, JS code and cookies data of window A should not see that of windows B.
Alternatively, I could image to somehow trap set-cookie requests and keep them in memory, thus not using app global cookie storage on HD.
Could someone provide code for this feature?
I'm aware of this post, which explains how to app.setPath() of userData. Unfortunately userData is app-global, not e.g. window local.
If I would be now able to trap each cookie-set operation of each BrowserWindow, I would be able to use app.setPath() and switch the cookie storage based on the window, the trap was fired.
I did find a solution:
First create a partition. Let name it SomeNameForMySession :
const partition = 'persist:SomeNameForMySession'
Then pass the partition to a BrowserWindow like so at creation time:
var ctrlWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
partition: partition
}
})
If another BrowserWindow gets another partition with another name, the windows have fully separated cookies.
If another BrowserWindow gets the same partition, the windows share cookie storage.
Using this, you may for example trace, what cookie events happen in session of the named partition:
// First find the correct session based on the partitions name
const ses2 = session.fromPartition( partition2 )
// Then, add a listener
ses2.cookies.addListener( 'changed', function ( event, cookie, cause, removed ) {
console.log('COOKIE: ' + cookie.name + ' :: ' + cookie.value )
})
Related
I'm not really understand what's the temporary storage means.
recently I have an issue:
We can deliver a variable to the function by TwiML, but it's have size/length limit. So I have to save this variable to global, so I can get this variable in anywhere(function) I want. But I'm worry if the variable will be changed by some others, because our function in twilio is serverless. In fact, global variable is not safe. Anyone can solve this?
I want to ask may I use temporary storage to resolve this?
Thanks.
Twilio developer evangelist here.
A coworker, a solutions engineer based in the UK, wrote this great blog post on using temporary storage in a Twilio Function.
The code in your Twilio Function would look something like
/**
*
* This Function shows you how to reach and utilise the temporary storage under the Function layer, mainly for single-invocation jobs
* For example, on each invocation we can create a file based on user data and use it accordingly
*
* IMPORTANT: Do NOT treat this storage as long term storage or for personal data that need to persist.
* The contents get deleted whenever the associated container is brought down, so this function is useful for one time actions
*
*/
var fs = require('fs');
var path = require('path');
var tmp_dir = require('os').tmpdir();
exports.handler = function(context, event, callback) {
/*We create a text file and we put some data in it*/
fs.writeFile(path.join(tmp_dir, 'test_file.txt'), 'Contents of created file in OS temp directory', function(err) {
if (err) callback(err);
/*We read the contents of the temporary directory to check that the file was created. For multiple files you can create a loop*/
fs.readdir(tmp_dir, function(err, files) {
if (err) callback(err);
callback(null, "File created in temporary directory: " + files.join(", "));
});
});
};
If you want to use temporary storage from the Twilio CLI, you can do so by running this command inside a project that you created with the Serverless Toolkit:
twilio serverless:new example --template=temp-storage
This Function template is also here on the Twilio Labs GitHub page.
Let me know if this helps at all!
enter image description here
The code looks like this:
In widget api_get_account_status, I save correlationId to function storage-CallSid;
In function storage-CallSid, I save correlationId to the "temporary storage";
In widget split_check_call_type, I invoke another function get-storage-CallSid;
In function get-storage-CallSid, may I get correlationId from "temporary storage"?
In https://github.com/holochain/holochat-rust, how are the files ui/holoclient.js and ui/holoclient.map obtained ?
Also, is there any official documentation about that that I missed and is this still the way to get a UI to talk to the holochain container ?
ui/holoclient.js is a tiny library that makes it much easier to talk to a running Holochain app instance. The current way of connecting your GUI to an instance is a JSON-RPC-like process via a local WebSocket connection. It's intended as a nice wrapper to make zome function calls feel like local, in-browser function calls. Documentation is currently very light, but it shouldn't take much to figure out how it's supposed to work using the example. In a nutshell:
const url = 'ws://localhost:3000/'
window.holoclient.connect(url).then(({call, close}) => {
document.getElementById('form').addEventListener('submit', e => {
e.preventDefault()
// First, get a list of locally running Holochain instances...
call('info/instances')().then(info => {
// Now that we have instance info, we can make zome calls into any of them
// by referring to them by DNA hash (and agent ID) as specified in our
// container config.
// Search for the instance we're looking for, given known DNA and agent
// hashes.
const matchingInstances = Object.entries(info)
.find(([id, value]) => value.dna === 'blog_dna_hash' && value.agent === 'my_agent_hash')
const instance = getInstance(info, 'the_dna_hash', 'the_agent_hash')
const content = document.querySelector('#message').value
// Make another zome call now
call(instance, 'blog', 'main', 'create_post')({
content: content
})
})
})
})
It's written in TypeScript, which would mean that ui/holoclient.map is a 'source map', a file which maps line numbers in the compiled JavaScript file to line numbers in the original TypeScript source. Both Chrome and Firefox look for and use those source maps when you're debugging your JS.
I use the Silex/Pimple container to store parameters for my application. Some of those parameters are set using middleware.
Now I have come across the problem where I want to access a parameter value that should have been set through middleware. But when I output it, it still contains the old value.
This is a simplified version of my code:
$app['test'] = 'old value';
$app->before(function (Symfony\Component\HttpFoundation\Request $request, Silex\Application $app){
// logic
$app['test'] = 'new value';
}, Silex\Application::EARLY_EVENT);
echo $app['test'];
outputs:
old value
Does someone know how I can force the middleware to run first and then do the output? Or is there an other way to interact with the request before everything else?
I am looking to write a small firefox add-on that detects when files that were downloaded are (or have been) deleted locally and removes the corresponding entry in the firefox download list.
Can anybody point me to the relevant api to manipulate the download list? I cannot seem to find it.
The relevant API is PlacesUtils which abstracts the complexity of the Places database.
If your code runs in the context of a chrome window then you get a PlacesUtils glabal variable for free. Otherwise (bootstrapped, Add-on SDK, whatever) you have to import PlacesUtils.jsm.
Cu.import("resource://gre/modules/PlacesUtils.jsm");
As far as Places is concerned, downloaded files are nothing more than a special kind of visited pages, annotated accordingly. It's a matter of just one line of code to get an array of all downloaded files.
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
Since we asked for the destinationFileURI annotation, each element of the resultarray holds the download location in the annotationValue property as a file: URI spec string.
With that you can check if the file actually exists
function getFileFromURIspec(fileurispec){
// if Services is not available in your context Cu.import("resource://gre/modules/Services.jsm");
var filehandler = Services.io.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
try{
return filehandler.getFileFromURLSpec(fileurispec);
}
catch(e){
return null;
}
}
getFileFromURIspec will return an instance of nsIFile, or null if the spec is invalid which shouldn't happen in this case but a sanity check never hurts. With that you can call the exists() method and if it returns false then the associated page entry in Places is eligible for removal. We can tell which is that page by its uri, which conveniently is also a property of each element of the results.
PlacesUtils.bhistory.removePage(result.uri);
To sum it up
var results = PlacesUtils.annotations.getAnnotationsWithName("downloads/destinationFileURI");
results.forEach(function(result){
var file = getFileFromURIspec(result.annotationValue);
if(!file){
// I don't know how you should treat this edge case
// ask the user, just log, remove, some combination?
}
else if(!file.exists()){
PlacesUtils.bhistory.removePage(result.uri);
}
});
I am developing a mobile application using phonegap, Initially I have developed using WEBSQL but now I m planning to move it on INDEXDB. The problem is it does not have direct support on IOS , so on doing much R&D I came to know using IndexedDB Polyfil we can implement it on IOS too
http://blog.nparashuram.com/2012/10/indexeddb-example-on-cordova-phonegap.html
http://nparashuram.com/IndexedDBShim/
Can some please help me how to implement this as there are not enough documentation for this and I cannot figure out a any other solution / api except this
I have tested this on safari 5.1.7
Below is my code and Error Image
var request1 = indexedDB.open(dbName, 5);
request1.onsuccess = function (evt) {
db = request1.result;
var transaction = db.transaction(["AcceptedOrders"], "readwrite");
var objectStore = transaction.objectStore("AcceptedOrders");
for (var i in data) {
var request = objectStore.add(data[i]);
request.onsuccess = function (event) {
// alert("am again inserted")
// event.target.result == customerData[i].ssn;
};
}
};
request1.onerror = function (evt) {
alert("IndexedDB error: " + evt.target.errorCode);
};
Error Image
One blind guess
Maybe your dbName contains illegal characters for WebSQL database names. The polyfill doesn't translate your database names in any kind. So if you create a database called my-test, it would try to create a WebSQL database with the name my-test. This name is acceptable for an IndexedDB database, but in WebSQL you'll get in trouble because of the - character. So your database name has to match both, the IndexedDB and the WebSQL name conventions.
... otherwise use the debugger
You could set a break point onto your alert(...); line and use the debugger to look inside the evt object. This way you may get either more information about the error itself or more information to share with us.
To do so, enable the development menu in the Safari advanced settings, hit F10 and go to Developer > Start debugging JavaScript (something like that, my Safari is in a different language). Now open then "Scripts" tab in the developer window, select your script and set the break point by clicking on the line number. Reload the page and it should stop right in your error callback, where you can inspect the evt object.
If this doesn't help, you could get the non-minified version of the polyfill and try set some breakpoints around their open function to find the origin of this error.
You could try my open source library https://bitbucket.org/ytkyaw/ydn-db/wiki/Home. It works on iOS and Android.