Skip to content

Commit 1fc9c17

Browse files
committed
fix: provide fallback url when bc main site is down, close #12
1 parent 8ca39f3 commit 1fc9c17

File tree

3 files changed

+78
-24
lines changed

3 files changed

+78
-24
lines changed

src/loading/constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const ForwardedEvent = [
22
"fetching-bc-start",
33
"fetching-bc-done",
4+
"fetching-bc-fb",
45
"error",
56
] as const;
67

src/loading/fetchLatestBC.ts

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,71 @@
1-
import { net } from "electron";
1+
import { net } from 'electron'
22

3-
export function fetchLatestBC(): Promise<BCVersion[]> {
3+
export function fallback (): BCVersion[] {
4+
// monthly advanced versions
5+
// 2025/05/16 ~ 2025/06/15 = R116
6+
// 2025/06/16 ~ 2025/07/15 = R117
7+
// 2025/07/16 ~ 2025/08/15 = R118
8+
9+
const dateTime = new Date()
10+
const year = dateTime.getUTCFullYear()
11+
const month = dateTime.getUTCMonth()
12+
const day = dateTime.getUTCDate()
13+
14+
const vNumber =
15+
Math.floor((year - 2025) * 12 + month) + 111 + (day >= 16 ? 1 : 0)
16+
const version = `R${vNumber}`
17+
18+
console.log(`Using fallback version: ${version}`)
19+
20+
return [
21+
{
22+
version,
23+
url: `https://www.bondageprojects.elementfx.com/${version}/BondageClub/`,
24+
},
25+
{
26+
version,
27+
url: `https://www.bondage-europe.com/${version}/`,
28+
},
29+
{
30+
version,
31+
url: `https://www.bondageprojects.elementfx.com/${version}/`,
32+
},
33+
]
34+
}
35+
36+
export function fetchLatestBC (): Promise<BCVersion[]> {
437
return new Promise<BCVersion[]>((resolve, reject) => {
538
net
6-
.fetch("https://bondageprojects.com/club_game/", {
39+
.fetch('https://bondageprojects.com/club_game/', {
740
bypassCustomProtocolHandlers: true,
8-
cache: "no-store",
41+
cache: 'no-store',
942
})
10-
.then(async (response) => {
43+
.then(async response => {
1144
if (!response.ok)
12-
throw new Error(`HTTP ${response.status} ${response.statusText}`);
45+
throw new Error(`HTTP ${response.status} ${response.statusText}`)
1346

14-
const html = await response.text();
47+
const html = await response.text()
1548

1649
const matches = html.match(
1750
/onclick="window\.location='(https:\/\/www.bondage[^']+)'/g
18-
);
51+
)
1952

2053
if (!matches || matches.length === 0) {
21-
throw new Error("No valid bc versions found");
54+
throw new Error('No valid bc versions found')
2255
}
2356

24-
const versions: BCVersion[] = matches.map((match) => {
25-
const url = match.match(/'(https:\/\/www\.bondage[^']+)'/)?.[1];
26-
const version = url?.match(/R\d+/)?.[0];
27-
if (url && version) {
28-
return { url, version };
29-
}
30-
return undefined;
31-
}).filter(Boolean) as BCVersion[];
32-
resolve(versions);
57+
const versions: BCVersion[] = matches
58+
.map(match => {
59+
const url = match.match(/'(https:\/\/www\.bondage[^']+)'/)?.[1]
60+
const version = url?.match(/R\d+/)?.[0]
61+
if (url && version) {
62+
return { url, version }
63+
}
64+
return undefined
65+
})
66+
.filter(Boolean) as BCVersion[]
67+
resolve(versions)
3368
})
34-
.catch(reject);
35-
});
69+
.catch(reject)
70+
})
3671
}

src/loading/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import { BrowserWindow } from "electron";
22
import path from "path";
3-
import { fetchLatestBC } from "./fetchLatestBC";
3+
import { fallback, fetchLatestBC } from "./fetchLatestBC";
44
import { packageFile } from "../main/utility";
55
import { BCURLPreference } from "../urlprefer";
6+
import { sleep } from "../render/utils";
7+
import { ForwardedEvent } from "./constant";
8+
9+
function webContentsSend(
10+
win: BrowserWindow,
11+
channel: typeof ForwardedEvent[number],
12+
...args: any[]
13+
) {
14+
if (win.webContents.isDestroyed()) return;
15+
win.webContents.send(channel, ...args);
16+
}
617

718
export async function createFetchBCVersionWindow() {
819
const win = new BrowserWindow({
@@ -26,15 +37,22 @@ export async function createFetchBCVersionWindow() {
2637

2738
try {
2839
win.loadFile("resource/loading.html");
29-
win.webContents.send("fetching-bc-start");
40+
webContentsSend(win, "fetching-bc-start");
3041

3142
const results = await fetchLatestBC();
3243
const result = BCURLPreference.choose(results);
3344

34-
win.webContents.send("fetching-bc-done", result);
45+
webContentsSend(win, "fetching-bc-done", result);
3546
win.close();
3647
return results;
3748
} catch (error) {
38-
win.webContents.send("error", error);
49+
webContentsSend(win, "error", error);
3950
}
51+
52+
const fb_results = await fallback();
53+
const result = BCURLPreference.choose(fb_results);
54+
webContentsSend(win, "fetching-bc-fb", result);
55+
await sleep(2000);
56+
win.close();
57+
return fb_results;
4058
}

0 commit comments

Comments
 (0)