Splash screen for update
This commit is contained in:
parent
365aba0e01
commit
6537270905
|
@ -7,7 +7,8 @@ exports.startup = startup;
|
||||||
exports.handleSingleInstance = handleSingleInstance;
|
exports.handleSingleInstance = handleSingleInstance;
|
||||||
exports.setMainWindowVisible = setMainWindowVisible;
|
exports.setMainWindowVisible = setMainWindowVisible;
|
||||||
const { Menu } = require('electron');
|
const { Menu } = require('electron');
|
||||||
const request = require("request")
|
const yauzl = require("yauzl")
|
||||||
|
const fetch = require("node-fetch").default
|
||||||
|
|
||||||
let mainScreen;
|
let mainScreen;
|
||||||
function startup(bootstrapModules) {
|
function startup(bootstrapModules) {
|
||||||
|
@ -59,7 +60,7 @@ function startup(bootstrapModules) {
|
||||||
mainScreen.setMainWindowVisible(true)
|
mainScreen.setMainWindowVisible(true)
|
||||||
})
|
})
|
||||||
bootstrapModules.splashScreen.events.on("APP_SHOULD_LAUNCH", () => {
|
bootstrapModules.splashScreen.events.on("APP_SHOULD_LAUNCH", () => {
|
||||||
mainScreen.init()
|
mainScreen.init(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
mainScreen.events.on("ready", () => {
|
mainScreen.events.on("ready", () => {
|
||||||
|
@ -74,28 +75,37 @@ function startup(bootstrapModules) {
|
||||||
|
|
||||||
if(Date.now() - global.appSettings.get("LAST_UPDATE_CHECK_TIMESTAMP", 0) < 6.48e+8){
|
if(Date.now() - global.appSettings.get("LAST_UPDATE_CHECK_TIMESTAMP", 0) < 6.48e+8){
|
||||||
console.log("Starting with version "+version+" because it haven't been 1 week since the last check.")
|
console.log("Starting with version "+version+" because it haven't been 1 week since the last check.")
|
||||||
mainScreen.init(true)
|
mainScreen.init(false)
|
||||||
}else{
|
}else{
|
||||||
initByUpdate = true
|
initByUpdate = true
|
||||||
console.log("Checking if version "+version+" is outdated...")
|
console.log("Checking if version "+version+" is outdated...")
|
||||||
bootstrapModules.splashScreen.initSplash()
|
bootstrapModules.splashScreen.initSplash()
|
||||||
bootstrapModules.splashScreen.events.on("SPLASH_SCREEN_READY", () => {
|
bootstrapModules.splashScreen.events.on("SPLASH_SCREEN_READY", () => {
|
||||||
request.get({
|
fetch("https://haste.deroku.xyz/raw/oqigetomog", {
|
||||||
url: "https://haste.deroku.xyz/raw/oqigetomog",
|
headers: {
|
||||||
body: "json"
|
"User-Agent": "Lightcord-Updater/1.0"
|
||||||
}, (err, res, body) => {
|
}
|
||||||
if(err || res.statusCode !== 200){
|
}).then(async res => {
|
||||||
|
const body = await res.json()
|
||||||
|
if(res.status !== 200){
|
||||||
console.error("Couldn't check updates. Using installed version.")
|
console.error("Couldn't check updates. Using installed version.")
|
||||||
console.log(body)
|
|
||||||
bootstrapModules.splashScreen.launchMainWindow()
|
bootstrapModules.splashScreen.launchMainWindow()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
global.appSettings.set("LAST_UPDATE_CHECK_TIMESTAMP", Date.now())
|
global.appSettings.set("LAST_UPDATE_CHECK_TIMESTAMP", Date.now())
|
||||||
global.appSettings.save()
|
global.appSettings.save()
|
||||||
if(body.version !== version){
|
if(body.version > version){
|
||||||
console.error("App Outdated. Please update.")
|
console.error("App Outdated. updating...")
|
||||||
|
bootstrapModules.splashScreen.updateSplashState("update-available")
|
||||||
|
updateApp()
|
||||||
|
}else{
|
||||||
|
console.error("Latest version already installed. Opening window.")
|
||||||
bootstrapModules.splashScreen.launchMainWindow()
|
bootstrapModules.splashScreen.launchMainWindow()
|
||||||
}
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("Couldn't check updates. Using installed version.")
|
||||||
|
console.log(err)
|
||||||
|
bootstrapModules.splashScreen.launchMainWindow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -107,4 +117,29 @@ function handleSingleInstance(args) {
|
||||||
|
|
||||||
function setMainWindowVisible(visible) {
|
function setMainWindowVisible(visible) {
|
||||||
mainScreen.setMainWindowVisible(visible);
|
mainScreen.setMainWindowVisible(visible);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateApp(version){
|
||||||
|
const bootstrapModules = require('./bootstrapModules')
|
||||||
|
const updateLink = "https://github.com/Lightcord/Lightcord/archive/master.zip"
|
||||||
|
|
||||||
|
bootstrapModules.splashScreen.setSplashState({
|
||||||
|
status: "downloading-updates",
|
||||||
|
progress: 0
|
||||||
|
})
|
||||||
|
|
||||||
|
bootstrapModules.splashScreen.setSplashState({
|
||||||
|
status: "update-manually"
|
||||||
|
})
|
||||||
|
bootstrapModules.splashScreen.focusWindow()
|
||||||
|
delete global.appSettings.settings["LAST_UPDATE_CHECK_TIMESTAMP"]
|
||||||
|
global.appSettings.save()
|
||||||
|
return
|
||||||
|
|
||||||
|
// TODO: DOWNLOAD UPDATES AUTOMATICALLY
|
||||||
|
fetch(updateLink)
|
||||||
|
.then(async res => {
|
||||||
|
if(res.status !== 200){
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
|
@ -340,7 +340,7 @@ function launchMainAppWindow(isVisible) {
|
||||||
height: DEFAULT_HEIGHT,
|
height: DEFAULT_HEIGHT,
|
||||||
minWidth: MIN_WIDTH,
|
minWidth: MIN_WIDTH,
|
||||||
minHeight: MIN_HEIGHT,
|
minHeight: MIN_HEIGHT,
|
||||||
transparent: true,
|
transparent: false,
|
||||||
frame: false,
|
frame: false,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
show: isVisible,
|
show: isVisible,
|
||||||
|
|
|
@ -76,6 +76,10 @@ process.once('loaded', () => {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}catch(e){}
|
}catch(e){}
|
||||||
|
setTimeout(() => {
|
||||||
|
electron.remote.getCurrentWindow().setBackgroundColor("#00000000")
|
||||||
|
electron.remote.getCurrentWindow().center()
|
||||||
|
}, 500);
|
||||||
})
|
})
|
||||||
|
|
||||||
const webRequest = electron.remote.getCurrentWebContents().session.webRequest
|
const webRequest = electron.remote.getCurrentWebContents().session.webRequest
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Discord Loader</title>
|
<title>Lightcord Loader</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="splash-mount"></div>
|
<div id="splash-mount"></div>
|
||||||
|
|
8519
splash/index.js
8519
splash/index.js
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1,7 +1,3 @@
|
||||||
exports.initSplash = initSplash;
|
|
||||||
exports.focusWindow = focusWindow;
|
|
||||||
exports.pageReady = pageReady;
|
|
||||||
|
|
||||||
import * as electron from "electron"
|
import * as electron from "electron"
|
||||||
import {EventEmitter} from "events"
|
import {EventEmitter} from "events"
|
||||||
import * as fs from "fs"
|
import * as fs from "fs"
|
||||||
|
@ -26,23 +22,32 @@ export const APP_SHOULD_SHOW = 'APP_SHOULD_SHOW';
|
||||||
export const events = new EventEmitter();
|
export const events = new EventEmitter();
|
||||||
|
|
||||||
function webContentsSend(win, event, ...args) {
|
function webContentsSend(win, event, ...args) {
|
||||||
|
if(event === "SPLASH_UPDATE_STATE")lastStatus = args[0].status
|
||||||
if (win != null && win.webContents != null) {
|
if (win != null && win.webContents != null) {
|
||||||
win.webContents.send(`DISCORD_${event}`, ...args);
|
win.webContents.send(`DISCORD_${event}`, ...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let splashWindow;
|
let splashWindow:electron.BrowserWindow;
|
||||||
let modulesListeners;
|
let modulesListeners;
|
||||||
let splashState;
|
let splashState;
|
||||||
let launchedMainWindow;
|
let launchedMainWindow;
|
||||||
let quoteCachePath;
|
let quoteCachePath;
|
||||||
|
let lastStatus
|
||||||
|
|
||||||
exports.launchMainWindow = function(){
|
export function setSplashState(state:any){
|
||||||
launchMainWindow();
|
splashState = state
|
||||||
|
if (splashWindow != null && !splashWindow.isDestroyed() && !splashWindow.webContents.isDestroyed()) {
|
||||||
|
webContentsSend(splashWindow, 'SPLASH_UPDATE_STATE', Object.assign({ status: lastStatus }, splashState));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function launchMainWindow(){
|
||||||
|
launchMainWindowInternal();
|
||||||
updateSplashState(LAUNCHING);
|
updateSplashState(LAUNCHING);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initSplash(startMinimized = false) {
|
export function initSplash(startMinimized = false) {
|
||||||
modulesListeners = {};
|
modulesListeners = {};
|
||||||
splashState = {};
|
splashState = {};
|
||||||
launchedMainWindow = false;
|
launchedMainWindow = false;
|
||||||
|
@ -81,14 +86,13 @@ function removeModulesListeners() {
|
||||||
moduleUpdater.events.removeListener(event, modulesListeners[event]);
|
moduleUpdater.events.removeListener(event, modulesListeners[event]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export function updateSplashState(event) {
|
||||||
function updateSplashState(event) {
|
|
||||||
if (splashWindow != null && !splashWindow.isDestroyed() && !splashWindow.webContents.isDestroyed()) {
|
if (splashWindow != null && !splashWindow.isDestroyed() && !splashWindow.webContents.isDestroyed()) {
|
||||||
webContentsSend(splashWindow, 'SPLASH_UPDATE_STATE', Object.assign({ status: event }, splashState));
|
webContentsSend(splashWindow, 'SPLASH_UPDATE_STATE', Object.assign({ status: event }, splashState));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function launchSplashWindow(startMinimized) {
|
function launchSplashWindow(startMinimized = false) {
|
||||||
const windowConfig = {
|
const windowConfig = {
|
||||||
width: LOADING_WINDOW_WIDTH,
|
width: LOADING_WINDOW_WIDTH,
|
||||||
height: LOADING_WINDOW_HEIGHT,
|
height: LOADING_WINDOW_HEIGHT,
|
||||||
|
@ -99,7 +103,8 @@ function launchSplashWindow(startMinimized) {
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true
|
nodeIntegration: true
|
||||||
}
|
},
|
||||||
|
icon: path.join(__dirname, "..", "discord.png")
|
||||||
};
|
};
|
||||||
|
|
||||||
splashWindow = new electron.BrowserWindow(windowConfig);
|
splashWindow = new electron.BrowserWindow(windowConfig);
|
||||||
|
@ -140,6 +145,9 @@ function launchSplashWindow(startMinimized) {
|
||||||
|
|
||||||
events.emit("SPLASH_SCREEN_READY")
|
events.emit("SPLASH_SCREEN_READY")
|
||||||
});
|
});
|
||||||
|
ipcMain.default.on('LAUNCH_ANYWAY', () => {
|
||||||
|
launchMainWindowInternal()
|
||||||
|
});
|
||||||
|
|
||||||
const splashUrl = url.format({
|
const splashUrl = url.format({
|
||||||
protocol: 'file',
|
protocol: 'file',
|
||||||
|
@ -150,7 +158,7 @@ function launchSplashWindow(startMinimized) {
|
||||||
splashWindow.loadURL(splashUrl);
|
splashWindow.loadURL(splashUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
function launchMainWindow() {
|
function launchMainWindowInternal() {
|
||||||
removeModulesListeners();
|
removeModulesListeners();
|
||||||
if (!launchedMainWindow && splashWindow != null) {
|
if (!launchedMainWindow && splashWindow != null) {
|
||||||
launchedMainWindow = true;
|
launchedMainWindow = true;
|
||||||
|
@ -160,13 +168,13 @@ function launchMainWindow() {
|
||||||
|
|
||||||
function scheduleUpdateCheck() {}
|
function scheduleUpdateCheck() {}
|
||||||
|
|
||||||
function focusWindow() {
|
export function focusWindow() {
|
||||||
if (splashWindow != null) {
|
if (splashWindow != null) {
|
||||||
splashWindow.focus();
|
splashWindow.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageReady() {
|
export function pageReady() {
|
||||||
destroySplash();
|
destroySplash();
|
||||||
process.nextTick(() => events.emit(APP_SHOULD_SHOW));
|
process.nextTick(() => events.emit(APP_SHOULD_SHOW));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue