Skip to content

Commit 24c5e70

Browse files
Make a configuration file to have the site URL
1 parent 4d570b4 commit 24c5e70

File tree

6 files changed

+88
-151
lines changed

6 files changed

+88
-151
lines changed

addurl.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

src/config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Centralized configuration for Sploder-Launcher
3+
* This file is used by both the main process and the build script
4+
*/
5+
6+
// Default configuration
7+
const config = {
8+
// Base URL for the application
9+
baseUrl: "https://www.sploder.net",
10+
11+
// Specific endpoints
12+
endpoints: {
13+
update: "/update",
14+
ping: "/php/ping.php"
15+
},
16+
17+
// Generate a full URL for an endpoint
18+
getUrl: function(endpoint) {
19+
return this.baseUrl + (this.endpoints[endpoint] || endpoint);
20+
}
21+
};
22+
23+
// Allow overriding the base URL if needed
24+
function setBaseUrl(url) {
25+
config.baseUrl = url;
26+
}
27+
28+
module.exports = {
29+
config,
30+
setBaseUrl
31+
};

src/local/offline.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<style>*{margin:0;padding:0}html,body{width:100%;height:100%}body{margin:0;background-color:#32103C;font-family:"Helvetica Neue",Helvetica,Arial,Sans-serif;color:#fff}img{display:block}img.icon{z-index:-1;margin:-40px 0}img.logo{position:relative;z-index:1000}a{color:#ea0}h1,h2{color:#fff;margin-bottom:.25em}p{color:#ccc}table{height:100%;padding:20px}td.announce{margin-top:25%}div.cloudflare_logo{margin:10px 20px}ul{margin-top:20px;width:75%;background-color:#000;padding:20px;border-radius:10px}ul li{font-size:.8em;text-align:left;list-style-type:none}ul li p{color:#666}p.cferror_msg{padding-left:10%;padding-right:10%}</style>
99
<script type="text/javascript">
1010
// All hail GitHub Copilot!!
11-
function getRetryParameter() {
11+
async function getRetryParameter() {
1212
// Get the current URL
1313
var currentUrl = window.location.href;
1414

@@ -18,8 +18,19 @@
1818
// Get the value of the 'retry' parameter
1919
var retryParameterValue = url.searchParams.get('retry');
2020

21-
// Provide a default value if the 'retry' parameter is not present
22-
return retryParameterValue !== null ? retryParameterValue : '_[[URL]]_/update';
21+
// If the retry parameter is provided, use it, otherwise get the update URL from the config
22+
if (retryParameterValue !== null) {
23+
return retryParameterValue;
24+
} else {
25+
try {
26+
// Get the update URL from the main process
27+
return await window.electronAPI.getUrl('update');
28+
} catch (error) {
29+
console.error('Error getting update URL:', error);
30+
// Fallback to hardcoded URL in case of error
31+
return 'https://sploder.com/update';
32+
}
33+
}
2334
}
2435

2536

@@ -45,9 +56,13 @@
4556
function retry(){
4657
retried = true;
4758
}
48-
const btn = document.getElementById('retrybtn');
49-
btn.setAttribute('href', getRetryParameter());
50-
59+
60+
// Set up the retry button href when the document is loaded
61+
document.addEventListener('DOMContentLoaded', async function() {
62+
const btn = document.getElementById('retrybtn');
63+
const retryUrl = await getRetryParameter();
64+
btn.setAttribute('href', retryUrl);
65+
});
5166
</script>
5267

5368
</div>

src/local/start.html

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@
1010
// Wait for DOM to be fully loaded before initializing
1111
document.addEventListener('DOMContentLoaded', initializeApp);
1212

13-
function initializeApp() {
13+
async function initializeApp() {
1414
// Check get parameter to get URL
1515
const queryString = window.location.search;
1616
const urlParams = new URLSearchParams(queryString);
1717
const url = urlParams.get('url');
1818

1919
// If the URL is not provided, redirect to the update page
2020
if (url == null) {
21-
window.location.href = "_[[URL]]_/update";
21+
try {
22+
const updateUrl = await window.electronAPI.getUrl('update');
23+
window.location.href = updateUrl;
24+
} catch (error) {
25+
console.error('Error getting update URL:', error);
26+
// Fallback to hardcoded URL in case of error
27+
window.location.href = "https://sploder.com/update";
28+
}
2229
}
2330

2431
// Store URL in a global variable for other functions to access
@@ -124,7 +131,7 @@
124131
setInterval(discordrpc, 15000);
125132
// Custom built code to check if user is online.
126133
// I have no idea how or why this works.
127-
function online() {
134+
async function online() {
128135
if(document.getElementById("content-frame").contentWindow.location.href != "chrome-error://chromewebdata/"){
129136
page = document.getElementById("content-frame").contentWindow.location.href;
130137
} else if(page == undefined) {
@@ -136,9 +143,10 @@
136143

137144

138145
const frame = document.getElementById('content-frame');
139-
var pingUrl = "_[[URL]]_/php/ping.php";
140-
var xhttp = new XMLHttpRequest();
141-
xhttp.onreadystatechange = function() {
146+
try {
147+
var pingUrl = await window.electronAPI.getUrl('ping');
148+
var xhttp = new XMLHttpRequest();
149+
xhttp.onreadystatechange = function() {
142150

143151
if (this.readyState == 4 && this.status != 200 && frame.getAttribute('src') != "offline.html?retry="+page) {
144152
if(page != "test") {
@@ -160,7 +168,9 @@
160168
};
161169
xhttp.open("GET", pingUrl, true);
162170
xhttp.send();
163-
171+
} catch (error) {
172+
console.error('Error getting ping URL:', error);
173+
}
164174
}
165175
}
166176
// Add window focus and blur listeners to check window state

src/main/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const { app, BrowserWindow, shell, ipcMain } = require("electron");
22
const path = require("path");
33
const url = require("url");
44

5+
// Import centralized configuration
6+
const { config } = require("../config");
7+
58
// Helper function to create proper file URLs
69
function pathToFileURL(filePath) {
710
const formattedPath = path.resolve(filePath).replace(/\\/g, '/');
@@ -140,8 +143,8 @@ function createWindow() {
140143
startHtmlPath = path.resolve(path.join(app.getAppPath(), 'resources', 'src', 'local', 'start.html'));
141144
}
142145

143-
// Load the URL with proper file protocol
144-
const startUrl = `${pathToFileURL(startHtmlPath)}?url=_[[URL]]_/update`;
146+
// Load the URL with proper file protocol and use the config for the initial URL
147+
const startUrl = `${pathToFileURL(startHtmlPath)}?url=${config.getUrl('update')}`;
145148
win.loadURL(startUrl);
146149

147150
win.webContents.on('did-finish-load', () => {
@@ -305,3 +308,13 @@ ipcMain.handle('get-rpc-info', async (event) => {
305308
return '';
306309
}
307310
});
311+
312+
// Handler to provide application configuration to the renderer
313+
ipcMain.handle('get-config', (event) => {
314+
return config;
315+
});
316+
317+
// Handler to get a specific URL
318+
ipcMain.handle('get-url', (event, endpoint) => {
319+
return config.getUrl(endpoint);
320+
});

src/renderer/preload.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
1111
ipcRenderer.on('window-state-change', (_, isMaximized) => {
1212
callback(isMaximized);
1313
});
14-
}
14+
},
15+
// Configuration API
16+
getConfig: () => ipcRenderer.invoke('get-config'),
17+
getUrl: (endpoint) => ipcRenderer.invoke('get-url', endpoint)
1518
});

0 commit comments

Comments
 (0)