Skip to content

Commit ee3fb76

Browse files
committed
feat: add ElectronVersions.fetch()
Add a public method to explicitly fetch a new version list. Previously, it would check to see if the cache was too old but there was no explicit way to fetch new versions on demand. This feature is needed for Electron Fiddle's "Update Electron Release List" button.
1 parent ef29daf commit ee3fb76

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/versions.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,12 @@ export class ElectronVersions extends BaseVersions {
240240
return new ElectronVersions(versionsCache, now, versions);
241241
}
242242

243-
// upate the cache if it's too old
244-
private async keepFresh(): Promise<void> {
245-
const d = debug('fiddle-core:ElectronVersions:keepFresh');
246-
247-
// if it's still fresh, do nothing
243+
// update the cache
244+
public async fetch(): Promise<void> {
245+
const d = debug('fiddle-core:ElectronVersions:fetch');
248246
const { mtimeMs, versionsCache } = this;
249-
const now = Date.now();
250-
if (ElectronVersions.isCacheFresh(mtimeMs, now)) return;
251-
252-
// update the cache
253247
try {
254-
this.mtimeMs = now;
248+
this.mtimeMs = Date.now();
255249
const versions = await ElectronVersions.fetchVersions(versionsCache);
256250
this.setVersions(versions);
257251
d(`saved "${versionsCache}"`);
@@ -261,6 +255,13 @@ export class ElectronVersions extends BaseVersions {
261255
}
262256
}
263257

258+
// upate the cache iff it's too old
259+
private async keepFresh(): Promise<void> {
260+
if (!ElectronVersions.isCacheFresh(this.mtimeMs, Date.now())) {
261+
await this.fetch();
262+
}
263+
}
264+
264265
public override get prereleaseMajors(): number[] {
265266
void this.keepFresh();
266267
return super.prereleaseMajors;

0 commit comments

Comments
 (0)