Skip to content

Commit f820d1e

Browse files
authored
autoupdate p2
1 parent 85d9eab commit f820d1e

1 file changed

Lines changed: 123 additions & 5 deletions

File tree

index.html

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
<head>
22
<style>
3+
4+
*{
5+
font-family: 'Whitney','Arial';
6+
color:#fff;
7+
}
8+
9+
button,input,select{
10+
color:#000;
11+
}
12+
13+
p {
14+
margin:0px;
15+
}
16+
317
body {
418
background-color: #666;
519
margin: 0px;
@@ -26,7 +40,6 @@
2640
min-width: 35px;
2741
-webkit-app-region: no-drag;
2842
text-align: center;
29-
font-family: 'Whitney','Arial';
3043
color: #eee;
3144
font-size: 22px;
3245
padding-left: 4px;
@@ -90,6 +103,29 @@
90103
border-radius: 8px;
91104
}
92105

106+
.updatedialog {
107+
display: none;
108+
position: fixed;
109+
width: 100%;
110+
height: 100%;
111+
background-color: rgba(51, 51, 51, 0.7);
112+
z-index:99999;
113+
}
114+
115+
.updatedialog.active {
116+
display: block;
117+
}
118+
119+
.updatedialogbody {
120+
position: fixed;
121+
background-color: #666;
122+
width: 26vw;
123+
left: 37vw;
124+
top: 45vh;
125+
padding: 16px;
126+
border-radius: 8px;
127+
}
128+
93129
.rolldownbtn {
94130
position: fixed;
95131
display: none;
@@ -103,6 +139,30 @@
103139
.topbar:hover {
104140
height: 30px !important;
105141
}
142+
143+
.buttoncontainer{
144+
display:flex;
145+
flex-flow:row nowrap;
146+
justify-content: center;
147+
}
148+
149+
.button{
150+
flex: 1 1 0;
151+
display:flex;
152+
border-radius: 8px;
153+
height: 40px;
154+
margin: 0px 4px;
155+
padding:4px;
156+
background-color:#888;
157+
justify-content: center;
158+
align-items:center;
159+
font-size:20px;
160+
}
161+
.updatetext{
162+
font-size: 20px;
163+
margin-top:0px;
164+
margin-bottom:8px;
165+
}
106166
</style>
107167
</head>
108168

@@ -147,12 +207,23 @@
147207
tabs</input>
148208
</div>
149209
</div>
210+
<div class="updatedialog">
211+
<div class="updatedialogbody">
212+
<p class="updatetext">An update for DTabs is available, would you like to apply it?</p>
213+
<div class="buttoncontainer">
214+
<div class="button" onclick="update()"><p>Yes</p></div>
215+
<div class="button" onclick="dismissupdate(false)"><p>No</p></div>
216+
<div class="button" onclick="dismissupdate(true)"><p>Never</p></div>
217+
</div>
218+
</div>
219+
</div>
150220
<div class="mainbody">
151221
</div>
152222
</body>
223+
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
153224
<script>
154-
const VERSION="VERSION=0;";
155-
225+
const VERSION="VERSION=1;";
226+
156227
var $ = document.querySelector.bind(document)
157228
var $$ = document.querySelectorAll.bind(document)
158229

@@ -171,9 +242,10 @@
171242
}
172243
`
173244
let tabtokens = {}
174-
175245
let csskeys = {};
176246

247+
const fs = require("fs");
248+
177249
$`#injecttoggle`.checked = localStorage.getItem('injectcss') == 'true'
178250
$`#locktabs`.checked = localStorage.getItem('tablock') == 'true'
179251
$`#injectpath`.textContent = localStorage.getItem('csspath') || "Select file"
@@ -225,6 +297,52 @@
225297
$`.settings`.classList.add("active")
226298
}
227299

300+
//autoupdater
301+
setInterval(updatecheck,10800000)
302+
303+
var updatecontents = "";
304+
var checkdisabled = false;
305+
var verregex = /VERSION=(\d)+;/;
306+
var instance = axios.create({
307+
validateStatus: a => {
308+
return true;
309+
}
310+
});
311+
312+
function updatecheck(noprompt){
313+
if(checkdisabled) return;
314+
instance.get("https://raw.githubusercontent.com/craftxbox/DTabs/master/index.html").then(function(response){
315+
if(response.status != 200 && !checkdisabled){
316+
checkdisabled = true;
317+
alert("DTabs was unable to check for updates!")
318+
return;
319+
}
320+
updatecontents = response.data;
321+
if(!verregex.test(updatecontents)) return;
322+
if(updatecontents.match(verregex)[1] > VERSION.match(verregex)[1]){
323+
console.log("DTabs found an update! Upstream Version:",updatecontents.match(verregex)[1])
324+
if(!noprompt) $`.updatedialog`.classlist.add("active");
325+
} else{
326+
console.log("DTabs did not find an update. Upstream Version:",updatecontents.match(verregex)[1])
327+
}
328+
})
329+
}
330+
331+
function update(){
332+
$`.updatedialog`.classList.add("active")
333+
$`.updatedialogbody`.setAttribute("style","display:none;")
334+
updatecheck(true);
335+
fs.renameSync("./resources/app/index.html","./resources/app/index.html.OLD-"+Date.now());
336+
fs.writeFileSync("./resources/app/index.html",updatecontents,"utf8");
337+
alert("Update has been applied, DTabs will now exit.");
338+
window.close();
339+
}
340+
341+
function dismissupdate(dontask){
342+
checkdisabled = dontask;
343+
$`.updatedialog`.classlist.remove("active");
344+
}
345+
228346
function csspath(reload = false) {
229347
if (!reload) {
230348
const { dialog } = require("electron").remote
@@ -235,7 +353,6 @@
235353
}
236354
}
237355
if (localStorage.getItem('injectcss') == 'true' && localStorage.getItem('injectcss') && localStorage.getItem('csspath') != null) {
238-
const fs = require("fs");
239356
var cssfile = fs.readFileSync(localStorage.getItem("csspath")).toString();
240357
for (var i of $$("webview")) {
241358
i.executeJavaScript(`document.querySelector('.DTABSCSS') != null ? document.head.removeChild(document.querySelector('.DTABSCSS')) : null;
@@ -257,6 +374,7 @@
257374
async function inittabs() {
258375
if (tabsuninit.length < 1) {
259376
csspath(true);
377+
updatecheck();
260378
return;
261379
};
262380
let i = tabsuninit[0]

0 commit comments

Comments
 (0)