mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	Remove legacy config helper functions
This commit is contained in:
		
							parent
							
								
									a39fe281f6
								
							
						
					
					
						commit
						9d2a1190cf
					
				
					 5 changed files with 15 additions and 37 deletions
				
			
		|  | @ -1,7 +1,7 @@ | |||
| //ipc stuff
 | ||||
| import {app, ipcMain, shell, desktopCapturer} from "electron"; | ||||
| import {createTabsGuest, mainWindow} from "./window"; | ||||
| import {saveSettings, getVersion} from "./utils"; | ||||
| import {setConfigBulk, getVersion} from "./utils"; | ||||
| import {settings, customTitlebar, tabs} from "./main"; | ||||
| import {createSettingsWindow} from "./settings/main"; | ||||
| export function registerIpc() { | ||||
|  | @ -46,7 +46,7 @@ export function registerIpc() { | |||
|         app.exit(); | ||||
|     }); | ||||
|     ipcMain.on("saveSettings", (event, args) => { | ||||
|         saveSettings(args); | ||||
|         setConfigBulk(args); | ||||
|     }); | ||||
|     ipcMain.on("minimizeToTray", (event) => { | ||||
|         console.log(settings.minimizeToTray); | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ import {app, BrowserWindow, session, dialog} from "electron"; | |||
| import * as path from "path"; | ||||
| import "v8-compile-cache"; | ||||
| import * as storage from "electron-json-storage"; | ||||
| import {getConfigUnsafe, setup} from "./utils"; | ||||
| import {getConfig, setup} from "./utils"; | ||||
| import "./extensions/mods"; | ||||
| import "./extensions/plugin"; | ||||
| import "./tray"; | ||||
|  | @ -15,7 +15,7 @@ export var settings: any; | |||
| export var customTitlebar: boolean; | ||||
| export var tabs: boolean; | ||||
| async function appendSwitch() { | ||||
|     if ((await getConfigUnsafe("windowStyle")) == "glasstron") { | ||||
|     if ((await getConfig("windowStyle")) == "glasstron") { | ||||
|         console.log("Enabling transparency visuals."); | ||||
|         app.commandLine.appendSwitch("enable-transparent-visuals"); | ||||
|     } | ||||
|  | @ -46,7 +46,7 @@ storage.get("settings", function (error, data: any) { | |||
|     settings = data; | ||||
| }); | ||||
| app.whenReady().then(async () => { | ||||
|     switch (await getConfigUnsafe("windowStyle")) { | ||||
|     switch (await getConfig("windowStyle")) { | ||||
|         case "default": | ||||
|             createCustomWindow(); | ||||
|             customTitlebar = true; | ||||
|  | @ -79,7 +79,7 @@ app.whenReady().then(async () => { | |||
|     }); | ||||
|     app.on("activate", async function () { | ||||
|         if (BrowserWindow.getAllWindows().length === 0) | ||||
|             switch (await getConfigUnsafe("windowStyle")) { | ||||
|             switch (await getConfig("windowStyle")) { | ||||
|                 case "default": | ||||
|                     createCustomWindow(); | ||||
|                     break; | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| import {BrowserWindow, shell, ipcMain, app} from "electron"; | ||||
| import {getConfigUnsafe, saveSettings, Settings} from "../utils"; | ||||
| import {getConfig, setConfigBulk, Settings} from "../utils"; | ||||
| import path from "path"; | ||||
| var settingsWindow: BrowserWindow; | ||||
| var instance: number = 0; | ||||
|  | @ -26,10 +26,10 @@ export function createSettingsWindow() { | |||
|         }); | ||||
|         ipcMain.on("saveSettings", (event, args: Settings) => { | ||||
|             console.log(args); | ||||
|             saveSettings(args); | ||||
|             setConfigBulk(args); | ||||
|         }); | ||||
|         ipcMain.handle("getSetting", (event, toGet: string) => { | ||||
|             return getConfigUnsafe(toGet); | ||||
|             return getConfig(toGet); | ||||
|         }); | ||||
|         settingsWindow.webContents.setWindowOpenHandler(({url}) => { | ||||
|             shell.openExternal(url); | ||||
|  |  | |||
							
								
								
									
										28
									
								
								src/utils.ts
									
										
									
									
									
								
							
							
						
						
									
										28
									
								
								src/utils.ts
									
										
									
									
									
								
							|  | @ -21,7 +21,7 @@ export async function sleep(ms: number) { | |||
| } | ||||
| 
 | ||||
| export async function checkIfConfigIsBroken() { | ||||
|     if ((await getConfigUnsafe("0")) == "d") { | ||||
|     if ((await getConfig("0")) == "d") { | ||||
|         console.log("Detected a corrupted config"); | ||||
|         setup(); | ||||
|         dialog.showErrorBox( | ||||
|  | @ -50,30 +50,8 @@ export function setup() { | |||
|          | ||||
|     ); | ||||
| } | ||||
| //LEGACY WRAPPER
 | ||||
| export function saveSettings(settings: Settings) { | ||||
|     console.log("Setting up ArmCord settings."); | ||||
|     setConfigBulk( | ||||
|         { | ||||
|             ...settings, | ||||
|         }, | ||||
|     ); | ||||
| } | ||||
| //LEGACY
 | ||||
| export async function getConfigUnsafe(object: string) { | ||||
|     try { | ||||
|         const userDataPath = app.getPath("userData"); | ||||
|         const storagePath = path.join(userDataPath, "/storage/"); | ||||
|         let rawdata = fs.readFileSync(storagePath + "settings.json", "utf-8"); | ||||
|         let returndata = JSON.parse(rawdata); | ||||
|         console.log(returndata[object]); | ||||
|         return returndata[object]; | ||||
|     } catch (e) { | ||||
|         console.log("Config probably doesn't exist yet. Returning setup value."); | ||||
|         firstRun = true; | ||||
|         return "setup"; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| export function getVersion() { | ||||
|     //to-do better way of doing this
 | ||||
|     return "3.1.0"; | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
| import {BrowserWindow, shell, app, ipcMain, dialog} from "electron"; | ||||
| import path from "path"; | ||||
| import {contentPath} from "./main"; | ||||
| import {checkIfConfigIsBroken, firstRun, getConfigUnsafe} from "./utils"; | ||||
| import {checkIfConfigIsBroken, firstRun, getConfig} from "./utils"; | ||||
| import {registerIpc} from "./ipc"; | ||||
| import contextMenu from "electron-context-menu"; | ||||
| export let mainWindow: BrowserWindow; | ||||
|  | @ -31,10 +31,10 @@ function doAfterDefiningTheWindow() { | |||
|         return callback({}); | ||||
|     }); | ||||
|     mainWindow.on("close", async (e) => { | ||||
|         if (await getConfigUnsafe("minimizeToTray")) { | ||||
|         if (await getConfig("minimizeToTray")) { | ||||
|             e.preventDefault(); | ||||
|             mainWindow.hide(); | ||||
|         } else if (!(await getConfigUnsafe("minimizeToTray"))) { | ||||
|         } else if (!(await getConfig("minimizeToTray"))) { | ||||
|             e.preventDefault(); | ||||
|             app.quit(); | ||||
|         } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue