Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Shortcut and Menu events don't pass the same items #302

Closed
2 tasks done
garth74 opened this issue Mar 29, 2024 · 2 comments
Closed
2 tasks done

[Bug] Shortcut and Menu events don't pass the same items #302

garth74 opened this issue Mar 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@garth74
Copy link

garth74 commented Mar 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Are you using the latest Zotero and the latest plugin?

  • I have confirmed I'm using the latest Zotero and the latest plugin

Environment

  • OS: Mac - Sonoma 14.4 (23E214)
  • Zotero Version: 7.0.0-beta.68+c31a40c74
  • Plugin Version: 1.0.0-beta.36

Describe the bug

When the menu triggers scripts, the item isn't the same as when a shortcut triggers scripts. First described here.

I think the difference is from changes in the Zotero reader.js that may have changed the value of reader._item.

In order to fix it, I think the reader case in the items.ts needs to be changed. I think it may just be a matter of accessing and fetching the selected annotations, but I could be wrong.

async function getCurrentItems(type?: ActionShowInMenu) {
  let items = [] as Zotero.Item[];
  if (!type || type === "tools") {
    type = getCurrentTargetType();
  }
  switch (type) {
    case "item": {
      items = Zotero.getActiveZoteroPane().getSelectedItems();
      break;
    }
    case "collection": {
      const collection = Zotero.getActiveZoteroPane().getSelectedCollection();
      if (collection) {
        items = collection?.getChildItems() as Zotero.Item[];
      } else {
        const libraryID = Zotero.getActiveZoteroPane().getSelectedLibraryID();
        if (libraryID) {
          items = await Zotero.Items.getAll(libraryID);
        }
      }
      break;
    }
    case "reader": {
      const reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
      if (reader) {
        const annotationIDs = reader._state.selectedAnnotationIDs
        if (annotationIDs) {
            items = Zotero.Items.get(annotationIDs);
        }
      }
      break;
    }
  }
  return items;
}

Debug Output

1711750940531 addons.xpi WARN Checking /Applications/Zotero.app/Contents/Resources/distribution/extensions for addons

[JavaScript Error: "NS_NOINTERFACE: " {file: "resource://gre/modules/ComponentUtils.jsm" line: 90}]
createInstance@resource://gre/modules/ComponentUtils.jsm:90:36

1711750941194 addons.xpi WARN Addon with ID undefined already installed, older version will be disabled

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1710}]

[JavaScript Error: "Error: Addon must include an id, version, and type" {file: "resource://gre/modules/addons/XPIProvider.jsm" line: 1710}]

[JavaScript Error: "uncaught exception: undefined"]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NS_ERROR_FAILURE: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsITelemetry.getHistogramById]" {file: "resource://gre/modules/TerminatorTelemetry.jsm" line: 87}]

[JavaScript Error: "NotFoundError: Could not get children of file(/Users/garrettshipley/Library/Application Support/Zotero/Crash Reports/events) because it does not exist" {file: "resource://gre/modules/CrashManager.jsm" line: 682}]
_getUnprocessedEventsFiles/<@resource://gre/modules/CrashManager.jsm:682:12

appName => Zotero, version => 7.0.0-beta.68+c31a40c74, os => macOS 14.4, locale => en-US, extensions => Actions and Tags for Zotero (1.0.0-beta.36, extension), Zotero Debug Bridge (2.0.0, extension, disabled), Better BibTex for Zotero (6.7.172, extension, disabled)

(3)(+0018099): Getting contents of /Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js

(4)(+0000005): Beginning DB transaction mzam5nDT

(4)(+0000001): Committed DB transaction mzam5nDT

(3)(+0000000): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"// Only execute once for all selected items\nif (item) return;\n\nlet path = "/Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js";\nlet script_text = await Zotero.File.getContentsAsync(path);\neval(script_text)\nreturn await copyLink(items[0], collection);\n","shortcut":"⌘,⌥,ç","enabled":true,"menu":"[Copy] Item Link","name":"[Copy] Item Link","showInMenu":{"item":true,"collection":true,"tools":true,"reader":true,"readerAnnotation":true}} {"itemIDs":[4578],"triggerType":"menu"}

(4)(+0000003): Beginning DB transaction LQVYvXUu

(4)(+0000001): Item 4578 has not changed

(4)(+0000000): Committed DB transaction LQVYvXUu

(3)(+0000001): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"// Only execute once for all selected items\nif (item) return;\n\nlet path = "/Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js";\nlet script_text = await Zotero.File.getContentsAsync(path);\neval(script_text)\nreturn await copyLink(items[0], collection);\n","shortcut":"⌘,⌥,ç","enabled":true,"menu":"[Copy] Item Link","name":"[Copy] Item Link","showInMenu":{"item":true,"collection":true,"tools":true,"reader":true,"readerAnnotation":true}} {"itemID":4578,"triggerType":"menu"}

(3)(+0002999): [Actions and Tags for Zotero] undefined

(3)(+0000002): [Actions and Tags for Zotero] undefined

(3)(+0000002): [Actions and Tags for Zotero] undefined

(3)(+0000001): [Actions and Tags for Zotero] undefined

(3)(+0000479): [Actions and Tags for Zotero] undefined

(3)(+0000001): [Actions and Tags for Zotero] undefined

(3)(+0000418): [Actions and Tags for Zotero] ⌘,⌥,ç

(3)(+0000003): Getting contents of /Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js

(4)(+0000005): Beginning DB transaction GASAjRYD

(4)(+0000003): Committed DB transaction GASAjRYD

(3)(+0000001): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"// Only execute once for all selected items\nif (item) return;\n\nlet path = "/Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js";\nlet script_text = await Zotero.File.getContentsAsync(path);\neval(script_text)\nreturn await copyLink(items[0], collection);\n","shortcut":"⌘,⌥,ç","enabled":true,"menu":"[Copy] Item Link","name":"[Copy] Item Link","showInMenu":{"item":true,"collection":true,"tools":true,"reader":true,"readerAnnotation":true}} {"itemIDs":[4567],"triggerType":"shortcut"}

(4)(+0000004): Beginning DB transaction G7AEilSM

(4)(+0000013): Item 4567 has not changed

(4)(+0000004): Committed DB transaction G7AEilSM

(3)(+0000000): [Actions and Tags for Zotero] applyAction {"event":0,"operation":4,"data":"// Only execute once for all selected items\nif (item) return;\n\nlet path = "/Users/garrettshipley/Dropbox/github/zotero-scripts/copyLink.js";\nlet script_text = await Zotero.File.getContentsAsync(path);\neval(script_text)\nreturn await copyLink(items[0], collection);\n","shortcut":"⌘,⌥,ç","enabled":true,"menu":"[Copy] Item Link","name":"[Copy] Item Link","showInMenu":{"item":true,"collection":true,"tools":true,"reader":true,"readerAnnotation":true}} {"itemID":4567,"triggerType":"shortcut"}

(3)(+0056589): Checking for unprocessed full-text content

(4)(+0000002): SELECT itemID FROM fulltextItems WHERE synced=2

(3)(+0000002): No unprocessed full-text content found

(3)(+0000001): Unregistering full-text content processor idle observer

(3)(+0000000): Stopping full-text content processor

(3)(+0170799): HTTP POST "1711750940531 addons.xpi WARN …" (5698 chars) to https://repo.zotero.org/repo/report?debug=1

(3)(+0000009): POST body gzipped from 5698 to 1382; 76% savings

(3)(+0000694): HTTP POST https://repo.zotero.org/repo/report?debug=1 succeeded with 200

Anything else?

No response

@garth74 garth74 added the bug Something isn't working label Mar 29, 2024
@windingwind
Copy link
Owner

Thanks! Please try v1.0.0-beta.37

@garth74
Copy link
Author

garth74 commented Mar 30, 2024

You rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants