async plugins fixed

This commit is contained in:
andrei-mihnea-cerbu
2024-11-12 18:05:50 +02:00
parent 4fb58b9727
commit 44df437425
22 changed files with 1690 additions and 2262 deletions
+32 -18
View File
@@ -10,6 +10,17 @@ export class WindowManager {
constructor(mainWindow: BrowserWindow, pathToPagesDir: string) {
this.pathToPagesDir = pathToPagesDir;
this.mainWindow = mainWindow;
this.log('WindowManager initialized.');
}
// Logging helper function
private log(message: string, level: 'log' | 'error' = 'log'): void {
const prefix = '[WindowManager]';
if (level === 'error') {
console.error(`${prefix} ${message}`);
} else {
console.log(`${prefix} ${message}`);
}
}
// Show an alert dialog
@@ -21,8 +32,9 @@ export class WindowManager {
message: message,
buttons: ['OK'],
});
this.log(`Alert displayed with message: "${message}"`);
} else {
console.error('Main window is not available.');
this.log('Main window is not available.', 'error');
}
}
@@ -31,17 +43,17 @@ export class WindowManager {
if (this.mainWindow) {
try {
const destinationPath = path.join(this.pathToPagesDir, `${destination}.html`);
console.log(`Navigating to: ${destinationPath}`);
this.log(`Navigating to: ${destinationPath}`);
// Load the destination HTML file into the main window
await this.mainWindow.loadFile(destinationPath);
console.log(`Navigated to ${destination}`);
this.log(`Navigated to ${destination}`);
} catch (error) {
console.error('Error changing content:', error);
throw error; // Pass the error back to the render process
this.log(`Error changing content: ${error}`, 'error');
throw error; // Pass the error back to the render process
}
} else {
console.error('Main window is not available.');
this.log('Main window is not available.', 'error');
}
}
@@ -51,26 +63,26 @@ export class WindowManager {
properties: ['openDirectory'], // Only allow selecting directories
});
// If the user cancels, result.filePaths will be an empty array
if (result.filePaths && result.filePaths.length > 0) {
this.log(`Directory selected: ${result.filePaths[0]}`);
return result.filePaths[0]; // Return the selected directory path
} else {
console.log('No directory selected.');
this.log('No directory selected.');
return undefined; // Return undefined if no directory was selected
}
}
// Show a file in the explorer
async showFileInExplorer(filePath: string): Promise<void> {
if (filePath && fs.existsSync(filePath)) {
try {
// Use Electron's shell module to show the file in the explorer
shell.showItemInFolder(filePath);
console.log(`Opened file explorer for: ${filePath}`);
this.log(`Opened file explorer for: ${filePath}`);
} catch (error: any) {
console.error(`Error showing file in explorer: ${error.message}`);
this.log(`Error showing file in explorer: ${error.message}`, 'error');
}
} else {
console.error('File path is undefined or does not exist.');
this.log('File path is undefined or does not exist.', 'error');
}
}
@@ -84,9 +96,10 @@ export class WindowManager {
});
if (result.filePaths && result.filePaths.length > 0) {
this.log(`File selected: ${result.filePaths[0]}`);
return result.filePaths[0]; // Return the selected file path
} else {
console.log('No file selected.');
this.log('No file selected.');
return undefined; // Return undefined if no file was selected
}
}
@@ -94,15 +107,14 @@ export class WindowManager {
// Method to display an announcement in a new window
async displayAnnouncement(): Promise<void> {
if (this.announcementWindow) {
// If the window is already open, focus it
this.announcementWindow.focus();
this.log('Announcement window focused.');
return;
}
const mainScreen = require('electron').screen.getPrimaryDisplay();
const { width, height } = mainScreen.size;
// Initialize the announcement window
this.announcementWindow = new BrowserWindow({
width: width / 3,
height: height / 2,
@@ -116,20 +128,22 @@ export class WindowManager {
});
this.announcementWindow.removeMenu();
// Load the announcement page
const announcementPath = path.join(this.pathToPagesDir, 'announcement.html');
await this.announcementWindow.loadFile(announcementPath);
this.log(`Announcement window opened at: ${announcementPath}`);
// Handle window close
this.announcementWindow.on('closed', () => {
this.announcementWindow = null; // Clean up the reference
this.announcementWindow = null;
this.log('Announcement window closed.');
});
}
async closeAnnouncementWindow(): Promise<void> {
if (this.announcementWindow) {
this.announcementWindow.close();
this.log('Announcement window closed by user.');
}
}
}