update: hot reload without waiting
This commit is contained in:
		
							parent
							
								
									27c68b1167
								
							
						
					
					
						commit
						b2b490b191
					
				@ -225,11 +225,10 @@ When file changes are detected in `src` or `addon`, the plugin will be automatic
 | 
			
		||||
<details style="text-indent: 2em">
 | 
			
		||||
<summary>💡 Steps to add this feature to an existing plugin</summary>
 | 
			
		||||
 | 
			
		||||
1. Add `if (reason == ADDON_DISABLE) {Services.obs.notifyObservers(null, "startupcache-invalidate", null);}` to `shutdown()` in the `addon/bootstrap.js`
 | 
			
		||||
2. Copy `scripts/reload.mjs`
 | 
			
		||||
3. Copy `reload`, `watch`, and `start-watch` commands in `package.json`
 | 
			
		||||
4. Run `npm install --save-dev chokidar-cli`
 | 
			
		||||
5. Done.
 | 
			
		||||
1. Copy `scripts/reload.mjs`
 | 
			
		||||
2. Copy `reload`, `watch`, and `start-watch` commands in `package.json`
 | 
			
		||||
3. Run `npm install --save-dev chokidar-cli`
 | 
			
		||||
4. Done.
 | 
			
		||||
 | 
			
		||||
</details>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								addon/bootstrap.js
									
									
									
									
										vendored
									
									
								
							@ -106,9 +106,6 @@ function shutdown({ id, version, resourceURI, rootURI }, reason) {
 | 
			
		||||
  if (reason === APP_SHUTDOWN) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (reason == ADDON_DISABLE) {
 | 
			
		||||
    Services.obs.notifyObservers(null, "startupcache-invalidate", null);
 | 
			
		||||
  }
 | 
			
		||||
  if (typeof Zotero === "undefined") {
 | 
			
		||||
    Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
 | 
			
		||||
      Components.interfaces.nsISupports
 | 
			
		||||
 | 
			
		||||
@ -20,9 +20,7 @@ const script = `
 | 
			
		||||
(async () => {
 | 
			
		||||
  const { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 | 
			
		||||
  const addon = await AddonManager.getAddonByID("${addonID}");
 | 
			
		||||
  addon.disable();
 | 
			
		||||
  await Zotero.Promise.delay(1000);
 | 
			
		||||
  addon.enable();
 | 
			
		||||
  await addon.reload();
 | 
			
		||||
  const progressWindow = new Zotero.ProgressWindow({ closeOnClick: true });
 | 
			
		||||
  progressWindow.changeHeadline("${addonName} Hot Reload");
 | 
			
		||||
  progressWindow.progress = new progressWindow.ItemProgress(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user