Skip to content

Commit

Permalink
fix most eslint error (and ignore some others 🙈)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Schuettler <[email protected]>
  • Loading branch information
mschuettlerTNG committed Jan 24, 2025
1 parent 1097cda commit 4f7572d
Show file tree
Hide file tree
Showing 50 changed files with 2,500 additions and 1,206 deletions.
9 changes: 1 addition & 8 deletions WebUI/build/scripts/provide-electron-build-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ function copyFiles(targetDir, ...files) {
}
}

function copyDirectories(targetDir, ...dirs) {
for (const dir of dirs) {
fs.cpSync(dir, path.join(targetDir, path.basename(dir)), { recursive: true });
console.log('Copied:', dir, 'to:', path.join(targetDir, path.basename(dir)));
}
}

function clearPreviousZip(zipFilePath) {
if
(fs.existsSync(zipFilePath)) {
console.log('Removing previous zip file:', zipFilePath)<
console.log('Removing previous zip file:', zipFilePath)
fs.rmSync(zipFilePath, { recursive: true });
}
}
Expand Down
155 changes: 78 additions & 77 deletions WebUI/electron/electron-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,78 @@
/// <reference types="vite-plugin-electron/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* ├─┬─┬ dist
* │ │ └── index.html
* │ │
* │ ├─┬ dist-electron
* │ │ ├── main.js
* │ │ └── preload.js
* │
* ```
*/
DIST: string;
/** /dist/ or /public/ */
VITE_PUBLIC: string;
}
}

// Used in Renderer process, expose in `preload.ts`
interface Window {
ipcRenderer: import("electron").IpcRenderer;
}

type KVObject = {
[key: string]: any;
};

type Theme = 'dark' | 'lnl' | 'bmg';

type LocalSettings = {
debug: number;
comfyUiParameters?:string[];
} & KVObject;

type ThemeSettings = {
availableThemes: Theme[];
currentTheme: Theme;
}

type ModelPaths = {
llm: string,
embedding: string,
stableDiffusion: string,
inpaint: string,
lora: string,
vae: string,
} & StringKV

type ModelLists = {
llm: string[],
stableDiffusion: string[],
lora: string[],
vae: string[],
scheduler: string[],
embedding: string[],
inpaint: string[]
} & { [key: string]: Array<string> }

type SetupData = {
modelPaths: ModelPaths,
modelLists: ModelLists,
isAdminExec:boolean,
version:string,
}

type UpdateWorkflowsFromIntelResult = {
success: boolean
backupDir: string
}

type BackendStatus = 'notYetStarted' | 'starting' | 'running' | 'stopped' | 'stopping' | 'failed' | 'notInstalled' | 'installationFailed' | 'installing' | 'uninitializedStatus'

/// <reference types="vite-plugin-electron/electron-env" />

declare namespace NodeJS {
interface ProcessEnv {
/**
* The built directory structure
*
* ```tree
* ├─┬─┬ dist
* │ │ └── index.html
* │ │
* │ ├─┬ dist-electron
* │ │ ├── main.js
* │ │ └── preload.js
* │
* ```
*/
DIST: string;
/** /dist/ or /public/ */
VITE_PUBLIC: string;
}
}

// Used in Renderer process, expose in `preload.ts`
interface Window {
ipcRenderer: import("electron").IpcRenderer;
}

type KVObject = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};

type Theme = 'dark' | 'lnl' | 'bmg';

type LocalSettings = {
debug: number;
comfyUiParameters?:string[];
} & KVObject;

type ThemeSettings = {
availableThemes: Theme[];
currentTheme: Theme;
}

type ModelPaths = {
llm: string,
embedding: string,
stableDiffusion: string,
inpaint: string,
lora: string,
vae: string,
} & StringKV

type ModelLists = {
llm: string[],
stableDiffusion: string[],
lora: string[],
vae: string[],
scheduler: string[],
embedding: string[],
inpaint: string[]
} & { [key: string]: Array<string> }

type SetupData = {
modelPaths: ModelPaths,
modelLists: ModelLists,
isAdminExec:boolean,
version:string,
}

type UpdateWorkflowsFromIntelResult = {
success: boolean
backupDir: string
}

type BackendStatus = 'notYetStarted' | 'starting' | 'running' | 'stopped' | 'stopping' | 'failed' | 'notInstalled' | 'installationFailed' | 'installing' | 'uninitializedStatus'

194 changes: 97 additions & 97 deletions WebUI/electron/logging/logger.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
import WebContents = Electron.WebContents;
import fs from "fs";
import path from "node:path";
import {app} from "electron";


class Logger {
webContents: WebContents | null = null
private pathToLogFiles: string = path.resolve(app.isPackaged ? process.resourcesPath : path.join(__dirname, "../../external/"));
private startupMessageCache: {
message: string,
source: string,
level: 'error' | 'warn' | 'info'
}[] = []

constructor() {
}

onWebcontentReady(webContents: WebContents) {
this.webContents = webContents
this.startupMessageCache.forEach((logEntry) => {
this.webContents!.send('debugLog', logEntry)
});
this.startupMessageCache = []
}

info(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}
console.info(`[${source}]: ${message}`);
if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'info', source, message})
} catch (error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'info', source, message})
}
}

warn(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}
console.warn(`[${source}]: ${message}`);
if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'warn', source, message})
} catch (error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'error', source, message})
}
}

error(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}

console.error(`[${source}]: ${message}`);

if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'error', source, message})
} catch (error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'error', source, message})
}
}


logMessageToFile(message: string, source: string) {
const fileName = `${this.getDebugFileName()}.log`
const currentDate = new Date();
const hours = currentDate.getHours().toString().padStart(2, '0');
const minutes = currentDate.getMinutes().toString().padStart(2, '0');
const seconds = currentDate.getSeconds().toString().padStart(2, '0');

const formattedTime = `${hours}:${minutes}:${seconds}`;
const logMessage = `${formattedTime}|${source}|${message}`
fs.appendFileSync(path.join(this.pathToLogFiles, fileName), logMessage + "\r\n");
}

getDebugFileName(): string {
const currentDate = new Date();
const formattedDate = currentDate.toISOString().split('T')[0];
return `aip-${formattedDate}`
}
}

export const appLoggerInstance = new Logger()
import WebContents = Electron.WebContents;
import fs from "fs";
import path from "node:path";
import {app} from "electron";


class Logger {
webContents: WebContents | null = null
private pathToLogFiles: string = path.resolve(app.isPackaged ? process.resourcesPath : path.join(__dirname, "../../external/"));
private startupMessageCache: {
message: string,
source: string,
level: 'error' | 'warn' | 'info'
}[] = []

constructor() {
}

onWebcontentReady(webContents: WebContents) {
this.webContents = webContents
this.startupMessageCache.forEach((logEntry) => {
this.webContents!.send('debugLog', logEntry)
});
this.startupMessageCache = []
}

info(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}
console.info(`[${source}]: ${message}`);
if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'info', source, message})
} catch (_error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'info', source, message})
}
}

warn(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}
console.warn(`[${source}]: ${message}`);
if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'warn', source, message})
} catch (_error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'error', source, message})
}
}

error(message: string, source: string, alsoLogToFile: boolean = false) {
if (alsoLogToFile) {
this.logMessageToFile(message, source)
}

console.error(`[${source}]: ${message}`);

if (this.webContents) {
try {
this.webContents.send('debugLog', {level: 'error', source, message})
} catch (_error) {
console.error('Could not send debug log to renderer process');
}
} else {
this.startupMessageCache.push({level: 'error', source, message})
}
}


logMessageToFile(message: string, source: string) {
const fileName = `${this.getDebugFileName()}.log`
const currentDate = new Date();
const hours = currentDate.getHours().toString().padStart(2, '0');
const minutes = currentDate.getMinutes().toString().padStart(2, '0');
const seconds = currentDate.getSeconds().toString().padStart(2, '0');

const formattedTime = `${hours}:${minutes}:${seconds}`;
const logMessage = `${formattedTime}|${source}|${message}`
fs.appendFileSync(path.join(this.pathToLogFiles, fileName), logMessage + "\r\n");
}

getDebugFileName(): string {
const currentDate = new Date();
const formattedDate = currentDate.toISOString().split('T')[0];
return `aip-${formattedDate}`
}
}

export const appLoggerInstance = new Logger()
Loading

0 comments on commit 4f7572d

Please sign in to comment.