Copy link to clipboard
Copied
Hi,
Can anyone show a basic example of writing and reading cookies values for the panel?
I want to store the user settings and i could not find any example for it, though I ma still searching.
Thank you,
Check below snippets. It might help your work.
...//Set session cookie
document.cookie = "testCookie="+"testStrings"; //Key and Value
//Set persistent cookie
var dt = new Date();
dt.setTime(dt.getTime() + (30*24*60*60*1000));
var ce = "; expires=" + dt.toGMTString(); //persistent cookie needs expires time
var val = "persistentCookie="+"testStrings";
document.cookie = val + ce;
//Get cookies
alert(document.cookie);
//Set and Get localstorage
localStorage.setItem('storageTestKey', "StringFromLocalStorage");
loca
Copy link to clipboard
Copied
We're using a jquery extension "jquery cookie". Makes setting a cookie easier.
Set the cookie:
var myVar = "something";
$.cookie("xyz", myVar, { path: '/', expires: 365})
Remove the cookie:
$.cookie("xyz", "",{ path: '/', expires: -1})
Thomas
Copy link to clipboard
Copied
Thank,
Do i define the path for the cookie?
If yes, is it: "C:\Users\<USERNAME>\AppData\Local\Temp\cep_cache\"?
On this page:
it says, regarding cookie location:
C:\Users\<USERNAME>\AppData\Local\Temp\cep_cache\
/Users/<USERNAME>/Library/Caches/CSXS/cep_cache/
Each persistent cookie is a file. File name is HostID_HostVersion_ExtensionName, such as PHXS_15.0.0_com.adobe.extension1.
Copy link to clipboard
Copied
Yes, this is where the cookie is technically stored but this doesn't matter for the creation of the cookie. CEP takes care of storing it in the right file.
The 'path' attribute signifies the URL or path for which the cookie is valid. The default path attribute is set as '/'. This is not the path where the cookie is physically stored. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
Copy link to clipboard
Copied
Thanks,
Is there by any chance a function which stores/restores all required user input field?
Copy link to clipboard
Copied
Which event is triggered by closing the panel?
I want to run a function which saves the session cookies when the panel is closed.
Copy link to clipboard
Copied
Check below snippets. It might help your work.
//Set session cookie
document.cookie = "testCookie="+"testStrings"; //Key and Value
//Set persistent cookie
var dt = new Date();
dt.setTime(dt.getTime() + (30*24*60*60*1000));
var ce = "; expires=" + dt.toGMTString(); //persistent cookie needs expires time
var val = "persistentCookie="+"testStrings";
document.cookie = val + ce;
//Get cookies
alert(document.cookie);
//Set and Get localstorage
localStorage.setItem('storageTestKey', "StringFromLocalStorage");
localStorage.getItem('storageTestKey');
Copy link to clipboard
Copied
Do you know how to save settings when i collapse the panel?
I tried
new csInterface.addEventListener("com.adobe.csxs.events.ExtensionUnloaded", function(event) { ...
But it did not help, or i did not use it properly.
I searched for this and could not understand whether it is possible to detect when the panel is collapsed or not.
Dan
Copy link to clipboard
Copied
What app are you targeting?
Do you want to keep panel contents until application quit?
Copy link to clipboard
Copied
I am using Photoshop and i want to keep the settings even when Photoshop restarts.
Copy link to clipboard
Copied
If you want to keep contents until close Photoshop app, set persistent event when your extension initializes.
var csi = new CSInterface();
var event = new CSEvent("com.adobe.PhotoshopPersistent", "APPLICATION");
event.extensionId = csi.getExtensionID(); //csInterface define outside function(global).
csi.dispatchEvent(event);
Photoshop doesn't support "applicationBeforeQuit" event. Therefore you need to save each time when your form changed.
Copy link to clipboard
Copied
Thank you,
If that means that it will be saved each time the form changes, as you suggest, then i'll attach the save cookies to my main action button.
Copy link to clipboard
Copied
I think localStorage is better to use.
Here is an example:
HTML form
<input type="text" name="txt" value="Hello" onchange="storeLocal(this.value)">
JavaScript/ When Text field changed...
function storeLocal (val) {
localStorage.setItem('formTxt', val);
}
Run once, when Extension loaded...n once, when Extension loaded.
function init() {
document.getElementById("txt").value = localStorage.getItem('formTxt');
}
Copy link to clipboard
Copied
Tried this and get this error in return
Uncaught TypeError: Cannot set property 'value' of null
EDIT
Quick Googked helped, the input has no ID so i added an id. Now works indeed. But it only works when that get is on the index page, not when i add it to main.js file which has all the code for the panel. Than i get an error again about value. This is nice.
Still wonder then how that cep_cache works and different this is or what we can do with that. I know regular scripts can write some sort of cache so its read back when dialog windows show. So much to learn.... not so much time
Edit 2
well not sure what happened, but it does work from main.js i guess it i didn't do a refresh. can we also store a son file locally or so. I guess using that for settings is easier.
Copy link to clipboard
Copied
Mopved from D&I to Exchange to hopefully get an answer
Copy link to clipboard
Copied
Can i ask where this is stored? I get the popup but i don't see cep_cache folder appear. Ive also enabled --persist-session-cookies in the manifest
```