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