♻️ var => let & general bug fixing

This commit is contained in:
Florian Metz
2019-09-21 22:46:01 +02:00
parent 0a101e3b69
commit 4e563b3c05
11 changed files with 38 additions and 28 deletions

View File

@@ -47,6 +47,7 @@ async function fileChange(diagnostic: ts.Diagnostic) {
} else
console.log(chalk.greenBright(ts.formatDiagnostic(diagnostic, formatHost)));
console.log(currChild && currChild.killed);
//* Kill old child if exists && alive
if (currChild && !currChild.killed) currChild.kill();

5
pkg.ts
View File

@@ -27,8 +27,7 @@ electronPackager({
appBundleId: "eu.Timeraa.PreMiD",
appCategoryType: "Utilities",
appCopyright: "Timeraa 2018-2019",
prune: true,
arch: "ia32"
prune: true
}).then(() => {
console.log("Successfully packaged app.");
@@ -83,7 +82,7 @@ electronPackager({
console.log("Creating installer...");
var builder = exec(
`"${bitRockBuilder}" build installer_assets/PreMiD_x32.xml ${
`"${bitRockBuilder}" build installer_assets/PreMiD_x64.xml ${
platform() === "win32" ? "windows" : "osx"
}`
);

View File

@@ -13,7 +13,7 @@ import { info } from "./util/debug";
//* Set AppUserModelId for task manager etc
//* Hide app icon if Mac OS
//* Mac OS truted accessability client
export var updateCheckerInterval = null;
export let updateCheckerInterval = null;
app.setAppUserModelId("Timeraa.PreMiD");
if (platform() === "darwin") {
app.dock.hide();

View File

@@ -6,7 +6,7 @@ import { info } from "../util/debug";
import { init as initKeybinds, deinit as deinitKeybinds } from "./inputManager";
//* Define Presence array
var loggedInPresences: Array<Presence> = [];
let loggedInPresences: Array<Presence> = [];
/**
* Sets the user's activity
@@ -21,8 +21,9 @@ export function setActivity(presence: PresenceData) {
//* Show debug
if (presence.mediaKeys) initKeybinds();
else deinitKeybinds();
if (platform() === "darwin") tray.setTitle(presence.trayTitle);
var rpc = loggedInPresences.find(p => p.clientId === presence.clientId);
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);
else
loginPresence(presence.clientId).then(p =>
@@ -47,7 +48,7 @@ export function clearActivity(clientId: string = undefined) {
//* Check if this presence is logged in
//* If it is clear its activity
//* Return to prevent further actions
var pTC = loggedInPresences.find(p => p.clientId === clientId);
let pTC = loggedInPresences.find(p => p.clientId === clientId);
if (pTC) pTC.rpc.clearActivity();
return;
}
@@ -66,7 +67,8 @@ function loginPresence(clientId: string) {
//* Add presence to object
//* Try login with client id
//* Once RPC connection is ready
var presence: Presence = {
//* Destroy all clients when Discord closed (My issue #42)
let presence: Presence = {
clientId: clientId,
rpc: new Discord.Client({ transport: "ipc" }),
ready: false
@@ -86,6 +88,8 @@ function loginPresence(clientId: string) {
presence.ready = true;
resolve(presence);
});
// @ts-ignore
presence.rpc.once("disconnected", destroy);
});
}
@@ -98,8 +102,10 @@ export function destroy() {
//* Set loggedInPresences to new Array
//* Return the promise
if (platform() === "darwin") tray.setTitle("");
var res = Promise.all(
loggedInPresences.map((presence: Presence) => presence.rpc.destroy())
let res = Promise.all(
loggedInPresences.map((presence: Presence) =>
presence.rpc.destroy().catch(() => {})
)
);
loggedInPresences = [];
return res;

View File

@@ -2,7 +2,7 @@ import { app, globalShortcut } from "electron";
import { socket } from "./socketManager";
import { info, error, success } from "./../util/debug";
var playPauseSwitch = null,
let playPauseSwitch = null,
playPauseTimeout = null;
/**
@@ -20,7 +20,7 @@ export function init() {
globalShortcut.isRegistered("mediaprevioustrack")
)
return;
var mpp = globalShortcut.register("mediaplaypause", () => {
let mpp = globalShortcut.register("mediaplaypause", () => {
//* Return if not connected
//* if playPause timeout not set set it - 500ms timeout > switch play/pause, nextrack/previoustrack
//* Increase switch each press
@@ -56,8 +56,8 @@ export function init() {
*/
function handlePlayPause() {
//* Switch case -> emit
//* Reset switch var
//* Reset timeout var
//* Reset switch let
//* Reset timeout let
switch (playPauseSwitch) {
case 1:
socket.emit("keybinds", { playback: "pause" });

View File

@@ -4,7 +4,7 @@ import { settings } from "./settingsManager";
import { info } from "../util/debug";
//* Create autoLaunch object
var autoLaunch = new AutoLaunch({
let autoLaunch = new AutoLaunch({
name: app.getName(),
isHidden: true
});

View File

@@ -4,7 +4,7 @@ import { socket } from "./socketManager";
import { extname } from "path";
import { info } from "../util/debug";
var presenceDevWatchedFiles = [],
let presenceDevWatchedFiles = [],
currWatchPath = "";
export async function watchDir(path: string) {
@@ -12,7 +12,7 @@ export async function watchDir(path: string) {
//* Set currWatchDir
//* Set watched files to files
//* Add file watcher to each file
var files = await readdirSync(path);
let files = await readdirSync(path);
currWatchPath = path + "/";
presenceDevWatchedFiles = files;
presenceDevWatchedFiles.map(f => {
@@ -54,7 +54,7 @@ export async function openFileDialog() {
//* If user cancels
//* Unwatch all still watched files
//* Watch directory
var filePaths = await dialog.showOpenDialogSync(null, {
let filePaths = await dialog.showOpenDialogSync(null, {
title: "Select Presence Folder",
message:
"Please select the folder that contains the presence you want to load.\n(metadata.json, presence.js, iframe.js)",

View File

@@ -6,7 +6,7 @@ import { deinit as deinitInputs } from "./inputManager";
import { info } from "../util/debug";
//* Export and set default settings
export var settings = new ElectronStore({
export let settings = new ElectronStore({
defaults: {
autoLaunch: true
}

View File

@@ -7,9 +7,9 @@ import { update as updateSettings } from "./settingsManager";
import { openFileDialog } from "./presenceDevManager";
import { setActivity, clearActivity, destroy } from "./discordManager";
export var io: socketIo.Server;
export var socket: socketIo.Socket;
export var server: Server;
export let io: socketIo.Server;
export let socket: socketIo.Socket;
export let server: Server;
export function init() {
return new Promise(resolve => {
@@ -33,11 +33,12 @@ export function init() {
function socketConnection(cSocket: socketIo.Socket) {
//* Show debug
//* Set exported socket variable to current socket
//* Set exported socket letiable to current socket
//* Handle setActivity event
//* Handle clearActivity event
//* Handle settingsUpdate
//* Handle presenceDev
//* Handle version request
//* Once socket user disconnects run cleanup
success("Socket connection");
socket = cSocket;
@@ -45,6 +46,9 @@ function socketConnection(cSocket: socketIo.Socket) {
socket.on("clearActivity", clearActivity);
socket.on("settingUpdate", updateSettings);
socket.on("selectLocalPresence", openFileDialog);
socket.on("getVersion", () =>
socket.emit("receiveVersion", app.getVersion().replace(/[\D]/g, ""))
);
socket.once("disconnect", () => {
//* Show debug
//* Destroy all open RPC connections

View File

@@ -3,8 +3,8 @@ import { join } from "path";
//* Export tray
//* Export trayContextMenu
export var tray: Tray;
export var trayContextMenu = Menu.buildFromTemplate([
export let tray: Tray;
export let trayContextMenu = Menu.buildFromTemplate([
{
role: "quit"
}

View File

@@ -9,7 +9,7 @@ import { updateCheckerInterval } from "../index";
import { existsSync } from "fs";
import sudoPrompt from "sudo-prompt";
var updaterPath: string;
let updaterPath: string;
export async function checkForUpdate(autoUpdate = false) {
if (!app.isPackaged) {
@@ -33,7 +33,7 @@ export async function checkForUpdate(autoUpdate = false) {
return;
}
var child = spawn(updaterPath, ["--mode", "unattended"]);
let child = spawn(updaterPath, ["--mode", "unattended"]);
child.on("error", err => {
// @ts-ignore