mirror of
https://github.com/PreMiD/PreMiD.git
synced 2026-04-06 04:41:58 +02:00
♻ cmd.exe (updater) > PreMiD-Updater.exe
This commit is contained in:
6
.github/workflows/deploy.yml
vendored
6
.github/workflows/deploy.yml
vendored
@@ -83,9 +83,9 @@ jobs:
|
||||
mv upgrader.app.tgz ../
|
||||
rm -rf upgrader.app upgrader.app.zip
|
||||
unzip windows-latest.zip
|
||||
cp updater.exe windows-latest/PreMiD-win32-x64/updater.exe
|
||||
cp PreMiD-Updater.exe windows-latest/PreMiD-win32-x64/PreMiD-Updater.exe
|
||||
cp update.ini windows-latest/PreMiD-win32-x64/update.ini
|
||||
cp updater.exe windows-latest/PreMiD-win32-ia32/updater.exe
|
||||
cp PreMiD-Updater.exe windows-latest/PreMiD-win32-ia32/PreMiD-Updater.exe
|
||||
cp update.ini windows-latest/PreMiD-win32-ia32/update.ini
|
||||
cd windows-latest/PreMiD-win32-x64/
|
||||
zip -r ../../PreMiD-win32-x64.zip .
|
||||
@@ -96,7 +96,7 @@ jobs:
|
||||
cd ../..
|
||||
rm -rf windows-latest windows-latest.zip
|
||||
unzip macOS-latest.zip
|
||||
cp -r updater.app macOS-latest/PreMiD-darwin-x64/updater.app
|
||||
cp -r PreMiD-Updater.app macOS-latest/PreMiD-darwin-x64/PreMiD-Updater.app
|
||||
cp update.ini macOS-latest/PreMiD-darwin-x64/update.ini
|
||||
cd macOS-latest/PreMiD-darwin-x64/
|
||||
zip -r ../../PreMiD-darwin-x64.zip .
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
<vendor>Timeraa</vendor>
|
||||
<version>2.0</version>
|
||||
<singleInstanceCheck>1</singleInstanceCheck>
|
||||
<requestedExecutionLevel>asInvoker</requestedExecutionLevel>
|
||||
<enableSslSupport>1</enableSslSupport>
|
||||
<outputDirectory>../dist/app/</outputDirectory>
|
||||
<installerFilename>updater.${platform_exec_suffix}</installerFilename>
|
||||
<installerFilename>PreMiD-Updater.${platform_exec_suffix}</installerFilename>
|
||||
<osxPlatforms>osx-intel osx-x86_64</osxPlatforms>
|
||||
<createOsxBundleZip>1</createOsxBundleZip>
|
||||
<windowsExecutableIcon>appIcon.ico</windowsExecutableIcon>
|
||||
<osxApplicationBundleIcon>appIcon.icns</osxApplicationBundleIcon>
|
||||
</autoUpdateProject>
|
||||
@@ -7,7 +7,7 @@
|
||||
"scripts": {
|
||||
"init": "tsc --skipLibCheck && tsc pkg util/prepare util/zip && devScript --copyOnly",
|
||||
"start": "electron dist/app/.",
|
||||
"dev": "devScript",
|
||||
"dev": "nodemon --exec yarn start -S --watch dist/app",
|
||||
"pkg": "rimraf dist && tsc --skipLibCheck && devScript --copyOnly && cd dist/app/ && yarn && cd ../../ && node pkg",
|
||||
"deploy": "tsc --skipLibCheck .github/deploy && cd .github && node deploy.js"
|
||||
},
|
||||
@@ -49,7 +49,6 @@
|
||||
"axios": "0.19.2",
|
||||
"discord-rpc": "github:discordjs/RPC",
|
||||
"electron-store": "5.1.0",
|
||||
"socket.io": "2.3.0",
|
||||
"sudo-prompt": "9.1.1"
|
||||
"socket.io": "2.3.0"
|
||||
}
|
||||
}
|
||||
|
||||
20
src/index.ts
20
src/index.ts
@@ -1,12 +1,13 @@
|
||||
import { app, dialog } from "electron";
|
||||
//* Source .map support if devEnv
|
||||
if (!app.isPackaged) require("source-map-support").install();
|
||||
import "source-map-support/register";
|
||||
|
||||
import { app, dialog } from "electron";
|
||||
import { init as initSocket, socket } from "./managers/socketManager";
|
||||
import { init as initTray } from "./managers/trayManager";
|
||||
import { update as initAutoLaunch } from "./managers/launchManager";
|
||||
import { platform } from "os";
|
||||
import { checkForUpdate } from "./util/updateChecker";
|
||||
import { TrayManager } from "./managers/trayManager";
|
||||
|
||||
export let trayManager: TrayManager;
|
||||
|
||||
//* Define and set it to null
|
||||
//* Set AppUserModelId for task manager etc
|
||||
@@ -14,13 +15,10 @@ import { checkForUpdate } from "./util/updateChecker";
|
||||
export let updateCheckerInterval = null;
|
||||
app.setAppUserModelId("Timeraa.PreMiD");
|
||||
app.whenReady().then(async () => {
|
||||
//* Init auto launch
|
||||
//* Check for updates > Update and relaunch
|
||||
//* Init socket
|
||||
//* init application tray icon
|
||||
//* If app is packaged, run an update check every 15 mins
|
||||
initAutoLaunch();
|
||||
await Promise.all([checkForUpdate(true), initSocket(), initTray()]);
|
||||
trayManager = new TrayManager();
|
||||
|
||||
await Promise.all([checkForUpdate(true), initAutoLaunch(), initSocket()]);
|
||||
|
||||
app.isPackaged
|
||||
? (updateCheckerInterval = setInterval(checkForUpdate, 15 * 1000 * 60))
|
||||
: undefined;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Client } from "discord-rpc";
|
||||
import { app } from "electron";
|
||||
import { platform } from "os";
|
||||
import { tray } from "./trayManager";
|
||||
import { info } from "../util/debug";
|
||||
|
||||
//* Import custom types
|
||||
import Presence from "../../@types/PreMiD/Presence";
|
||||
import PresenceData from "../../@types/PreMiD/PresenceData";
|
||||
import { trayManager } from "..";
|
||||
|
||||
//* Define Presence array
|
||||
let loggedInPresences: Array<Presence> = [];
|
||||
@@ -16,20 +16,20 @@ let loggedInPresences: Array<Presence> = [];
|
||||
* @param presence PresenceData to set activity
|
||||
*/
|
||||
export function setActivity(presence: PresenceData) {
|
||||
//* If platform is darwin (Mac OS) set trayTitle if theres one
|
||||
//* Check if theres an active RPC connection that we can use
|
||||
//* If we have one, use it
|
||||
//* Else create one and use it
|
||||
//* Show debug
|
||||
if (platform() === "darwin" && presence.trayTitle)
|
||||
tray.setTitle(presence.trayTitle);
|
||||
let rpc = loggedInPresences.find(p => p.clientId === presence.clientId);
|
||||
if (rpc) rpc.rpc.setActivity(presence.presenceData).catch(destroy);
|
||||
else
|
||||
loginPresence(presence.clientId).then(p =>
|
||||
p.rpc.setActivity(presence.presenceData).catch(destroy)
|
||||
);
|
||||
info("setActivity");
|
||||
//* If platform is darwin (Mac OS) set trayTitle if theres one
|
||||
//* Check if theres an active RPC connection that we can use
|
||||
//* If we have one, use it
|
||||
//* Else create one and use it
|
||||
//* Show debug
|
||||
if (platform() === "darwin" && presence.trayTitle)
|
||||
trayManager.tray.setTitle(presence.trayTitle);
|
||||
let rpc = loggedInPresences.find(p => p.clientId === presence.clientId);
|
||||
if (rpc) rpc.rpc.setActivity(presence.presenceData).catch(destroy);
|
||||
else
|
||||
loginPresence(presence.clientId).then(p =>
|
||||
p.rpc.setActivity(presence.presenceData).catch(destroy)
|
||||
);
|
||||
info("setActivity");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,21 +37,21 @@ export function setActivity(presence: PresenceData) {
|
||||
* @param clientId clientId of presence to clear
|
||||
*/
|
||||
export function clearActivity(clientId: string = undefined) {
|
||||
//* Clear tray title
|
||||
//* If clientId set
|
||||
//* Else map through presences and clear them
|
||||
//* Show Debug
|
||||
if (platform() === "darwin") tray.setTitle("");
|
||||
if (clientId) {
|
||||
//* Check if this presence is logged in
|
||||
//* If it is clear its activity
|
||||
//* Return to prevent further actions
|
||||
let pTC = loggedInPresences.find(p => p.clientId === clientId);
|
||||
if (pTC) pTC.rpc.clearActivity().catch(destroy);
|
||||
return;
|
||||
}
|
||||
loggedInPresences.map(p => p.rpc.clearActivity().catch(destroy));
|
||||
info("clearActivity");
|
||||
//* Clear tray title
|
||||
//* If clientId set
|
||||
//* Else map through presences and clear them
|
||||
//* Show Debug
|
||||
if (platform() === "darwin") trayManager.tray.setTitle("");
|
||||
if (clientId) {
|
||||
//* Check if this presence is logged in
|
||||
//* If it is clear its activity
|
||||
//* Return to prevent further actions
|
||||
let pTC = loggedInPresences.find(p => p.clientId === clientId);
|
||||
if (pTC) pTC.rpc.clearActivity().catch(destroy);
|
||||
return;
|
||||
}
|
||||
loggedInPresences.map(p => p.rpc.clearActivity().catch(destroy));
|
||||
info("clearActivity");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,60 +59,61 @@ export function clearActivity(clientId: string = undefined) {
|
||||
* @param clientId client ID of presence
|
||||
*/
|
||||
function loginPresence(clientId: string) {
|
||||
//* Return promise that will resolve to either Presence or null
|
||||
return new Promise<Presence>((resolve, reject) => {
|
||||
//* Create presence object
|
||||
//* Add presence to object
|
||||
//* Try login with client id
|
||||
//* Once RPC connection is ready
|
||||
//* Destroy all clients when Discord closed (My issue #42)
|
||||
let presence: Presence = {
|
||||
clientId: clientId,
|
||||
rpc: new Client({ transport: "ipc" }),
|
||||
ready: false
|
||||
};
|
||||
loggedInPresences.push(presence);
|
||||
presence.rpc.login({ clientId: clientId }).catch(() => {
|
||||
//* If couldn't log in remove it from loggedInPresences
|
||||
//* Reject promise
|
||||
loggedInPresences = loggedInPresences.filter(
|
||||
p => p.clientId !== presence.clientId
|
||||
);
|
||||
reject();
|
||||
});
|
||||
presence.rpc.once("ready", () => {
|
||||
//* Update status
|
||||
//* Resolve with presence
|
||||
presence.ready = true;
|
||||
resolve(presence);
|
||||
});
|
||||
// @ts-ignore
|
||||
presence.rpc.once("disconnected", destroy);
|
||||
});
|
||||
//* Return promise that will resolve to either Presence or null
|
||||
return new Promise<Presence>((resolve, reject) => {
|
||||
//* Create presence object
|
||||
//* Add presence to object
|
||||
//* Try login with client id
|
||||
//* Once RPC connection is ready
|
||||
//* Destroy all clients when Discord closed (My issue #42)
|
||||
let presence: Presence = {
|
||||
clientId: clientId,
|
||||
rpc: new Client({ transport: "ipc" }),
|
||||
ready: false
|
||||
};
|
||||
loggedInPresences.push(presence);
|
||||
presence.rpc.login({ clientId: clientId }).catch(() => {
|
||||
//* If couldn't log in remove it from loggedInPresences
|
||||
//* Reject promise
|
||||
loggedInPresences = loggedInPresences.filter(
|
||||
p => p.clientId !== presence.clientId
|
||||
);
|
||||
reject();
|
||||
});
|
||||
presence.rpc.once("ready", () => {
|
||||
//* Update status
|
||||
//* Resolve with presence
|
||||
presence.ready = true;
|
||||
resolve(presence);
|
||||
});
|
||||
// @ts-ignore
|
||||
presence.rpc.once("disconnected", destroy);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroys all rpc connections
|
||||
*/
|
||||
export function destroy() {
|
||||
//* Clear tray title
|
||||
//* Map through loggedInPresences and destroy their rpcs
|
||||
//* Set loggedInPresences to new Array
|
||||
//* Return the promise
|
||||
if (platform() === "darwin" && typeof tray !== "undefined") tray.setTitle("");
|
||||
let res = Promise.all(
|
||||
loggedInPresences.map((presence: Presence) =>
|
||||
presence.rpc.destroy().catch(() => {})
|
||||
)
|
||||
);
|
||||
loggedInPresences = [];
|
||||
return res;
|
||||
//* Clear tray title
|
||||
//* Map through loggedInPresences and destroy their rpcs
|
||||
//* Set loggedInPresences to new Array
|
||||
//* Return the promise
|
||||
if (platform() === "darwin" && typeof trayManager.tray !== "undefined")
|
||||
trayManager.tray.setTitle("");
|
||||
let res = Promise.all(
|
||||
loggedInPresences.map((presence: Presence) =>
|
||||
presence.rpc.destroy().catch(() => {})
|
||||
)
|
||||
);
|
||||
loggedInPresences = [];
|
||||
return res;
|
||||
}
|
||||
|
||||
//* if app will quit
|
||||
app.once("will-quit", () => {
|
||||
//* Show debug
|
||||
//* Destroy all connections
|
||||
info("Closing rpc connections");
|
||||
destroy();
|
||||
//* Show debug
|
||||
//* Destroy all connections
|
||||
info("Closing rpc connections");
|
||||
destroy();
|
||||
});
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import ElectronStore from "electron-store";
|
||||
import { tray } from "./trayManager";
|
||||
import { update as updateAutoLaunch } from "./launchManager";
|
||||
import { platform } from "os";
|
||||
import { info } from "../util/debug";
|
||||
|
||||
//* Import custom types
|
||||
import ExtensionSettings from "../../@types/PreMiD/ExtensionSettings";
|
||||
import { trayManager } from "..";
|
||||
|
||||
//* Export and set default settings
|
||||
export let settings = new ElectronStore({
|
||||
defaults: {
|
||||
autoLaunch: true
|
||||
}
|
||||
defaults: {
|
||||
autoLaunch: true
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -19,15 +19,15 @@ export let settings = new ElectronStore({
|
||||
* @param extensionSettings Settings from extension
|
||||
*/
|
||||
export function update(extensionSettings: ExtensionSettings) {
|
||||
//* Show debug
|
||||
//* remove title if disabled
|
||||
//* Update autolaunch if updated
|
||||
//* Save Settings
|
||||
info("Updated settings");
|
||||
if (!extensionSettings.titleMenubar && platform() === "darwin")
|
||||
tray.setTitle("");
|
||||
if (settings.get("autoLaunch") != extensionSettings.autoLaunch) {
|
||||
settings.set("autoLaunch", extensionSettings.autoLaunch);
|
||||
updateAutoLaunch();
|
||||
}
|
||||
//* Show debug
|
||||
//* remove title if disabled
|
||||
//* Update autolaunch if updated
|
||||
//* Save Settings
|
||||
info("Updated settings");
|
||||
if (!extensionSettings.titleMenubar && platform() === "darwin")
|
||||
trayManager.tray.setTitle("");
|
||||
if (settings.get("autoLaunch") != extensionSettings.autoLaunch) {
|
||||
settings.set("autoLaunch", extensionSettings.autoLaunch);
|
||||
updateAutoLaunch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
import { Menu, Tray } from "electron";
|
||||
import { join } from "path";
|
||||
import { platform } from "os";
|
||||
|
||||
//* Export tray
|
||||
//* Export trayContextMenu
|
||||
export let tray: Tray;
|
||||
export let trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
role: "quit"
|
||||
}
|
||||
]);
|
||||
export class TrayManager {
|
||||
tray: Tray;
|
||||
trayContextMenu: Menu;
|
||||
|
||||
/**
|
||||
* Create tray
|
||||
*/
|
||||
export function init() {
|
||||
//* Return promise resolves to Tray
|
||||
return new Promise<Tray>(function(resolve) {
|
||||
//* Create Tray
|
||||
//* Set its context menu
|
||||
//* Resolve promise
|
||||
tray = new Tray(join(__dirname, "../assets/tray/IconTemplate.png"));
|
||||
tray.setContextMenu(trayContextMenu);
|
||||
resolve(tray);
|
||||
});
|
||||
constructor() {
|
||||
this.trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
role: "quit"
|
||||
}
|
||||
]);
|
||||
|
||||
this.tray = new Tray(join(__dirname, "../assets/tray/IconTemplate.png"));
|
||||
this.tray.setContextMenu(this.trayContextMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
import { exec } from "child_process";
|
||||
import { resolve } from "path";
|
||||
import { error, info } from "./debug";
|
||||
import { trayContextMenu } from "../managers/trayManager";
|
||||
import { MenuItem, app, dialog } from "electron";
|
||||
import { tray } from "../managers/trayManager";
|
||||
import { platform } from "os";
|
||||
import sudoPrompt from "sudo-prompt";
|
||||
import axios from "axios";
|
||||
import { Notification } from "electron";
|
||||
import { trayManager } from "..";
|
||||
|
||||
let updaterPath: string;
|
||||
//* Resolve paths for each OS
|
||||
switch (platform()) {
|
||||
case "darwin":
|
||||
updaterPath = resolve(
|
||||
`${app.getAppPath()}../../../../../updater.app/Contents/MacOS/installbuilder.sh`
|
||||
`${app.getAppPath()}../../../../../PreMiD-Updater.app/Contents/MacOS/installbuilder.sh`
|
||||
);
|
||||
break;
|
||||
case "win32":
|
||||
updaterPath = resolve(`${app.getAppPath()}../../../updater.exe`);
|
||||
updaterPath = resolve(`${app.getAppPath()}../../../PreMiD-Updater.exe`);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -70,22 +68,15 @@ export function update() {
|
||||
return;
|
||||
}
|
||||
|
||||
sudoPrompt.exec(
|
||||
exec(
|
||||
`\"${updaterPath}\" --mode unattended --unattendedmodebehavior download`,
|
||||
{
|
||||
name: app.name,
|
||||
icns: "assets/appIcon.icns"
|
||||
},
|
||||
err => {
|
||||
// @ts-ignore
|
||||
if (err.message === "User did not grant permission.") {
|
||||
// @ts-ignore
|
||||
error(err.message);
|
||||
addTray();
|
||||
} else
|
||||
dialog.showErrorBox(
|
||||
"Error while updating",
|
||||
// @ts-ignore
|
||||
`${app.name} was unable to update itself. Please try again later.\n\nError: ${err.message}`
|
||||
);
|
||||
}
|
||||
@@ -93,8 +84,8 @@ export function update() {
|
||||
}
|
||||
|
||||
function addTray() {
|
||||
if (trayContextMenu.items.length < 3) {
|
||||
trayContextMenu.insert(
|
||||
if (trayManager.trayContextMenu.items.length < 3) {
|
||||
trayManager.trayContextMenu.insert(
|
||||
0,
|
||||
new MenuItem({
|
||||
label: "Update available!",
|
||||
@@ -104,12 +95,12 @@ function addTray() {
|
||||
})
|
||||
);
|
||||
|
||||
trayContextMenu.insert(
|
||||
trayManager.trayContextMenu.insert(
|
||||
1,
|
||||
new MenuItem({
|
||||
type: "separator"
|
||||
})
|
||||
);
|
||||
tray.setContextMenu(trayContextMenu);
|
||||
trayManager.tray.setContextMenu(trayManager.trayContextMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es2018",
|
||||
"moduleResolution": "node",
|
||||
"inlineSourceMap": true,
|
||||
"outDir": "dist/app",
|
||||
"removeComments": true,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": [
|
||||
"**/node_modules/",
|
||||
"pkg.ts",
|
||||
"util/**/*",
|
||||
"installer_assets/builder.ts",
|
||||
|
||||
@@ -2530,11 +2530,6 @@ strip-json-comments@~2.0.1:
|
||||
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"
|
||||
integrity sha1-PFMZQukIwml8DsNEhYwobHygpgo=
|
||||
|
||||
sudo-prompt@9.1.1:
|
||||
version "9.1.1"
|
||||
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-9.1.1.tgz#73853d729770392caec029e2470db9c221754db0"
|
||||
integrity sha512-es33J1g2HjMpyAhz8lOR+ICmXXAqTuKbuXuUWLhOLew20oN9oUCgCJx615U/v7aioZg7IX5lIh9x34vwneu4pA==
|
||||
|
||||
sumchecker@^3.0.1:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-3.0.1.tgz#6377e996795abb0b6d348e9b3e1dfb24345a8e42"
|
||||
|
||||
Reference in New Issue
Block a user