Skip to content

Commit

Permalink
Added dropbox setting import export
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Oct 29, 2024
1 parent 9d04990 commit e1f1fd1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 9 deletions.
3 changes: 3 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Utils
var Filter;
var Image;
var Ai;
var Io;
var CryptoJS;
var Actions;
var Annotations;
Expand Down Expand Up @@ -267,6 +268,7 @@ async function startup({ id, version, resourceURI, rootURI = resourceURI.spec })
Services.scriptloader.loadSubScript(rootURI + 'core/data.js');
Services.scriptloader.loadSubScript(rootURI + 'core/format.js');
Services.scriptloader.loadSubScript(rootURI + 'core/ai.js');
Services.scriptloader.loadSubScript(rootURI + 'core/io.js');
Services.scriptloader.loadSubScript(rootURI + 'content/notes/actions.js');
Services.scriptloader.loadSubScript(rootURI + 'core/annotations.js');
Services.scriptloader.loadSubScript(rootURI + 'core/languages.js');
Expand Down Expand Up @@ -295,6 +297,7 @@ async function startup({ id, version, resourceURI, rootURI = resourceURI.spec })
ZeNotes.Filter = Filter;
ZeNotes.Image = Image;
ZeNotes.Ai = Ai;
ZeNotes.Io = Io;
ZeNotes.CryptoJS = CryptoJS;
ZeNotes.Actions = Actions;
ZeNotes.Annotations = Annotations;
Expand Down
2 changes: 2 additions & 0 deletions content/notes/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Io = {
Zotero.ZeNotes.Prefs.set("export-default-ext", fp.defaultExtension);
}
},

savebinary(file, url)
{
fetch(url)
Expand All @@ -75,6 +76,7 @@ Io = {
Zotero.File.putContentsAsync(file, blob);
});
},

assets(directory, files)
{
Zotero.File.createDirectoryIfMissingAsync(directory).then(()=>{
Expand Down
7 changes: 7 additions & 0 deletions content/settings/dropbox.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
<input id="zn-dropbox-ms-per-file" type="text" onchange="Zotero_Preferences.ZeNotes.setpreference(event, 'dropbox-ms-per-file');" style="width:100%;" placeholder="Time spent to export one item (in milliseconds)" title="This value depends on your computer. Adjust it as needed." />
</td>
</tr>
<tr>
<td>From file</td>
<td>
<button onclick="Zotero.ZeNotes.NSync.loadsettings();">Load from file ... </button>
<button onclick="Zotero.ZeNotes.NSync.exportsettings();">Export to file ... </button>
</td>
</tr>

</table>
</div>
31 changes: 31 additions & 0 deletions core/io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var { OS } = ChromeUtils.importESModule("chrome://zotero/content/osfile.mjs");
var { FilePicker } = ChromeUtils.importESModule('chrome://zotero/content/modules/filePicker.mjs');

Io = {
async savedialog(title, filter, extension, defaultstring, contents)
{
let fp = new FilePicker();
fp.init(window, title, fp.modeSave);
fp.appendFilter(filter, extension);
fp.defaultString = defaultstring;
var rv = await fp.show();
if(rv == fp.returnOK || rv == fp.returnReplace)
{
let outputFile = fp.file;
Zotero.File.putContentsAsync(outputFile, contents);
}
},
async loaddialog(title, filter, extension, defaultstring)
{
let fp = new FilePicker();
fp.init(window, title, fp.modeOpen);
fp.appendFilter(filter, extension);
fp.defaultString = defaultstring;
var rv = await fp.show();
if(rv == fp.returnOK)
{
let outputFile = fp.file;
return await Zotero.File.getContentsAsync("file:///"+outputFile);
}
}
}
44 changes: 44 additions & 0 deletions core/nsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,5 +355,49 @@ NSync = {
}
}
return true;
},

loadsettings()
{
let title = "Export Dropbox settings";
let filter = "ZeNotes Dropbox Settings (*.zdb)";
let extension = "*.zdb";
let defaultstring = "zenotes-dropbox-settings.zdb";
Zotero.ZeNotes.Io.loaddialog(title, filter, extension, defaultstring).then(settings=>{
try {
let s = JSON.parse(Zotero.ZeNotes.decrypt(settings));
if(!confirm("Do you want to import the settings for Dropbox?"))
{
return;
}

Zotero.ZeNotes.Prefs.setb('dropbox-access-token', s["dropbox-access-token"]);
Zotero.ZeNotes.Prefs.setb('dropbox-refresh-token', s["dropbox-refresh-token"]);
Zotero.ZeNotes.Prefs.setb('dropbox-client-id', s["dropbox-client-id"]);
Zotero.ZeNotes.Prefs.setb('dropbox-client-secret', s["dropbox-client-secret"]);
Zotero.ZeNotes.Prefs.set("dropbox-target-user", s["dropbox-target-user"]);
}
catch(e)
{
alert(e);
}
})
},

exportsettings()
{
let settings = Zotero.ZeNotes.encrypt(JSON.stringify(
{
"dropbox-access-token": Zotero.ZeNotes.Prefs.getb('dropbox-access-token', ''),
"dropbox-refresh-token": Zotero.ZeNotes.Prefs.getb('dropbox-refresh-token', ''),
"dropbox-client-id": Zotero.ZeNotes.Prefs.getb('dropbox-client-id', ''),
"dropbox-client-secret": Zotero.ZeNotes.Prefs.getb('dropbox-client-secret', ''),
"dropbox-target-user": Zotero.Prefs.get("extensions.zotero.sync.server.username", true)
}));
let title = "Export Dropbox settings";
let filter = "ZeNotes Dropbox Settings (*.zdb)";
let extension = "*.zdb";
let defaultstring = "zenotes-dropbox-settings.zdb";
Zotero.ZeNotes.Io.savedialog(title, filter, extension, defaultstring, settings);
}
}
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.9.4</em:version>
<em:version>0.9.5</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://github.com/frianasoa/Ze-Notes/releases/download/release/zenotes-update.rdf</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.9.4",
"version": "0.9.5",
"description": "Advanced notes manager",
"author": "Fanantenana Rianasoa Andriariniaina",
"homepage_url": "https://github.com/frianasoa/zenotes",
Expand All @@ -13,7 +13,7 @@
"zotero": {
"id": "[email protected]",
"update_url": "https://github.com/frianasoa/Ze-Notes/releases/download/release/zenotes-update.json",
"strict_min_version": "6.0",
"strict_min_version": "7.0.0-beta.70",
"strict_max_version": "7.0.*"
},
"gecko": {
Expand Down
6 changes: 3 additions & 3 deletions zenotes-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.9.4",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.4/zenotes-v0.9.4.xpi",
"update_hash": "sha512:d320b6a7b5c6f6357f67d1a7a8a052e043f85cf9ddb3313fc27c95d4e6984a9b106df7e9504a2cc288e2da14a75b5b783b78b4c98ce6b4759a3d58f9309e4b24",
"version": "0.9.5",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.5/zenotes-v0.9.5.xpi",
"update_hash": "sha512:7e1c7631c12b5dd9c1649527d4f1673baf03efe47529af97a29f3b0297771cf90a2587e14a8a7eccd7647ab90dec89363814ad7d9a83575a1021d16714b57dc0",
"applications": {
"gecko": {
"strict_min_version": "6.0",
Expand Down
6 changes: 3 additions & 3 deletions zenotes-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.9.4</ns1:version>
<ns1:version>0.9.5</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.4/zenotes-v0.9.4.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.5/zenotes-v0.9.5.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.4/zenotes-v0.9.4.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.9.5/zenotes-v0.9.5.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit e1f1fd1

Please sign in to comment.