mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	Add theme loader
This commit is contained in:
		
							parent
							
								
									b7a0d1face
								
							
						
					
					
						commit
						a216475618
					
				
					 4 changed files with 33 additions and 14 deletions
				
			
		|  | @ -11,7 +11,6 @@ import "./shortcuts"; | |||
| export var settings: any; | ||||
| export var customTitlebar: boolean; | ||||
| 
 | ||||
| 
 | ||||
| if (process.platform == "linux") { | ||||
|     if (process.env.$XDG_SESSION_TYPE == "wayland") { | ||||
|         console.log("Wayland specific patches applied."); | ||||
|  |  | |||
|  | @ -28,6 +28,9 @@ const clientMods = { | |||
| }; | ||||
| 
 | ||||
| console.log("ArmCord"); | ||||
| ipcRenderer.on("themeLoader", (event, message) => { | ||||
|     addStyle(message); | ||||
| }); | ||||
| if (window.location.href.indexOf("splash.html") > -1) { | ||||
|     console.log("Skipping titlebar injection and client mod injection."); | ||||
| } else { | ||||
|  |  | |||
|  | @ -52,6 +52,3 @@ export function injectTitlebar() { | |||
|         }); | ||||
|     }); | ||||
| } | ||||
| export function removeTitlebar() { | ||||
|     document.querySelector("#titlebar")!.remove(); | ||||
| } | ||||
|  |  | |||
|  | @ -2,10 +2,11 @@ | |||
| // I had to add most of the window creation code here to split both into seperete functions
 | ||||
| // WHY? Because I can't use the same code for both due to annoying bug with value `frame` not responding to variables
 | ||||
| // I'm sorry for this mess but I'm not sure how to fix it.
 | ||||
| import {BrowserWindow, shell, app, dialog} from "electron"; | ||||
| import { BrowserWindow, shell, app, dialog } from "electron"; | ||||
| import path from "path"; | ||||
| import {checkIfConfigIsBroken, firstRun, getConfig, contentPath, isSetup, setConfig, setLang, setWindowState} from "./utils"; | ||||
| import {registerIpc} from "./ipc"; | ||||
| import { checkIfConfigIsBroken, firstRun, getConfig, contentPath, isSetup, setConfig, setLang, setWindowState } from "./utils"; | ||||
| import { registerIpc } from "./ipc"; | ||||
| import * as fs from "fs"; | ||||
| import startServer from "./socket"; | ||||
| import contextMenu from "electron-context-menu"; | ||||
| import os from "os"; | ||||
|  | @ -30,7 +31,7 @@ async function doAfterDefiningTheWindow() { | |||
|         osType = "Windows " + os.release().split('.')[0] + " (" + os.release() + ")"; | ||||
|     } | ||||
|     mainWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`; //fake useragent for screenshare to work
 | ||||
|     mainWindow.webContents.setWindowOpenHandler(({url}) => { | ||||
|     mainWindow.webContents.setWindowOpenHandler(({ url }) => { | ||||
|         if (url.startsWith("https:" || url.startsWith("http:") || url.startsWith("mailto:"))) { | ||||
|             shell.openExternal(url); | ||||
|         } else { | ||||
|  | @ -48,7 +49,7 @@ async function doAfterDefiningTheWindow() { | |||
|                     checkboxChecked: false | ||||
|                 }; | ||||
| 
 | ||||
|                 dialog.showMessageBox(mainWindow, options).then(({response, checkboxChecked}) => { | ||||
|                 dialog.showMessageBox(mainWindow, options).then(({ response, checkboxChecked }) => { | ||||
|                     console.log(response, checkboxChecked); | ||||
|                     if (checkboxChecked) { | ||||
|                         if (response == 0) { | ||||
|  | @ -65,12 +66,31 @@ async function doAfterDefiningTheWindow() { | |||
|                 }); | ||||
|             } | ||||
|         } | ||||
|         return {action: "deny"}; | ||||
|         return { action: "deny" }; | ||||
|     }); | ||||
|     mainWindow.webContents.session.webRequest.onBeforeRequest((details, callback) => { | ||||
|         if (/api\/v\d\/science$/g.test(details.url)) return callback({cancel: true}); | ||||
|         if (/api\/v\d\/science$/g.test(details.url)) return callback({ cancel: true }); | ||||
|         return callback({}); | ||||
|     }); | ||||
|     const userDataPath = app.getPath("userData"); | ||||
|     const themesFolder = userDataPath + "/themes/"; | ||||
|     if (!fs.existsSync(themesFolder)) { | ||||
|         fs.mkdirSync(themesFolder); | ||||
|         console.log("Created missing theme folder"); | ||||
|     } | ||||
|     mainWindow.webContents.on('did-finish-load', () => { | ||||
|         fs.readdirSync(themesFolder).forEach((file) => { | ||||
|             try { | ||||
|                 const manifest = fs.readFileSync(`${themesFolder}/${file}/manifest.json`, "utf8"); | ||||
|                 var themeFile = JSON.parse(manifest); | ||||
|                 mainWindow.webContents.send("themeLoader", fs.readFileSync(`${themesFolder}/${file}/${themeFile.theme}`, "utf-8")) | ||||
|                 console.log(`%cLoaded ${themeFile.name} made by ${themeFile.author}`, "color:red"); | ||||
|             } catch (err) { | ||||
|                 console.error(err); | ||||
|             } | ||||
|         }); | ||||
|     }); | ||||
| 
 | ||||
|     mainWindow.on("close", async (e) => { | ||||
|         let [width, height] = mainWindow.getSize() | ||||
|         setWindowState({ | ||||
|  | @ -86,10 +106,10 @@ async function doAfterDefiningTheWindow() { | |||
|             app.quit(); | ||||
|         } | ||||
|     }); | ||||
|     mainWindow.on('maximize',() =>{ | ||||
|     mainWindow.on('maximize', () => { | ||||
|         mainWindow.webContents.executeJavaScript(`document.body.setAttribute("isMaximized", "");`) | ||||
|     }) | ||||
|     mainWindow.on('unmaximize',() =>{ | ||||
|     mainWindow.on('unmaximize', () => { | ||||
|         mainWindow.webContents.executeJavaScript(`document.body.removeAttribute("isMaximized");`) | ||||
|     }) | ||||
|     console.log(contentPath); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue