Fix desktop application errors
Security and functionality fixes: - Added Content Security Policy to index.html to address Electron security warning - Fixed function name errors: updateImageGallery() -> updateImageGalleryControls() - Enhanced error handling in desktop-file-manager.js path operations - Added null checks for directory initialization to prevent undefined path errors - Fixed category mapping for task/consequence directory access - Improved error logging and user feedback for file operations Fixes resolve: - Electron CSP security warnings - TypeError with undefined path arguments - Missing function reference errors - Desktop import button functionality
This commit is contained in:
parent
1aed657e74
commit
45adf1b757
|
|
@ -16,17 +16,26 @@ class DesktopFileManager {
|
|||
this.isElectron = window.electronAPI !== undefined;
|
||||
|
||||
if (this.isElectron) {
|
||||
this.appPath = await window.electronAPI.getAppPath();
|
||||
this.imageDirectories.tasks = await window.electronAPI.pathJoin(this.appPath, 'images', 'tasks');
|
||||
this.imageDirectories.consequences = await window.electronAPI.pathJoin(this.appPath, 'images', 'consequences');
|
||||
|
||||
// Ensure directories exist
|
||||
await window.electronAPI.createDirectory(this.imageDirectories.tasks);
|
||||
await window.electronAPI.createDirectory(this.imageDirectories.consequences);
|
||||
|
||||
console.log('Desktop file manager initialized');
|
||||
console.log('App path:', this.appPath);
|
||||
console.log('Image directories:', this.imageDirectories);
|
||||
try {
|
||||
this.appPath = await window.electronAPI.getAppPath();
|
||||
if (this.appPath) {
|
||||
this.imageDirectories.tasks = await window.electronAPI.pathJoin(this.appPath, 'images', 'tasks');
|
||||
this.imageDirectories.consequences = await window.electronAPI.pathJoin(this.appPath, 'images', 'consequences');
|
||||
|
||||
// Ensure directories exist
|
||||
await window.electronAPI.createDirectory(this.imageDirectories.tasks);
|
||||
await window.electronAPI.createDirectory(this.imageDirectories.consequences);
|
||||
|
||||
console.log('Desktop file manager initialized');
|
||||
console.log('App path:', this.appPath);
|
||||
console.log('Image directories:', this.imageDirectories);
|
||||
} else {
|
||||
console.error('Failed to get app path');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error initializing desktop file manager:', error);
|
||||
this.isElectron = false;
|
||||
}
|
||||
} else {
|
||||
console.log('Running in browser mode - file manager disabled');
|
||||
}
|
||||
|
|
@ -47,7 +56,13 @@ class DesktopFileManager {
|
|||
}
|
||||
|
||||
const importedImages = [];
|
||||
const targetDir = this.imageDirectories[category];
|
||||
const targetDir = category === 'task' ? this.imageDirectories.tasks : this.imageDirectories.consequences;
|
||||
|
||||
if (!targetDir) {
|
||||
console.error('Target directory not initialized');
|
||||
this.showNotification('Directory not initialized', 'error');
|
||||
return [];
|
||||
}
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const fileName = filePath.split(/[\\/]/).pop();
|
||||
|
|
@ -89,7 +104,13 @@ class DesktopFileManager {
|
|||
}
|
||||
|
||||
try {
|
||||
const targetDir = this.imageDirectories[category];
|
||||
const targetDir = category === 'task' ? this.imageDirectories.tasks : this.imageDirectories.consequences;
|
||||
|
||||
if (!targetDir) {
|
||||
console.error(`Target directory not initialized for ${category}`);
|
||||
return [];
|
||||
}
|
||||
|
||||
const images = await window.electronAPI.readDirectory(targetDir);
|
||||
|
||||
console.log(`Found ${images.length} images in ${category} directory`);
|
||||
|
|
@ -110,8 +131,8 @@ class DesktopFileManager {
|
|||
return { task: [], consequence: [] };
|
||||
}
|
||||
|
||||
const taskImages = await this.scanDirectoryForImages('tasks');
|
||||
const consequenceImages = await this.scanDirectoryForImages('consequences');
|
||||
const taskImages = await this.scanDirectoryForImages('task');
|
||||
const consequenceImages = await this.scanDirectoryForImages('consequence');
|
||||
|
||||
const results = {
|
||||
task: taskImages,
|
||||
|
|
|
|||
6
game.js
6
game.js
|
|
@ -947,7 +947,7 @@ class TaskChallengeGame {
|
|||
newImportTaskBtn.addEventListener('click', async () => {
|
||||
if (this.fileManager) {
|
||||
await this.fileManager.selectAndImportImages('task');
|
||||
this.updateImageGallery();
|
||||
this.updateImageGalleryControls('task');
|
||||
} else {
|
||||
this.showNotification('Desktop file manager not available', 'warning');
|
||||
}
|
||||
|
|
@ -960,7 +960,7 @@ class TaskChallengeGame {
|
|||
newImportConsequenceBtn.addEventListener('click', async () => {
|
||||
if (this.fileManager) {
|
||||
await this.fileManager.selectAndImportImages('consequence');
|
||||
this.updateImageGallery();
|
||||
this.updateImageGalleryControls('consequence');
|
||||
} else {
|
||||
this.showNotification('Desktop file manager not available', 'warning');
|
||||
}
|
||||
|
|
@ -994,7 +994,7 @@ class TaskChallengeGame {
|
|||
if (this.fileManager) {
|
||||
// Use desktop file manager scanning
|
||||
await this.fileManager.scanAllDirectories();
|
||||
this.updateImageGallery();
|
||||
this.updateImageGalleryControls('task');
|
||||
} else {
|
||||
// Fallback to web scanning
|
||||
this.scanForNewImages();
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 1020 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval' data: file:; img-src 'self' data: file:; script-src 'self' 'unsafe-inline' 'unsafe-eval';">
|
||||
<title>Task Challenge Game</title>
|
||||
<link rel="stylesheet" href="styles.css">
|
||||
</head>
|
||||
|
|
|
|||
Loading…
Reference in New Issue