Skip to content

Commit 04511a2

Browse files
authored
fix(snaps): Patch CronjobController (#17266)
## **Description** This PR fixes a regression in the `7.50.1` release by patching temporarily in the new release the `CronjobController` with a fix that exists in a higher version of the package. This fix is only applied to this release as the next releases already contains the fix with the actual version of the package. Fixes: #17183
1 parent 00e9b6f commit 04511a2

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

patches/@metamask+snaps-controllers+13.1.1.patch renamed to patches/@metamask+snaps-controllers+13.0.0.patch

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.cjs b/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.cjs
2-
index 0e8feeb..2bf546a 100644
2+
index 0e8feeb..5eae8f9 100644
33
--- a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.cjs
44
+++ b/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.cjs
55
@@ -39,9 +39,18 @@ class CronjobController extends base_controller_1.BaseController {
@@ -21,6 +21,28 @@ index 0e8feeb..2bf546a 100644
2121
this.#start();
2222
this.#clear();
2323
this.#reschedule();
24+
@@ -182,6 +191,12 @@ class CronjobController extends base_controller_1.BaseController {
25+
if (ms > exports.DAILY_TIMEOUT) {
26+
return;
27+
}
28+
+ // When an event is supposed to be scheduled close to the current time
29+
+ // we may end up needing to execute immediately instead.
30+
+ if (ms <= 0) {
31+
+ this.#execute(event);
32+
+ return;
33+
+ }
34+
const timer = new Timer_1.Timer(ms);
35+
timer.start(() => {
36+
this.#execute(event);
37+
@@ -262,6 +277,8 @@ class CronjobController extends base_controller_1.BaseController {
38+
* @param snap - Basic Snap information.
39+
*/
40+
#handleSnapInstalledEvent = (snap) => {
41+
+ // In case of local Snaps, they may already have cronjobs that should be cleared.
42+
+ this.unregister(snap.id);
43+
this.register(snap.id);
44+
};
45+
/**
2446
diff --git a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.d.cts b/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.d.cts
2547
index 99f72dd..bac97d5 100644
2648
--- a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.d.cts
@@ -106,7 +128,7 @@ index 40ba2e1..ae0fb31 100644
106128
* Schedule a non-recurring background event.
107129
*
108130
diff --git a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.mjs b/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.mjs
109-
index e3f025c..b90b08f 100644
131+
index e3f025c..421ecb8 100644
110132
--- a/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.mjs
111133
+++ b/node_modules/@metamask/snaps-controllers/dist/cronjob/CronjobController.mjs
112134
@@ -36,9 +36,18 @@ export class CronjobController extends BaseController {
@@ -128,3 +150,25 @@ index e3f025c..b90b08f 100644
128150
this.#start();
129151
this.#clear();
130152
this.#reschedule();
153+
@@ -179,6 +188,12 @@ export class CronjobController extends BaseController {
154+
if (ms > DAILY_TIMEOUT) {
155+
return;
156+
}
157+
+ // When an event is supposed to be scheduled close to the current time
158+
+ // we may end up needing to execute immediately instead.
159+
+ if (ms <= 0) {
160+
+ this.#execute(event);
161+
+ return;
162+
+ }
163+
const timer = new Timer(ms);
164+
timer.start(() => {
165+
this.#execute(event);
166+
@@ -259,6 +274,8 @@ export class CronjobController extends BaseController {
167+
* @param snap - Basic Snap information.
168+
*/
169+
#handleSnapInstalledEvent = (snap) => {
170+
+ // In case of local Snaps, they may already have cronjobs that should be cleared.
171+
+ this.unregister(snap.id);
172+
this.register(snap.id);
173+
};
174+
/**

0 commit comments

Comments
 (0)