From 1e79726b73e94d3950d79342134e9864db3e218c Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sun, 5 Jun 2016 12:23:40 +0300 Subject: [PATCH] Electron installer update --- Installers/Electron/package.json | 10 -- Installers/Electron/src/data/css/main.css | 59 +++++++- Installers/Electron/src/data/index.html | 26 +++- Installers/Electron/src/data/js/main.js | 38 ++++- Installers/Electron/src/data/js/splash.js | 11 ++ Installers/Electron/src/data/splash.html | 1 + Installers/Electron/src/index.js | 173 ++++++++++++++++++++++ Installers/Electron/src/package.json | 11 +- Installers/Electron/src/utils.js | 45 ++++++ Installers/Electron/src/vi.json | 2 +- 10 files changed, 349 insertions(+), 27 deletions(-) delete mode 100644 Installers/Electron/package.json create mode 100644 Installers/Electron/src/index.js create mode 100644 Installers/Electron/src/utils.js diff --git a/Installers/Electron/package.json b/Installers/Electron/package.json deleted file mode 100644 index c3f7b634..00000000 --- a/Installers/Electron/package.json +++ /dev/null @@ -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" - } -} diff --git a/Installers/Electron/src/data/css/main.css b/Installers/Electron/src/data/css/main.css index 6c357e56..fde73358 100644 --- a/Installers/Electron/src/data/css/main.css +++ b/Installers/Electron/src/data/css/main.css @@ -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; } \ No newline at end of file diff --git a/Installers/Electron/src/data/index.html b/Installers/Electron/src/data/index.html index e7ad2a35..571d803f 100644 --- a/Installers/Electron/src/data/index.html +++ b/Installers/Electron/src/data/index.html @@ -3,6 +3,7 @@ +
@@ -24,10 +25,10 @@
-
+

Welcome to the BetterDiscord setup

- The setup will isntall BetterDiscord on your computer. + The setup will install BetterDiscord on your computer.
Click "Next" to continue or "Cancel" to exit the setup.

@@ -63,12 +64,16 @@
-
feafewa
+
+
+ +
+ - - + +
@@ -94,5 +99,14 @@
- + + + \ No newline at end of file diff --git a/Installers/Electron/src/data/js/main.js b/Installers/Electron/src/data/js/main.js index 026b82a2..dff350e1 100644 --- a/Installers/Electron/src/data/js/main.js +++ b/Installers/Electron/src/data/js/main.js @@ -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(); +})(); -})(); \ No newline at end of file +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); + } +} \ No newline at end of file diff --git a/Installers/Electron/src/data/js/splash.js b/Installers/Electron/src/data/js/splash.js index 58a3bca3..90192201 100644 --- a/Installers/Electron/src/data/js/splash.js +++ b/Installers/Electron/src/data/js/splash.js @@ -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" }'); +}); \ No newline at end of file diff --git a/Installers/Electron/src/data/splash.html b/Installers/Electron/src/data/splash.html index 23e07459..aee077ae 100644 --- a/Installers/Electron/src/data/splash.html +++ b/Installers/Electron/src/data/splash.html @@ -7,6 +7,7 @@ +
diff --git a/Installers/Electron/src/index.js b/Installers/Electron/src/index.js new file mode 100644 index 00000000..38092a9b --- /dev/null +++ b/Installers/Electron/src/index.js @@ -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); +}); \ No newline at end of file diff --git a/Installers/Electron/src/package.json b/Installers/Electron/src/package.json index fffe79fa..e3329739 100644 --- a/Installers/Electron/src/package.json +++ b/Installers/Electron/src/package.json @@ -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" + } } \ No newline at end of file diff --git a/Installers/Electron/src/utils.js b/Installers/Electron/src/utils.js new file mode 100644 index 00000000..381c47d1 --- /dev/null +++ b/Installers/Electron/src/utils.js @@ -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; \ No newline at end of file diff --git a/Installers/Electron/src/vi.json b/Installers/Electron/src/vi.json index 35212f18..e2f72486 100644 --- a/Installers/Electron/src/vi.json +++ b/Installers/Electron/src/vi.json @@ -1 +1 @@ -{ "version": "0.1.0" } \ No newline at end of file +{ "version": "0.0.9" } \ No newline at end of file