Skip to content

Commit 98ef3c2

Browse files
committed
Fix URL propagation
1 parent 9e8393e commit 98ef3c2

File tree

3 files changed

+73
-57
lines changed

3 files changed

+73
-57
lines changed

src/local/offline.html

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
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 getUrl() {
12+
return new URL(window.location.href).searchParams.get('url');
13+
}
14+
document.getElementById('sploder-url').textContent = getUrl();
15+
1016
// All hail GitHub Copilot!!
1117
function getRetryParameter() {
1218
// Get the current URL
@@ -18,11 +24,23 @@
1824
// Get the value of the 'retry' parameter
1925
var retryParameterValue = url.searchParams.get('retry');
2026

27+
const queryString = window.location.search;
28+
const urlParam = getUrl();
29+
2130
// Provide a default value if the 'retry' parameter is not present
22-
return retryParameterValue !== null ? retryParameterValue : 'http://sploder.local/update';
31+
return retryParameterValue !== null
32+
? retryParameterValue
33+
: urlParam + '/update';
2334
}
2435

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

2846

@@ -34,21 +52,13 @@
3452
<img style="margin-top:-40px;" alt="Sploder" class="logo" width="203" height="160" src="images/logo.png"><
3553
<img class="icon" width="200" height="200" src="images/icon.png">
3654
<div class="cf-error-details cf-error-522">
37-
<BR><BR><br><h1>Whoops... Could not connect to the server.</h1>
55+
<br><br><br>
56+
<h1>Whoops... Could not connect to the server.</h1>
3857
<p>Check your internet connection and try again.</p>
58+
<span id="sploder-url"></span>
3959
<p>If that does not work, please email <a href="mailto:saptarshi12345yt@gmail.com">saptarshi12345yt@gmail.com</a> with
4060
your exact issue.</p>
4161
<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>
5262

5363
</div>
5464

src/local/start.html

Lines changed: 28 additions & 37 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 = "http://sploder.local/update";
18-
}
19+
// window.href.location = urlParam + '/update';
1920

2021
var page;
2122
var prevpage;
@@ -58,29 +59,30 @@
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 = "http://sploder.local/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 queryString = window.location.search;
73+
// Check get parameter to get URL
74+
const urlParam = getUrl();
75+
var url = urlParam + '/php/ping.php';
76+
var xhttp = new XMLHttpRequest();
77+
xhttp.onreadystatechange = function() {
78+
const offlineUrl = "offline.html?retry="+page+'&url='+encodeURIComponent(urlParam);
79+
if (this.readyState == 4 && this.status != 200 && frame.getAttribute('src') != offlineUrl) {
7780
if(page != "test") {
78-
prevpage = page;
81+
prevpage = page;
7982
}
8083
pagestat = "offline";
8184
page = "offline.html";
82-
frame.setAttribute('src', 'offline.html?retry='+page);
83-
85+
frame.setAttribute('src', offlineUrl);
8486
} else if(document.getElementById("content-frame").contentWindow.location.href != "chrome-error://chromewebdata/") {
8587
page = document.getElementById("content-frame").contentWindow.location.href;
8688
} else {
@@ -89,11 +91,9 @@
8991
}
9092
//pagestat = "online";
9193
}
92-
9394
};
9495
xhttp.open("GET", url, true);
9596
xhttp.send();
96-
9797
}
9898
}
9999
// Prevent scrolling using JavaScript
@@ -113,10 +113,7 @@
113113
event.preventDefault(); // Disable keyboard scrolling
114114
}
115115
});
116-
117-
118-
119-
116+
});
120117
</script>
121118
<style>
122119
body, html {
@@ -163,11 +160,10 @@
163160
}
164161
</style>
165162
<body>
166-
167163
<div class="window" style="width: 100%; height: calc(100% - 3px)">
168164
<div class="title-bar">
169165
<img class="title-bar-icon" src="images/icon.png">
170-
<div class="title-bar-text">Sploder</div>
166+
<div class="title-bar-text">Sploder <span id="sploder-url"></span></div>
171167
<div class="titlebar-movable"></div>
172168
<div class="title-bar-controls">
173169
<button id="min-btn" onclick="win.minimize()" aria-label="Minimize"></button>
@@ -178,13 +174,8 @@
178174
<div class="window-body"
179175
style="width: 100%; height: calc(100% - 50px); margin-left: 3px; margin-top:0px; padding-bottom: -50px;">
180176
<iframe id="content-frame" onload="online();" src="">
181-
</iframe>
182-
<script>
183-
document.getElementById("content-frame").setAttribute('src', url);
184-
</script>
185-
177+
</iframe>
186178
</div>
187179
</div>
188-
189180
</body>
190-
</html>
181+
</html>

src/main/index.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
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
if (process.platform === "win32") {
516
const DiscordRPC = require('discord-rpc');
617
}
718
let win;
819
let pluginName;
9-
const isDev = false; // Change to false if you want to disable development mode and package the application.
1020
switch (process.platform) {
1121
case "win32":
1222
pluginName = process.arch == 'x64' ? 'x64/pepflashplayer.dll' : 'x32/pepflashplayer32.dll';
@@ -116,12 +126,14 @@ function createWindow() {
116126
win.openDevTools();
117127
}
118128
// Load the custom Windows XP titlebar.
119-
if(isDev){
120-
startpath = "/../../src/local/start.html?url="
129+
if(isDev) {
130+
startpath = `/../../src/local/start.html?url=${encodeURIComponent(config.SPLODER_URL)}`
131+
console.log('startpath: ', startpath);
121132
} else {
122-
startpath = "/../../resources/src/local/start.html?url="
133+
startpath = `/../../resources/src/local/start.html?url=${encodeURIComponent(config.SPLODER_URL)}`
123134
}
124-
win.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + "http://sploder.local/update");
135+
// win.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + '/update');
136+
win.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath);
125137
win.webContents.on('did-finish-load', () => {
126138
win.show();
127139
});
@@ -146,7 +158,11 @@ function createWindow() {
146158
},
147159
});
148160
win.newwin.setMenu(null);
149-
win.newwin.loadURL("file:///" + app.getAppPath().replace(/\\/g, '/') + startpath + url);
161+
const publishUrl = "file:///" + app.getAppPath().replace(/\\/g, '/') + startpath;
162+
if (isDev) {
163+
console.log('publish: ', publishUrl);
164+
}
165+
win.newwin.loadURL(publishUrl);
150166
win.newwin.webContents.on('did-finish-load', () => {
151167
win.newwin.show();
152168
});
@@ -176,7 +192,6 @@ app.on("window-all-closed", function () {
176192
app.quit();
177193
});
178194

179-
180195
if (process.platform === "win32") {
181196
const clientId = '915116210570539058';
182197
const rpc = new DiscordRPC.Client({ transport: 'ipc' });

0 commit comments

Comments
 (0)