pi-chrome 0.15.43 → 0.15.45
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.
|
@@ -718,15 +718,43 @@ export default function (pi: ExtensionAPI): void {
|
|
|
718
718
|
countdownInterval = undefined;
|
|
719
719
|
};
|
|
720
720
|
|
|
721
|
-
const
|
|
721
|
+
const chromeToolsActive = (tools = pi.getActiveTools()): boolean => tools.some((name) => CHROME_TOOL_NAME_SET.has(name));
|
|
722
722
|
|
|
723
|
-
const activateChromeTools = ():
|
|
723
|
+
const activateChromeTools = (): boolean => {
|
|
724
724
|
registerChromeTools(pi);
|
|
725
|
-
|
|
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 = ():
|
|
729
|
-
pi.
|
|
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 = (
|
|
738
|
+
action: "authorized" | "revoked" | "expired",
|
|
739
|
+
options: { label?: string; authorizedUntil?: number | "indefinite" } = {},
|
|
740
|
+
): void => {
|
|
741
|
+
const enabled = action === "authorized";
|
|
742
|
+
const content = enabled
|
|
743
|
+
? `Chrome tools enabled by /chrome authorize${options.label ? ` (${options.label})` : ""}.`
|
|
744
|
+
: action === "expired"
|
|
745
|
+
? "Chrome tools disabled because /chrome authorize grant expired."
|
|
746
|
+
: "Chrome tools disabled by /chrome revoke.";
|
|
747
|
+
pi.sendMessage({
|
|
748
|
+
customType: "pi-chrome-tool-change",
|
|
749
|
+
content,
|
|
750
|
+
display: true,
|
|
751
|
+
details: {
|
|
752
|
+
action,
|
|
753
|
+
tools: [...CHROME_TOOL_NAMES],
|
|
754
|
+
authorizedUntil: options.authorizedUntil,
|
|
755
|
+
at: Date.now(),
|
|
756
|
+
},
|
|
757
|
+
}, { triggerTurn: false });
|
|
730
758
|
};
|
|
731
759
|
|
|
732
760
|
// Close THIS session's dedicated automation window/tab. Fire-and-forget and best-effort: it
|
|
@@ -738,12 +766,13 @@ export default function (pi: ExtensionAPI): void {
|
|
|
738
766
|
void bridge.send("automation.cleanup", sessionKey !== undefined ? { sessionKey } : {}, 3_000).catch(() => undefined);
|
|
739
767
|
};
|
|
740
768
|
|
|
741
|
-
const lockChromeControl = (): void => {
|
|
769
|
+
const lockChromeControl = (logAction?: "revoked" | "expired"): void => {
|
|
742
770
|
clearAuthExpiryTimer();
|
|
743
771
|
clearCountdownInterval();
|
|
772
|
+
const hadChromeTools = deactivateChromeTools();
|
|
773
|
+
if (logAction && hadChromeTools) logChromeToolChange(logAction, { authorizedUntil: undefined });
|
|
744
774
|
chromeAuthorizedUntil = undefined;
|
|
745
775
|
persistAuth();
|
|
746
|
-
deactivateChromeTools();
|
|
747
776
|
// Revoking control ends pi-chrome's automation for this session; tidy up the target we own.
|
|
748
777
|
cleanupAutomationTargetBestEffort();
|
|
749
778
|
};
|
|
@@ -760,7 +789,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
760
789
|
const chromeControlAuthorized = (): boolean => {
|
|
761
790
|
if (chromeAuthorizedUntil === "indefinite") return true;
|
|
762
791
|
if (typeof chromeAuthorizedUntil === "number" && chromeAuthorizedUntil > Date.now()) return true;
|
|
763
|
-
if (chromeAuthorizedUntil !== undefined) lockChromeControl();
|
|
792
|
+
if (chromeAuthorizedUntil !== undefined) lockChromeControl("expired");
|
|
764
793
|
return false;
|
|
765
794
|
};
|
|
766
795
|
|
|
@@ -827,7 +856,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
827
856
|
authExpiryTimer = setTimeout(() => {
|
|
828
857
|
if (chromeAuthorizedUntil !== until) return;
|
|
829
858
|
try {
|
|
830
|
-
lockChromeControl();
|
|
859
|
+
lockChromeControl("expired");
|
|
831
860
|
ctx.ui.notify("Chrome control authorization expired. Run /chrome authorize to allow chrome_* tools again.", "info");
|
|
832
861
|
updateChromeStatus(ctx);
|
|
833
862
|
} catch (error) {
|
|
@@ -1040,6 +1069,7 @@ Usage rules:
|
|
|
1040
1069
|
chromeAuthorizedUntil = until;
|
|
1041
1070
|
persistAuth();
|
|
1042
1071
|
activateChromeTools();
|
|
1072
|
+
logChromeToolChange("authorized", { label, authorizedUntil: until });
|
|
1043
1073
|
scheduleAuthExpiry(ctx, until);
|
|
1044
1074
|
ctx.ui.notify(`Chrome control authorized for ${label}.`, "info");
|
|
1045
1075
|
updateChromeStatus(ctx);
|
|
@@ -1063,7 +1093,7 @@ Usage rules:
|
|
|
1063
1093
|
};
|
|
1064
1094
|
|
|
1065
1095
|
const revokeHandler = (ctx: ExtensionContext) => {
|
|
1066
|
-
lockChromeControl();
|
|
1096
|
+
lockChromeControl("revoked");
|
|
1067
1097
|
ctx.ui.notify("Chrome control locked. Run /chrome authorize to allow chrome_* tools again.", "info");
|
|
1068
1098
|
updateChromeStatus(ctx);
|
|
1069
1099
|
};
|
package/package.json
CHANGED