pi-chrome 0.15.43 → 0.15.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Pi Chrome Connector",
4
- "version": "0.15.43",
4
+ "version": "0.15.44",
5
5
  "description": "Lets Pi control tabs in Chrome via a local connector at 127.0.0.1.",
6
6
  "permissions": [
7
7
  "tabs",
@@ -718,15 +718,40 @@ export default function (pi: ExtensionAPI): void {
718
718
  countdownInterval = undefined;
719
719
  };
720
720
 
721
- const activeToolNamesWithoutChrome = (): string[] => pi.getActiveTools().filter((name) => !CHROME_TOOL_NAME_SET.has(name));
721
+ const chromeToolsActive = (tools = pi.getActiveTools()): boolean => tools.some((name) => CHROME_TOOL_NAME_SET.has(name));
722
722
 
723
- const activateChromeTools = (): void => {
723
+ const activateChromeTools = (): boolean => {
724
724
  registerChromeTools(pi);
725
- pi.setActiveTools([...new Set([...pi.getActiveTools(), ...CHROME_TOOL_NAMES])]);
725
+ const before = pi.getActiveTools();
726
+ const next = [...new Set([...before, ...CHROME_TOOL_NAMES])];
727
+ pi.setActiveTools(next);
728
+ return !chromeToolsActive(before) && chromeToolsActive(next);
726
729
  };
727
730
 
728
- const deactivateChromeTools = (): void => {
729
- pi.setActiveTools(activeToolNamesWithoutChrome());
731
+ const deactivateChromeTools = (): boolean => {
732
+ const before = pi.getActiveTools();
733
+ pi.setActiveTools(before.filter((name) => !CHROME_TOOL_NAME_SET.has(name)));
734
+ return chromeToolsActive(before);
735
+ };
736
+
737
+ const logChromeToolChange = (action: "authorized" | "revoked" | "expired", label?: string): void => {
738
+ const enabled = action === "authorized";
739
+ const content = enabled
740
+ ? `Chrome tools enabled by /chrome authorize${label ? ` (${label})` : ""}.`
741
+ : action === "expired"
742
+ ? "Chrome tools disabled because /chrome authorize grant expired."
743
+ : "Chrome tools disabled by /chrome revoke.";
744
+ pi.sendMessage({
745
+ customType: "pi-chrome-tool-change",
746
+ content,
747
+ display: true,
748
+ details: {
749
+ action,
750
+ tools: [...CHROME_TOOL_NAMES],
751
+ authorizedUntil: chromeAuthorizedUntil,
752
+ at: Date.now(),
753
+ },
754
+ }, { triggerTurn: false });
730
755
  };
731
756
 
732
757
  // Close THIS session's dedicated automation window/tab. Fire-and-forget and best-effort: it
@@ -738,12 +763,13 @@ export default function (pi: ExtensionAPI): void {
738
763
  void bridge.send("automation.cleanup", sessionKey !== undefined ? { sessionKey } : {}, 3_000).catch(() => undefined);
739
764
  };
740
765
 
741
- const lockChromeControl = (): void => {
766
+ const lockChromeControl = (logAction?: "revoked" | "expired"): void => {
742
767
  clearAuthExpiryTimer();
743
768
  clearCountdownInterval();
769
+ const hadChromeTools = deactivateChromeTools();
770
+ if (logAction && hadChromeTools) logChromeToolChange(logAction);
744
771
  chromeAuthorizedUntil = undefined;
745
772
  persistAuth();
746
- deactivateChromeTools();
747
773
  // Revoking control ends pi-chrome's automation for this session; tidy up the target we own.
748
774
  cleanupAutomationTargetBestEffort();
749
775
  };
@@ -760,7 +786,7 @@ export default function (pi: ExtensionAPI): void {
760
786
  const chromeControlAuthorized = (): boolean => {
761
787
  if (chromeAuthorizedUntil === "indefinite") return true;
762
788
  if (typeof chromeAuthorizedUntil === "number" && chromeAuthorizedUntil > Date.now()) return true;
763
- if (chromeAuthorizedUntil !== undefined) lockChromeControl();
789
+ if (chromeAuthorizedUntil !== undefined) lockChromeControl("expired");
764
790
  return false;
765
791
  };
766
792
 
@@ -827,7 +853,7 @@ export default function (pi: ExtensionAPI): void {
827
853
  authExpiryTimer = setTimeout(() => {
828
854
  if (chromeAuthorizedUntil !== until) return;
829
855
  try {
830
- lockChromeControl();
856
+ lockChromeControl("expired");
831
857
  ctx.ui.notify("Chrome control authorization expired. Run /chrome authorize to allow chrome_* tools again.", "info");
832
858
  updateChromeStatus(ctx);
833
859
  } catch (error) {
@@ -1040,6 +1066,7 @@ Usage rules:
1040
1066
  chromeAuthorizedUntil = until;
1041
1067
  persistAuth();
1042
1068
  activateChromeTools();
1069
+ logChromeToolChange("authorized", label);
1043
1070
  scheduleAuthExpiry(ctx, until);
1044
1071
  ctx.ui.notify(`Chrome control authorized for ${label}.`, "info");
1045
1072
  updateChromeStatus(ctx);
@@ -1063,7 +1090,7 @@ Usage rules:
1063
1090
  };
1064
1091
 
1065
1092
  const revokeHandler = (ctx: ExtensionContext) => {
1066
- lockChromeControl();
1093
+ lockChromeControl("revoked");
1067
1094
  ctx.ui.notify("Chrome control locked. Run /chrome authorize to allow chrome_* tools again.", "info");
1068
1095
  updateChromeStatus(ctx);
1069
1096
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-chrome",
3
- "version": "0.15.43",
3
+ "version": "0.15.44",
4
4
  "scripts": {
5
5
  "test": "node test-suite/unit/csp-eval.test.mjs && node test-suite/unit/automation-target.test.mjs",
6
6
  "version": "node scripts/sync-manifest-version.js",