Skip to content

Commit e32e3dd

Browse files
committed
Fix URL propagation for Launcher
1 parent 004432d commit e32e3dd

File tree

3 files changed

+90
-74
lines changed

3 files changed

+90
-74
lines changed

src/local/offline.html

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,38 @@
77
<title>Sploder</title>
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">
10+
document.addEventListener('DOMContentLoaded', function() {
11+
function getSearchParams() {
12+
return new URL(window.location.href).searchParams;
13+
}
14+
function getUrl() {
15+
return getSearchParams().get('url');
16+
}
17+
const url = getUrl();
18+
document.getElementById('sploder-url').textContent = url;
19+
1020
// All hail GitHub Copilot!!
1121
function getRetryParameter() {
12-
// Get the current URL
13-
var currentUrl = window.location.href;
14-
15-
// Create a URL object
16-
var url = new URL(currentUrl);
17-
18-
// Get the value of the 'retry' parameter
19-
var retryParameterValue = url.searchParams.get('retry');
22+
// Get the current URL
23+
const searchParams = getSearchParams();
24+
// Get the value of the 'retry' parameter
25+
const retryParameterValue = searchParams.get('retry');
2026

2127
// Provide a default value if the 'retry' parameter is not present
22-
return retryParameterValue !== null ? retryParameterValue : 'https://sploder.xyz/update';
28+
const value = retryParameterValue !== null
29+
? retryParameterValue
30+
: url + '/update';
31+
return value;
2332
}
2433

25-
34+
// Check if we actually retried and not come here for the first time.
35+
var retried;
36+
function retry(){
37+
retried = true;
38+
}
39+
const btn = document.getElementById('retrybtn');
40+
btn.setAttribute('href', getRetryParameter());
41+
});
2642
</script>
2743

2844

@@ -34,28 +50,19 @@
3450
<img style="margin-top:-40px;" alt="Sploder" class="logo" width="203" height="160" src="images/logo.png"><
3551
<img class="icon" width="200" height="200" src="images/icon.png">
3652
<div class="cf-error-details cf-error-522">
37-
<BR><BR><br><h1>Whoops... Could not connect to the server.</h1>
53+
<br><br><br>
54+
<h1>Whoops... Could not connect to the server.</h1>
3855
<p>Check your internet connection and try again.</p>
56+
<span>Server: <span id="sploder-url"></span></span>
3957
<p>If that does not work, please email <a href="mailto:saptarshi12345yt@gmail.com">saptarshi12345yt@gmail.com</a> with
4058
your exact issue.</p>
41-
<br><a onclick="retry()" id="retrybtn"><button style="outline:none;border:1px solid #7b8eac;background:url('images/button_bkgd_small.jpg') repeat-x top;padding:8px 12px;margin-left:10px;white-space:nowrap;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;color:#ec0;cursor: pointer;">Try again</button></a>
42-
<script>
43-
// Check if we actually retried and not come here for the first time.
44-
var retried;
45-
function retry(){
46-
retried = true;
47-
}
48-
const btn = document.getElementById('retrybtn');
49-
btn.setAttribute('href', getRetryParameter());
50-
51-
</script>
52-
59+
<br>
60+
<a onclick="retry()" id="retrybtn">
61+
<button style="outline:none;border:1px solid #7b8eac;background:url('images/button_bkgd_small.jpg') repeat-x top;padding:8px 12px;margin-left:10px;white-space:nowrap;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;color:#ec0;cursor: pointer;">Try again</button>
62+
</a>
5363
</div>
54-
5564
</td>
5665
</tr>
5766
</tbody></table>
58-
59-
60-
61-
</body></html>
67+
</body>
68+
</html>

src/local/start.html

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
<title>Sploder</title>
88
</head>
99
<script>
10+
document.addEventListener('DOMContentLoaded', function() {
11+
function getUrl() {
12+
return new URL(window.location.href).searchParams.get('url');
13+
}
1014
// Check get parameter to get URL
11-
const queryString = window.location.search;
12-
const urlParams = new URLSearchParams(queryString);
13-
const url = urlParams.get('url');
14-
15+
let url = getUrl();
16+
document.getElementById('sploder-url').textContent = getUrl();
17+
document.getElementById("content-frame").setAttribute('src', url);
1518
// If the URL is not provided, redirect to the update page
16-
if (url == null) {
17-
window.location.href = "https://sploder.xyz/update";
18-
}
19+
// window.href.location = urlParam + '/update';
1920

2021
var page;
2122
var prevpage;
@@ -58,29 +59,27 @@
5859
// Custom built code to check if user is online.
5960
// I have no idea how or why this works.
6061
function online() {
61-
if(document.getElementById("content-frame").contentWindow.location.href != "chrome-error://chromewebdata/"){
62-
page = document.getElementById("content-frame").contentWindow.location.href;
63-
} else if(page == undefined) {
62+
if (document.getElementById("content-frame").contentWindow.location.href != "chrome-error://chromewebdata/") {
63+
page = document.getElementById("content-frame").contentWindow.location.href;
64+
} else if (page == undefined) {
6465
page = url;
6566
}
66-
if(page.includes("offline.html")){
67+
68+
if (page.includes("offline.html")){
6769
page = "test";
6870
} else {
69-
70-
71-
const frame = document.getElementById('content-frame');
72-
var url = "https://sploder.xyz/php/ping.php";
73-
var xhttp = new XMLHttpRequest();
74-
xhttp.onreadystatechange = function() {
75-
76-
if (this.readyState == 4 && this.status != 200 && frame.getAttribute('src') != "offline.html?retry="+page) {
71+
const frame = document.getElementById('content-frame');
72+
const pingUrl = url + '/php/ping.php';
73+
var xhttp = new XMLHttpRequest();
74+
xhttp.onreadystatechange = function() {
75+
const offlineUrl = "offline.html?retry="+page+'&url='+encodeURIComponent(urlParam);
76+
if (this.readyState == 4 && this.status != 200 && frame.getAttribute('src') != offlineUrl) {
7777
if(page != "test") {
78-
prevpage = page;
78+
prevpage = page;
7979
}
8080
pagestat = "offline";
8181
page = "offline.html";
82-
frame.setAttribute('src', 'offline.html?retry='+page);
83-
82+
frame.setAttribute('src', offlineUrl);
8483
} else if(document.getElementById("content-frame").contentWindow.location.href != "chrome-error://chromewebdata/") {
8584
page = document.getElementById("content-frame").contentWindow.location.href;
8685
} else {
@@ -89,11 +88,9 @@
8988
}
9089
//pagestat = "online";
9190
}
92-
9391
};
94-
xhttp.open("GET", url, true);
92+
xhttp.open("GET", pingUrl, true);
9593
xhttp.send();
96-
9794
}
9895
}
9996
// Prevent scrolling using JavaScript
@@ -113,10 +110,7 @@
113110
event.preventDefault(); // Disable keyboard scrolling
114111
}
115112
});
116-
117-
118-
119-
113+
});
120114
</script>
121115
<style>
122116
body, html {
@@ -163,11 +157,10 @@
163157
}
164158
</style>
165159
<body>
166-
167160
<div class="window" style="width: 100%; height: calc(100% - 3px)">
168161
<div class="title-bar">
169162
<img class="title-bar-icon" src="images/icon.png">
170-
<div class="title-bar-text">Sploder</div>
163+
<div class="title-bar-text">Sploder <span id="sploder-url"></span></div>
171164
<div class="titlebar-movable"></div>
172165
<div class="title-bar-controls">
173166
<button id="min-btn" onclick="win.minimize()" aria-label="Minimize"></button>
@@ -178,13 +171,8 @@
178171
<div class="window-body"
179172
style="width: 100%; height: calc(100% - 50px); margin-left: 3px; margin-top:0px; padding-bottom: -50px;">
180173
<iframe id="content-frame" onload="online();" src="">
181-
</iframe>
182-
<script>
183-
document.getElementById("content-frame").setAttribute('src', url);
184-
</script>
185-
174+
</iframe>
186175
</div>
187176
</div>
188-
189177
</body>
190-
</html>
178+
</html>

src/main/index.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
const { app, BrowserWindow, shell } = require("electron");
22
const path = require("path");
3+
process.env.NODE_ENV || 'development';
4+
5+
const config = {
6+
SPLODER_URL: "http://127.0.0.1:8010",
7+
DEV: !app.isPackaged,
8+
}
9+
const isDev = config.DEV;
10+
if (isDev) {
11+
console.log(config);
12+
}
13+
314
// If not on windows, disable RPC
415
let DiscordRPC;
516
if (process.platform == "win32") {
617
DiscordRPC = require('discord-rpc');
718
}
819
let win;
920
let pluginName;
10-
const isDev = false; // Change to false if you want to disable development mode and package the application.
1121
switch (process.platform) {
1222
case "win32":
1323
pluginName = process.arch == 'x64' ? 'x64/pepflashplayer.dll' : 'x32/pepflashplayer32.dll';
@@ -116,13 +126,25 @@ function createWindow() {
116126
if(isDev){
117127
win.openDevTools();
118128
}
129+
130+
function getSploderUrl(path='') {
131+
return encodeURIComponent(config.SPLODER_URL + path);
132+
}
119133
// Load the custom Windows XP titlebar.
120-
if(isDev){
121-
startpath = "/../../src/local/start.html?url="
134+
if(isDev) {
135+
startpath = '/../../src/local/start.html?url='
136+
console.log('startpath: ', startpath);
122137
} else {
123-
startpath = "/../../resources/src/local/start.html?url="
138+
startpath = '/../../resources/src/local/start.html?url='
139+
}
140+
function loadURLFromStartPath(appendedPath='') {
141+
const path = "file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + getSploderUrl() + appendedPath;
142+
if (isDev) {
143+
console.log(path);
144+
}
145+
win.loadURL(path);
124146
}
125-
win.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + "https://sploder.xyz/update");
147+
loadURLFromStartPath();
126148
win.webContents.on('did-finish-load', () => {
127149
win.show();
128150
});
@@ -147,7 +169,7 @@ function createWindow() {
147169
},
148170
});
149171
win.newwin.setMenu(null);
150-
win.newwin.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + url);
172+
loadURLFromStartPath(url);
151173
win.newwin.webContents.on('did-finish-load', () => {
152174
win.newwin.show();
153175
});
@@ -177,8 +199,7 @@ app.on("window-all-closed", function () {
177199
app.quit();
178200
});
179201

180-
181-
if (process.platform == "win32") {
202+
if (process.platform === "win32") {
182203
const clientId = '915116210570539058';
183204
const rpc = new DiscordRPC.Client({ transport: 'ipc' });
184205
const startTimestamp = new Date();

0 commit comments

Comments
 (0)