Electron installer update

This commit is contained in:
Jiiks 2016-06-05 12:23:40 +03:00
parent cfe00cd50d
commit 1e79726b73
10 changed files with 349 additions and 27 deletions

View File

@ -1,10 +0,0 @@
{
"name": "Install",
"description": "Better Discord enhances Discord.",
"version": "0.1.1",
"homepage": "https://github.com/Jiiks/BetterDiscordApp",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "^1.0.0"
}
}

View File

@ -1,7 +1,7 @@
html, body {
margin:0;
padding:0;
background:#212229;
background: rgba(34, 35, 42, 0.6);
overflow: hidden;
}
@ -25,9 +25,12 @@ html, body {
pointer-events: none;
width:100%;
height:40px;
background:#212229;
background:rgba(34, 35, 42, 0.6);
border-bottom:1px solid #000;
box-shadow:0 1px 0 0 #303030;
background: rgba(23, 23, 23, 0.6);
border:none;
box-shadow: none;
}
#titleBar h3 {
@ -62,12 +65,16 @@ html, body {
.sidebar {
width:200px;
height:100%;
height:359px;
border-right:1px solid #000;
box-shadow:1px 0 0 0 #303030;
background:#212229;
background:rgba(34, 35, 42, 0.6);
z-index:90001;
margin-top: 1px;
border:none;
margin:0;
box-shadow: none;
margin-left:1px;
}
.sidebar-inner {
@ -191,6 +198,8 @@ button {
padding:5px;
box-shadow:1px 1px 0 0 #303030 inset;
cursor:pointer;
border: none;
box-shadow: none;
}
button:hover {
@ -204,6 +213,9 @@ button:disabled {
color:gray;
cursor: not-allowed;
}
button:active {
background: #232b2e;
}
::-webkit-scrollbar-thumb {
background:#282828 !important;
@ -314,4 +326,43 @@ input.path {
20% {opacity: 0}
50% {opacity: 1}
100%{opacity: 0}
}
#log {
padding: 10px;
height:294px;
resize: none;
width: 563px;
background: rgba(42, 44, 55, 0.6);
border: none;
-webkit-user-select: text;
word-wrap: break-word;
white-space: pre-line;
overflow: auto;
}
progress {
position: absolute;
bottom: -36px;
left:0;
width:520px;
height: 27px;
-webkit-appearance:none;
}
progress::-webkit-progress-bar {
background:rgba(42, 44, 55, 0.6);
}
progress[value]::-webkit-progress-value {
background-image: -webkit-linear-gradient(left, rgba(73,155,234,1) 0%, rgba(32,124,229,1) 100%);
}
.border {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
border:1px solid #55BBF7;
}

View File

@ -3,6 +3,7 @@
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<div class="border"></div>
<div id="titleBar">
<div class="icon">
<div class="icon-image"></div>
@ -24,10 +25,10 @@
</div>
<div class="main">
<div class="panel-container">
<div class="panel" id="panel-0">
<div class="panel" id="panel-3">
<h2>Welcome to the BetterDiscord setup</h2>
<p>
The setup will isntall BetterDiscord on your computer.
The setup will install BetterDiscord on your computer.
<br>
Click "Next" to continue or "Cancel" to exit the setup.
</p>
@ -63,12 +64,16 @@
<label for="restart" style="margin:0; line-height: 18px;">Restart Discord after installation</label>
</div>
<div class="panel" id="panel-3">feafewa</div>
<div class="panel" id="panel-0">
<div name="log" id="log"></div>
<progress id="logpbar" value="0" max="100"></progress>
</div>
</div>
<div class="controls">
<button id="uninstall" style="display: none;">Uninstall</button>
<button id="back" style="display: none;">Back</button>
<button id="next">Next</button>
<button id="cancel">Cancel</button>
<button id="next" style="display: none;">Next</button>
<button id="cancel">Abort</button>
</div>
</div>
</div>
@ -94,5 +99,14 @@
</div>
</body>
<script type="text/javascript" src="js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript">
$(window).blur(function(){
$(".border").css("border-color", "#F76455");
});
$(window).focus(function(){
$(".border").css("border-color", "#55BBF7");
});
</script>
</html>

View File

@ -2,7 +2,7 @@
const ipcRenderer = require('electron').ipcRenderer;
$(function() {
(function() {
var currentPanel = 0;
@ -102,6 +102,38 @@ $(function() {
$("#quit").show();
}
$("#discordPath").val(ipcRenderer.sendSync('sync', 'getInstallPath'));
$("#discordPath").val(ipcRenderer.sendSync('sync', '{ "arg": "getInstallPath" }'));
install();
})();
})();
ipcRenderer.on('async-reply', (event, arg) => {
console.log(arg);
switch(arg.arg) {
case "exists":
switch(arg.file) {
case "app.asar":
if(arg.exists) {
appendLog("Located app.asar");
appendLog("Downloading latest BetterDiscord package");
ipcRenderer.send('async', '{"arg": "download", "package": { "host": "https://github.com/", "path": "Jiiks/BetterDiscordApp/archive/stable16.zip" }}');
} else {
appendLog("Unable to locate app.asar. Check your install path.");
}
}
break;
}
});
function install() {
appendLog("Initiating installation");
ipcRenderer.send('async', '{ "arg": "locate-discord" }');
}
function appendLog(text) {
var log = $("#log");
log.append(text+"\n");
var sh = log[0].scrollHeight - 40;
if(log.height() + log.scrollTop() >= sh) {
log.scrollTop(sh);
}
}

View File

@ -2,3 +2,14 @@
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.on('async-reply', (event, arg) => {
switch(arg) {
case "update":
$(".spinnertext").text("Downloading Update");
break;
}
});
$(function() {
ipcRenderer.send('async', '{ "arg": "update" }');
});

View File

@ -7,6 +7,7 @@
</head>
</head>
<body class="splash">
<div class="border"></div>
<div class="wrapper">
<div class="spinner"></div>
</div>

View File

@ -0,0 +1,173 @@
'use strict';
const utils = require('./utils');
const _utils = new utils.utils();
const electron = require('electron');
const fs = require('fs');
const path = require('path');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const ipcMain = electron.ipcMain;
var mainWindow = null;
var lastKnownVersion = "0.0.291";
var platform = process.platform;
var installPath = getInstallPath();
var dataPath = `${__dirname}/data/`;
var vi = require(`${dataPath}vi.json`);
function getInstallPath() {
switch(platform) {
case "win32":
var hver = "0.0.0";
var path = `${process.env.LOCALAPPDATA}/Discord/app-${lastKnownVersion}/`;
fs.readdirSync(`${process.env.LOCALAPPDATA}/Discord/`).filter(function(file) {
var tpath = `${process.env.LOCALAPPDATA}/Discord/${file}`;
if(fs.statSync(tpath).isDirectory()) return;
if(!file.startsWith("app-")) return;
var ver = file.replace("app-", "");
if(ver < hver) return;
hver = ver;
});
return path;
break;
case "darwin":
return "/Applications/Discord.app";
break;
default:
return "";
break;
}
}
function loadContent(file, width, height, center) {
if(mainWindow == null) {
createMainWindow(file, width, height);
return;
}
mainWindow.setSize(width, height);
if(center) mainWindow.center();
mainWindow.loadURL(`${dataPath}${file}.html`);
}
function createMainWindow(file, width, height) {
mainWindow = new BrowserWindow({
width: width,
height: height,
fullscreenable: false,
maximizable: false,
frame: false,
resizable: true,
alwaysOnTop: true,
transparent: true
});
mainWindow.loadURL(`${dataPath}${file}.html`);
}
function update() {
var promises = [
new Promise((resolve, reject) => {
downloadResource("default", "/Jiiks/BetterDiscordApp/master/Installers/Electron/src/data/index.html", (error, data) => {
if(error) {
error(data);
reject();
return;
}
_utils.log("Succesfully loaded index.html");
resolve();
});
}),
new Promise((resolve, reject) => {
downloadResource("default", "/Jiiks/BetterDiscordApp/master/Installers/Electron/src/data/js/main.js", (error, data) => {
if(error) {
error(data);
reject();
return;
}
_utils.log("Succesfully loaded main.js");
resolve();
});
}),
new Promise((resolve, reject) => {
downloadResource("default", "/Jiiks/BetterDiscordApp/master/Installers/Electron/src/data/css/main.css", (error, data) => {
if(error) {
error(data);
reject();
return;
}
_utils.log("Succesfully loaded main.css");
resolve();
});
})
];
return Promise.all(promises);
}
function checkForUpdates(okCb, errorCb) {
_utils.downloadResource("default", "/Jiiks/BetterDiscordApp/master/Installers/Electron/src/data/vi.json", (error, data) => {
if(error) {
errorCb(data);
return;
}
try {
data = JSON.parse(data);
}catch(err) {
errorCb(err);
return;
}
switch(platform) {
case "win32":
okCb(data.windows.version < vi.windows.version);
break;
case "darwin":
okCb(data.osx.version < vi.osx.version);
break;
}
});
}
ipcMain.on('async', (event, arg) => {
var obj = JSON.parse(arg);
switch(obj.arg) {
case "update":
checkForUpdates((update) => {
if(update) {
event.sender.send('async-reply', "update");
update().then(() => {
_utils.log("Update OK!");
loadContent("index", 800, 400, true);
}, () => {
error("Update Failed!");
});
} else {
loadContent("index", 800, 400, true);
}
}, (err) => {
error(err);
});
break;
}
});
function error(error) {
_utils.log(error);
loadContent("error");
}
app.on('ready', function() {
//loadContent("https://raw.githubusercontent.com/Jiiks/BetterDiscordApp/master/Installers/Electron/src/data/index.html", 800, 400 ,true);
//loadContent("splash", 300, 100, true);
});

View File

@ -1,5 +1,10 @@
{
"name" : "bd-electron",
"version" : "0.1.0",
"main" : "main.js"
"name": "Install",
"description": "Better Discord enhances Discord.",
"version": "0.1.1",
"homepage": "https://github.com/Jiiks/BetterDiscordApp",
"license": "MIT",
"devDependencies": {
"electron-prebuilt": "^1.0.0"
}
}

View File

@ -0,0 +1,45 @@
'use strict';
const https = require('https');
const fs = require('fs');
const eol = require('os').EOL;
function utils() {}
var logs = "";
utils.prototype.log = (message) => {
var d = new Date();
var ds = ("00" + (d.getDate() + 1)).slice(-2) + "/" +
("00" + d.getMonth()).slice(-2) + "/" +
d.getFullYear() + " " +
("00" + d.getHours()).slice(-2) + ":" +
("00" + d.getMinutes()).slice(-2) + ":" +
("00" + d.getSeconds()).slice(-2);
console.log(`[${ds}] ${message}`);
logs += `[${ds}] ${message}${eol}`;
}
utils.prototype.saveLogs = () => {
}
utils.prototype.downloadResource = (host, resource, callback) => {
https.get({
host: host == "default" ? "raw.githubusercontent.com" : host,
path: resource,
headers: { 'user-agent': 'Mozilla/5.0' }
},
(response) => {
var data = "";
response.on("data", (chunk) => {
data += chunk;
});
response.on("end", () => {
callback(false, data);
});
response.on("error", (e) => {
callback(true, e);
});
});
}
exports.utils = utils;

View File

@ -1 +1 @@
{ "version": "0.1.0" }
{ "version": "0.0.9" }