Skip to content

Commit

Permalink
Fixed ur fuckup myles u dickhead
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-GameWorks committed Feb 29, 2024
1 parent 3545b91 commit f13b834
Showing 1 changed file with 15 additions and 132 deletions.
147 changes: 15 additions & 132 deletions client/electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
// The built directory structure
//
// ├─┬ dist-electron
// │ ├─┬ main
// │ │ └── index.js > Electron-Main
// │ └─┬ preload
// │ └── index.js > Preload-Scripts
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//

process.env.DIST_ELECTRON = join(__dirname, "../..");
process.env.DIST = join(process.env.DIST_ELECTRON, "../dist");
process.env.PUBLIC = app.isPackaged
? process.env.DIST
: join(process.env.DIST_ELECTRON, "../public");

import { app, BrowserWindow, shell, ipcMain, dialog } from "electron";
import settings from "electron-settings";
import { release, homedir } from "os";
import path, { join } from "path";
import fs from "fs";
import { app, BrowserWindow, shell } from "electron";
import { join } from "path";
import runIpcStorageEvents from "./ipc/ipcStorageEvents";
import runIpcGameEvents from "./ipc/ipcGameEvents";
import { checkIfGamesDirectoryExists } from "../api/gameManager";
import { autoUpdater } from "electron-updater";
// Disable GPU Acceleration for Windows 7
if (release().startsWith("6.1")) app.disableHardwareAcceleration();

// Set application name for Windows 10+ notifications
if (process.platform === "win32") app.setAppUserModelId(app.getName());

if (!app.requestSingleInstanceLock()) {
app.quit();
process.exit(0);
}
import { checkIfGamesDirectoryExistsAndCreate } from "../api/gameManager";
import { callHandlers, handleExternAuthentication } from "./eventHandlers";
import { globalSetup } from "./globalSetup";

//#region Global Setups
export let win: BrowserWindow | null = null;
// Here, you can also use other preload
const preload = join(__dirname, "../preload/index.js");
const url = process.env.VITE_DEV_SERVER_URL;
const indexHtml = join(process.env.DIST, "index.html");

if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient("select-launcher", process.execPath, [
path.resolve(process.argv[1]),
]);
}
} else {
app.setAsDefaultProtocolClient("select-launcher");
}
globalSetup();
//#endregion

async function createWindow() {
win = new BrowserWindow({
Expand All @@ -65,10 +34,9 @@ async function createWindow() {
minHeight: 500,
});

// Handle dev tools
if (process.env.VITE_DEV_SERVER_URL) {
// electron-vite-vue#298
win.loadURL(url);
// Open devTool if the app is not packaged
win.webContents.openDevTools();
} else {
win.loadFile(indexHtml);
Expand All @@ -78,7 +46,6 @@ async function createWindow() {
win.webContents.on("did-finish-load", () => {
win?.webContents.send("main-process-message", new Date().toLocaleString());
});
win.webContents.setVisualZoomLevelLimits(1, 1);

// Make all links open with the browser, not with the application
win.webContents.setWindowOpenHandler(({ url }) => {
Expand All @@ -87,75 +54,24 @@ async function createWindow() {
});
}

app.on("window-all-closed", () => {
win = null;
if (process.platform !== "darwin") app.quit();
});

const gotTheLock = app.requestSingleInstanceLock();

async function handleFolderOpen() {
const currentLibraryPath = await (
await settings.get("locations.libraryLocation")
).toString();
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
title: "Select Library Location",
defaultPath: currentLibraryPath,
properties: ["openDirectory"],
});
if (canceled) {
return;
} else {
return filePaths[0];
}
}
//#region Handlers
callHandlers(win, preload, indexHtml);

if (!gotTheLock) {
if (!app.requestSingleInstanceLock()) {
app.quit();
} else {
app.on("second-instance", (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore();
win.focus();
win.reload();
console.log(commandLine);
if (commandLine[3].includes("select-launcher://home")) {
dialog.showMessageBox({
type: "info",
title: "Select Launcher",
message: "Account verification successful!",
});
}
}
});
handleExternAuthentication(win);

// Create mainWindow, load the rest of the app, etc...
app.whenReady().then(async () => {
// if (app.isPackaged) {
// await checkForUpdates();
// }

createWindow();

// create game storage directory
if (!checkIfGamesDirectoryExists) {
fs.mkdir(
path.join(settings.getSync("locations.libraryLocation").toString()),
() => console.log("created games folder"),
);
return;
}
checkIfGamesDirectoryExistsAndCreate();

ipcMain.handle("dialog:openFolder", handleFolderOpen);
runIpcStorageEvents();
runIpcGameEvents();
});

// Handle the protocol. In this case, we choose to show an Error Box.
app.on("open-url", (event, url) => {
dialog.showErrorBox("Welcome Back", `You arrived from: ${url}`);
});
}

app.on("activate", () => {
Expand All @@ -166,37 +82,4 @@ app.on("activate", () => {
createWindow();
}
});

// new window example arg: new windows url
ipcMain.handle("open-win", (event, arg) => {
const childWindow = new BrowserWindow({
webPreferences: {
preload,
nodeIntegration: true,
contextIsolation: false,
},
});

if (process.env.VITE_DEV_SERVER_URL) {
childWindow.loadURL(`${url}#${arg}`);
} else {
childWindow.loadFile(indexHtml, { hash: arg });
}
});

app.on("ready", () => {
autoUpdater.checkForUpdatesAndNotify();
});

autoUpdater.on("update-available", (info) => {
win.webContents.send(
"update_available",
`Updates are available! v${info.version} is ready to be installed.\n\nFeel free to use the app while the update is being downloaded.`,
);
});
autoUpdater.on("update-downloaded", () => {
win.webContents.send(
"update_downloaded",
`Update has been downloaded! We will launch the next version when you restart the app.`,
);
});
//#endregion

0 comments on commit f13b834

Please sign in to comment.