Skip to content

Commit

Permalink
Merge branch 'master' into gh-3094
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Jan 22, 2025
2 parents e0b9405 + df837b5 commit c107e50
Show file tree
Hide file tree
Showing 103 changed files with 4,447 additions and 4,111 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,21 @@ jobs:
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package-lock.json')
}}-${{ hashFiles('requirements.txt') }}

- name: Set system-wide proxy using PAC URL
run: |
echo "auto_proxy=http://proxy-doc.ird.fr/proxy.pac" | sudo tee -a /etc/environment
echo "auto_proxy=http://proxy-doc.ird.fr/proxy.pac" >> $GITHUB_ENV
- name: Verify proxy settings
run: env | grep -i proxy

- name: install ${{ matrix.client }}
run: |
curl -sL https://raw.githubusercontent.com/retorquere/zotero-deb/master/install.sh | sudo bash
sudo apt-get update
sudo apt-get install ${{ matrix.client }}
sudo apt-get install mesa-utils libegl1-mesa xvfb
sudo apt-get install mesa-utils xvfb
sudo apt-get install wmctrl xdotool
curl -LO https://github.com/jgm/pandoc/releases/download/3.1.11.1/pandoc-3.1.11.1-linux-amd64.tar.gz
tar xvzf pandoc-3.1.11.1-linux-amd64.tar.gz
sudo mv pandoc-3.1.11.1/bin/pandoc /usr/bin
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/src/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,21 @@ jobs:
- *install_python_packages
- *cache

- name: Set system-wide proxy using PAC URL
run: |
echo "auto_proxy=http://proxy-doc.ird.fr/proxy.pac" | sudo tee -a /etc/environment
echo "auto_proxy=http://proxy-doc.ird.fr/proxy.pac" >> $GITHUB_ENV
- name: Verify proxy settings
run: env | grep -i proxy

- name: install ${{ matrix.client }}
run: |
curl -sL https://raw.githubusercontent.com/retorquere/zotero-deb/master/install.sh | sudo bash
sudo apt-get update
sudo apt-get install ${{ matrix.client }}
sudo apt-get install mesa-utils libegl1-mesa xvfb
sudo apt-get install mesa-utils xvfb
sudo apt-get install wmctrl xdotool
curl -LO https://github.com/jgm/pandoc/releases/download/3.1.11.1/pandoc-3.1.11.1-linux-amd64.tar.gz
tar xvzf pandoc-3.1.11.1-linux-amd64.tar.gz
sudo mv pandoc-3.1.11.1/bin/pandoc /usr/bin
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# PSA: Zotero 6 support is ending

I am in the process of switching BBT to Zotero 7 exclusively. It is no longer feasible for me to maintain compatibility across 6 and 7. A 6-compatible build remains available, and I might do emergency fixes on it depending on the case at hand, but new work will be 7-only.

# Better BibTeX for Zotero

[![Join the chat at https://gitter.im/retorquere/zotero-better-bibtex](https://badges.gitter.im/retorquere/zotero-better-bibtex.svg)](https://gitter.im/retorquere/zotero-better-bibtex?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Greenkeeper badge](https://badges.greenkeeper.io/retorquere/zotero-better-bibtex.svg)](https://greenkeeper.io/)
Expand All @@ -6,7 +10,7 @@ Better BibTeX (BBT) is an extension for [Zotero](https://www.zotero.org) and [Ju

## Zotero 7 support

Better BibTeX is mostly compatible with the Zotero 7 beta; I am awaiting a change by the Zotero team to get to complete support. You can find the status of Zotero 7 support in the first post of [#2522](https://github.com/retorquere/zotero-better-bibtex/issues/2522); if you find new problems (which are not still marked as unresolved in that top post), please report them as *new* issues, not by commenting on #2522.
I have begun the process of deprecating Zotero 6 support. I'm still putting the infrastructure for than in place, but as of now, only Zotero7 and Zotero7 beta get new functionality, and Zotero 6 support (available at https://github.com/retorquere/zotero-better-bibtex/releases/tag/v6.7.267) is in maintenance mode.

## Juris-M support

Expand All @@ -28,7 +32,7 @@ in your items that Bib(La)TeX won't understand.

* BBT will convert from/to HTML/LaTeX:

- `<i>...</i>`&#8660;`\emph{...}`/`\textit{...}`
- `<i>...</i>`&#8660;`\emph{...}`/`\mkbibemph{...}`/`\textit{...}`
- `<b>...</b>`&#8660;`\textbf{...}`
- `<sup>...</sup>`&#8660;`\textsuperscript{...}` and `<sub>...</sub>`&#8660;`\textsubscript{...}`.

Expand Down
3 changes: 1 addition & 2 deletions content/ErrorReport.pug
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ wizard#better-bibtex-error-report(
tooltip#better-bibtex-error-report-info &better-bibtex_error-report_review;
textbox#better-bibtex-report-current.plain(flex='1' readonly='true')
textbox#better-bibtex-report-latest.plain.textbox-emph(flex='1' readonly='true')
textbox#better-bibtex-report-oom.plain.textbox-emph(hidden='true' flex='1' multiline='true' readonly='true' value='&better-bibtex_error-report_better-bibtex_oom.value;')
textbox#better-bibtex-report-cache.plain(flex='1' readonly='true')
checkbox.better-bibtex-error-report-facet#better-bibtex-error-report-include-errors(label='&better-bibtex_error-report_include-errors.label;')/
checkbox.better-bibtex-error-report-facet#better-bibtex-error-report-include-log(label='&better-bibtex_error-report_include-log.label;')/
Expand Down Expand Up @@ -67,5 +66,5 @@ wizard#better-bibtex-error-report(
script(src='chrome://zotero/content/include.js')
script.
window.addEventListener('load', function() {
(new Zotero.BetterBibTeX.ErrorReport).load(window).catch(err => Zotero.debug(`BBT.ErrorReport: error: ${err}`))
Zotero.BetterBibTeX.ErrorReport.load(window).catch(err => Zotero.debug(`BBT.ErrorReport: error: ${err}`))
})
117 changes: 83 additions & 34 deletions content/ErrorReport.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
Components.utils.import('resource://gre/modules/Services.jsm')

import * as client from './client'

import { Shim } from './os'
const $OS = client.is7 ? Shim : OS
import { Path, File } from './file'

import { Cache } from './db/cache'
import { PromptService } from './prompt'
// import { regex as escapeRE } from './escape'
import { regex as escapeRE } from './escape'

import { Preference } from './prefs'

Expand All @@ -19,7 +14,7 @@ import { log } from './logger'
import { AutoExport } from './auto-export'
import { KeyManager } from './key-manager'

import { pick } from './file-picker'
import { FilePickerHelper } from 'zotero-plugin-toolkit'
import * as l10n from './l10n'

import * as UZip from 'uzip'
Expand All @@ -28,8 +23,6 @@ import { alert } from './prompt'

import * as s3 from './s3.json'

import * as PACKAGE from '../package.json'

const kB = 1024

type WizardButton = HTMLElement & { disabled: boolean }
Expand All @@ -53,8 +46,7 @@ type Report = {
cache?: string
}

// const homeDir = $OS.Constants.Path.homeDir
// const $home = new RegExp(`${escapeRE(homeDir)}|${escapeRE(homeDir.replace(Zotero.isWin ? /\\/g : /\//g, '$1$1'))}|${escapeRE($OS.Path.toFileURI(homeDir))}`, 'g')
const $home = new RegExp(`${escapeRE(Path.home)}|${escapeRE(Path.home.replace(Zotero.isWin ? /\\/g : /\//g, '$1$1'))}|${escapeRE(PathUtils.toFileURI(Path.home))}`, 'g')

export class ErrorReport {
private previewSize = 3
Expand Down Expand Up @@ -102,7 +94,7 @@ export class ErrorReport {
wizard.advance();

// eslint-disable-next-line no-magic-numbers
(<HTMLInputElement> this.document.getElementById('better-bibtex-report-id')).value = `${ this.name() }/${ version }-${ client.is7 ? 7 : 6 }${ Zotero.BetterBibTeX.outOfMemory ? '/oom' : '' }`
(<HTMLInputElement> this.document.getElementById('better-bibtex-report-id')).value = `${ this.name() }/${version}`
this.document.getElementById('better-bibtex-report-result').hidden = false
}
catch (err) {
Expand All @@ -122,28 +114,28 @@ export class ErrorReport {
}

public restartWithDebugEnabled(): void {
const buttonFlags = PromptService.BUTTON_POS_0 * PromptService.BUTTON_TITLE_IS_STRING
+ PromptService.BUTTON_POS_1 * PromptService.BUTTON_TITLE_CANCEL
+ PromptService.BUTTON_POS_2 * PromptService.BUTTON_TITLE_IS_STRING
const index = PromptService.confirmEx(
const buttonFlags = Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_IS_STRING
+ Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_CANCEL
+ Services.prompt.BUTTON_POS_2 * Services.prompt.BUTTON_TITLE_IS_STRING
const index = Services.prompt.confirmEx(
null,
Zotero.getString('zotero.debugOutputLogging'),
Zotero.getString('zotero.debugOutputLogging.enabledAfterRestart', [Zotero.clientName]),
buttonFlags,
Zotero.getString('general.restartNow'),
null, Zotero.getString('general.restartLater'), null, {}
null, Zotero.getString('general.restartLater'), null, { value: false }
)

if (index !== 1) Zotero.Prefs.set('debug.store', true)

if (index === 0) Zotero.Utilities.Internal.quit(true)
}

private async latest() {
private async latest(): Promise<string> {
try {
const latest = PACKAGE.xpi.releaseURL.replace('https://github.com/', 'https://api.github.com/repos/').replace(/\/releases\/.*/, '/releases/latest')
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse((await Zotero.HTTP.request('GET', latest, { noCache: true })).response).tag_name.replace('v', '')
const latest = JSON.parse((await Zotero.HTTP.request('GET', 'https://github.com/retorquere/zotero-better-bibtex/releases/download/release/updates.json', { noCache: true })).response)
return latest.addons['[email protected]'].updates[0].version as string
}
catch (err) {
log.error('errorreport.latest:', err)
Expand All @@ -169,8 +161,8 @@ export class ErrorReport {
}

public async save(): Promise<void> {
const filename = await pick('Logs', 'save', [[ 'Zip Archive (*.zip)', '*.zip' ]], `${ this.name() }.zip`)
if (filename) await $OS.File.writeAtomic(filename, this.zip(), { tmpPath: filename + '.tmp' })
const filename = await new FilePickerHelper('Logs', 'save', [[ 'Zip Archive (*.zip)', '*.zip' ]], `${this.name()}.zip`).open()
if (filename) await IOUtils.write(filename, this.zip(), { tmpPath: filename + '.tmp' })
}

private async ping(region: string) {
Expand Down Expand Up @@ -206,12 +198,12 @@ export class ErrorReport {
/protocol is not allowed for attachments/,
].map(re => re.source).join('|'))
return logging.filter(line => !line.match(ignore))
// .map(line => line.replace($home, '$HOME'))
.map(line => line.replace($home, '$HOME'))
.join('\n')
}

private errors(): string {
return this.scrub(Zotero.getErrors(true) as string[])
return this.scrub(Zotero.getErrors(true))
}

private log(): string {
Expand Down Expand Up @@ -353,14 +345,14 @@ export class ErrorReport {
}
this.input = {
context: await this.context(),
errors: `${ Zotero.BetterBibTeX.outOfMemory }\n${ this.errors() }`.trim(),
errors: this.errors(),
// # 1896
log: this.log(),
items: win.arguments[0].wrappedJSObject.items,
cache,
}
const acronyms = $OS.Path.join(Zotero.BetterBibTeX.dir, 'acronyms.csv')
if (await $OS.File.exists(acronyms)) this.input.acronyms = await $OS.File.read(acronyms, { encoding: 'utf-8' }) as unknown as string
const acronyms = PathUtils.join(Zotero.BetterBibTeX.dir, 'acronyms.csv')
if (await File.exists(acronyms)) this.input.acronyms = await IOUtils.readUTF8(acronyms)

await this.reload()

Expand All @@ -379,8 +371,7 @@ export class ErrorReport {
show_latest.hidden = false
}

(<HTMLInputElement> this.document.getElementById('better-bibtex-report-oom')).hidden = !Zotero.BetterBibTeX.outOfMemory

// @ts-expect-error zotero-types does not export .any
this.region = await Zotero.Promise.any(Object.keys(s3.region).map(this.ping.bind(this)))
this.bucket = `https://${ s3.bucket }-${ this.region.short }.s3-${ this.region.region }.amazonaws.com${ this.region.tld || '' }`
this.key = Zotero.Utilities.generateObjectKey()
Expand Down Expand Up @@ -434,7 +425,12 @@ export class ErrorReport {
context += 'Settings:\n'
const settings = { default: '', set: '' }
for (const [ key, value ] of Object.entries(Preference.all)) {
settings[value === defaults[key] ? 'default' : 'set'] += ` ${ key } = ${ JSON.stringify(value) }\n`
if (value === defaults[key]) {
settings.default += ` ${key} = ${ JSON.stringify(value) }\n`
}
else {
settings.set += ` ${key} = ${JSON.stringify(value)} (default: ${JSON.stringify(defaults[key])})\n`
}
}
if (settings.default) settings.default = `Settings at default:\n${ settings.default }`
context += settings.set + settings.default
Expand All @@ -447,14 +443,16 @@ export class ErrorReport {
if (autoExports.length) {
context += 'Auto-exports:\n'
for (const ae of autoExports) {
context += ` path: ...${ JSON.stringify($OS.Path.split(ae.path).components.pop()) }`
context += ` path: ...${JSON.stringify(Path.basename(ae.path))}`
switch (ae.type) {
case 'collection':
context += ` (${ Zotero.Collections.get(ae.id)?.name || '<collection>' })`
break
case 'library':
context += ` (${ Zotero.Libraries.get(ae.id)?.name || '<library>' })`
case 'library': {
const lib = Zotero.Libraries.get(ae.id)
context += ` (${(lib ? lib.name : '') || '<library>'})`
break
}
}
context += '\n'
for (const [ k, v ] of Object.entries(ae)) {
Expand All @@ -471,4 +469,55 @@ export class ErrorReport {

return context
}

public async open(items?: string): Promise<void> {
const selection = async () => {
let scope = null
const zp = Zotero.getActiveZoteroPane()
switch (items) {
case 'collection':
case 'library':
scope = { type: 'collection', collection: zp.getSelectedCollection() }
if (!scope.collection) scope = { type: 'library', id: zp.getSelectedLibraryID() }
break

case 'items':
try {
scope = { type: 'items', items: zp.getSelectedItems() }
}
catch (err) { // ZoteroPane.getSelectedItems() doesn't test whether there's a selection and errors out if not
log.error('Could not get selected items:', err)
}
}

if (!scope) return ''

try {
return await Zotero.BetterBibTeX.Translators.queueJob({
translatorID: Zotero.BetterBibTeX.Translators.bySlug.BetterBibTeXJSON.translatorID,
displayOptions: { worker: true, exportNotes: true, dropAttachments: true, Normalize: true },
scope,
timeout: 40,
})
}
catch (err) {
if (err.timeout) {
log.error('errorreport: items timed out after', err.timeout, 'seconds')
return 'Timeout retrieving items'
}
else {
log.error('errorreport: could not get items', err)
return `Error retrieving items: ${ err }`
}
}
}

items = items ? await selection() : ''

Zotero.getMainWindow().openDialog(
'chrome://zotero-better-bibtex/content/ErrorReport.xhtml',
'better-bibtex-error-report',
'chrome,centerscreen,modal',
{ wrappedJSObject: { items }})
}
}
Loading

0 comments on commit c107e50

Please sign in to comment.