Ensure the progress bar is hidden if session initialisation fails
This commit is contained in:
parent
e31d706ee4
commit
8b36f33513
|
@ -388,86 +388,91 @@ Zotero.Integration = new function() {
|
||||||
* @return {Zotero.Integration.Session} Promise
|
* @return {Zotero.Integration.Session} Promise
|
||||||
*/
|
*/
|
||||||
this.getSession = async function (app, doc, agent) {
|
this.getSession = async function (app, doc, agent) {
|
||||||
var progressBar = new Zotero.Integration.Progress(4, Zotero.isMac && agent != 'http');
|
|
||||||
progressBar.show();
|
|
||||||
|
|
||||||
var dataString = await doc.getDocumentData(),
|
|
||||||
data, session;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = new Zotero.Integration.DocumentData(dataString);
|
var progressBar = new Zotero.Integration.Progress(4, Zotero.isMac && agent != 'http');
|
||||||
} catch(e) {
|
progressBar.show();
|
||||||
data = new Zotero.Integration.DocumentData();
|
|
||||||
}
|
var dataString = await doc.getDocumentData(),
|
||||||
|
data, session;
|
||||||
if (data.prefs.fieldType) {
|
|
||||||
if (data.dataVersion < DATA_VERSION) {
|
try {
|
||||||
if (data.dataVersion == 1
|
data = new Zotero.Integration.DocumentData(dataString);
|
||||||
&& data.prefs.fieldType == "Field"
|
} catch(e) {
|
||||||
&& app.primaryFieldType == "ReferenceMark") {
|
data = new Zotero.Integration.DocumentData();
|
||||||
// Converted OOo docs use ReferenceMarks, not fields
|
|
||||||
data.prefs.fieldType = "ReferenceMark";
|
|
||||||
}
|
|
||||||
|
|
||||||
var warning = await doc.displayAlert(Zotero.getString("integration.upgradeWarning", [Zotero.clientName, '5.0']),
|
|
||||||
DIALOG_ICON_WARNING, DIALOG_BUTTONS_OK_CANCEL);
|
|
||||||
if (!warning) {
|
|
||||||
throw new Zotero.Exception.UserCancelled("document upgrade");
|
|
||||||
}
|
|
||||||
// Don't throw for version 4(JSON) during the transition from 4.0 to 5.0
|
|
||||||
} else if ((data.dataVersion > DATA_VERSION) && data.dataVersion != 4) {
|
|
||||||
throw new Zotero.Exception.Alert("integration.error.newerDocumentVersion",
|
|
||||||
[data.zoteroVersion, Zotero.version], "integration.error.title");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.prefs.fieldType !== app.primaryFieldType
|
if (data.prefs.fieldType) {
|
||||||
&& data.prefs.fieldType !== app.secondaryFieldType) {
|
if (data.dataVersion < DATA_VERSION) {
|
||||||
throw new Zotero.Exception.Alert("integration.error.fieldTypeMismatch",
|
if (data.dataVersion == 1
|
||||||
[], "integration.error.title");
|
&& data.prefs.fieldType == "Field"
|
||||||
|
&& app.primaryFieldType == "ReferenceMark") {
|
||||||
|
// Converted OOo docs use ReferenceMarks, not fields
|
||||||
|
data.prefs.fieldType = "ReferenceMark";
|
||||||
|
}
|
||||||
|
|
||||||
|
var warning = await doc.displayAlert(Zotero.getString("integration.upgradeWarning", [Zotero.clientName, '5.0']),
|
||||||
|
DIALOG_ICON_WARNING, DIALOG_BUTTONS_OK_CANCEL);
|
||||||
|
if (!warning) {
|
||||||
|
throw new Zotero.Exception.UserCancelled("document upgrade");
|
||||||
|
}
|
||||||
|
// Don't throw for version 4(JSON) during the transition from 4.0 to 5.0
|
||||||
|
} else if ((data.dataVersion > DATA_VERSION) && data.dataVersion != 4) {
|
||||||
|
throw new Zotero.Exception.Alert("integration.error.newerDocumentVersion",
|
||||||
|
[data.zoteroVersion, Zotero.version], "integration.error.title");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.prefs.fieldType !== app.primaryFieldType
|
||||||
|
&& data.prefs.fieldType !== app.secondaryFieldType) {
|
||||||
|
throw new Zotero.Exception.Alert("integration.error.fieldTypeMismatch",
|
||||||
|
[], "integration.error.title");
|
||||||
|
}
|
||||||
|
|
||||||
|
session = Zotero.Integration.sessions[data.sessionID];
|
||||||
}
|
}
|
||||||
|
if (!session) {
|
||||||
|
session = new Zotero.Integration.Session(doc, app);
|
||||||
|
session.reload = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await session.setData(data);
|
||||||
|
} catch(e) {
|
||||||
|
// make sure style is defined
|
||||||
|
if (e instanceof Zotero.Exception.Alert && e.name === "integration.error.invalidStyle") {
|
||||||
|
if (data.style.styleID) {
|
||||||
|
let trustedSource = /^https?:\/\/(www\.)?(zotero\.org|citationstyles\.org)/.test(data.style.styleID);
|
||||||
|
let errorString = Zotero.getString("integration.error.styleMissing", data.style.styleID);
|
||||||
|
if (trustedSource ||
|
||||||
|
await doc.displayAlert(errorString, DIALOG_ICON_WARNING, DIALOG_BUTTONS_YES_NO)) {
|
||||||
|
|
||||||
session = Zotero.Integration.sessions[data.sessionID];
|
let installed = false;
|
||||||
}
|
try {
|
||||||
if (!session) {
|
await Zotero.Styles.install(
|
||||||
session = new Zotero.Integration.Session(doc, app);
|
{url: data.style.styleID}, data.style.styleID, true
|
||||||
session.reload = true;
|
);
|
||||||
}
|
installed = true;
|
||||||
try {
|
}
|
||||||
await session.setData(data);
|
catch (e) {
|
||||||
} catch(e) {
|
await doc.displayAlert(
|
||||||
// make sure style is defined
|
Zotero.getString(
|
||||||
if (e instanceof Zotero.Exception.Alert && e.name === "integration.error.invalidStyle") {
|
'integration.error.styleNotFound', data.style.styleID
|
||||||
if (data.style.styleID) {
|
),
|
||||||
let trustedSource = /^https?:\/\/(www\.)?(zotero\.org|citationstyles\.org)/.test(data.style.styleID);
|
DIALOG_ICON_WARNING,
|
||||||
let errorString = Zotero.getString("integration.error.styleMissing", data.style.styleID);
|
DIALOG_BUTTONS_OK
|
||||||
if (trustedSource ||
|
);
|
||||||
await doc.displayAlert(errorString, DIALOG_ICON_WARNING, DIALOG_BUTTONS_YES_NO)) {
|
}
|
||||||
|
if (installed) {
|
||||||
let installed = false;
|
await session.setData(data, true);
|
||||||
try {
|
}
|
||||||
await Zotero.Styles.install(
|
|
||||||
{url: data.style.styleID}, data.style.styleID, true
|
|
||||||
);
|
|
||||||
installed = true;
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
await doc.displayAlert(
|
|
||||||
Zotero.getString(
|
|
||||||
'integration.error.styleNotFound', data.style.styleID
|
|
||||||
),
|
|
||||||
DIALOG_ICON_WARNING,
|
|
||||||
DIALOG_BUTTONS_OK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (installed) {
|
|
||||||
await session.setData(data, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await session.setDocPrefs();
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
await session.setDocPrefs();
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
progressBar.hide(true);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
session.agent = agent;
|
session.agent = agent;
|
||||||
session._doc = doc;
|
session._doc = doc;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user