@@ -3,16 +3,41 @@ const path = require('path');
33const chokidar = require ( 'chokidar' ) ;
44const fs = require ( 'fs' ) ;
55
6- // Handle creating/removing shortcuts on Windows when installing/uninstalling.
7- if ( require ( 'electron-squirrel-startup' ) ) {
8- app . quit ( ) ;
9- }
10-
116let mainWindow = null ;
127let watcher = null ;
138let tray = null ;
149let originalDebugSettings = null ;
1510let isCleaningUp = false ;
11+ let store = null ;
12+
13+ // Handle creating/removing shortcuts on Windows when installing/uninstalling.
14+ if ( require ( 'electron-squirrel-startup' ) ) {
15+ app . quit ( ) ;
16+ }
17+
18+ // Initialize electron store
19+ const initStore = async ( ) => {
20+ const { default : Store } = await import ( 'electron-store' ) ;
21+ store = new Store ( {
22+ defaults : {
23+ recentDirectories : [ ]
24+ }
25+ } ) ;
26+ } ;
27+
28+ // Function to add a directory to recent list
29+ const addToRecentDirectories = ( directory ) => {
30+ if ( ! store ) return [ ] ;
31+ const recentDirectories = store . get ( 'recentDirectories' , [ ] ) ;
32+ // Remove the directory if it already exists (to avoid duplicates)
33+ const filteredDirectories = recentDirectories . filter ( dir => dir !== directory ) ;
34+ // Add the new directory to the start of the array
35+ filteredDirectories . unshift ( directory ) ;
36+ // Keep only the last 5 directories
37+ const updatedDirectories = filteredDirectories . slice ( 0 , 5 ) ;
38+ store . set ( 'recentDirectories' , updatedDirectories ) ;
39+ return updatedDirectories ;
40+ } ;
1641
1742// Function to check if directory is a WordPress installation
1843const isWordPressDirectory = async ( directory ) => {
@@ -248,6 +273,8 @@ ipcMain.handle('select-directory', async () => {
248273 await enableWPDebug ( directory ) ;
249274 // Create mu-plugin
250275 await createMuPlugin ( directory ) ;
276+ // Add to recent directories
277+ addToRecentDirectories ( directory ) ;
251278 return directory ;
252279 } else {
253280 throw new Error ( 'Selected directory is not a WordPress installation' ) ;
@@ -256,6 +283,34 @@ ipcMain.handle('select-directory', async () => {
256283 return null ;
257284} ) ;
258285
286+ // Get recent directories
287+ ipcMain . handle ( 'get-recent-directories' , async ( ) => {
288+ if ( ! store ) return [ ] ;
289+ return store . get ( 'recentDirectories' , [ ] ) ;
290+ } ) ;
291+
292+ // Handle selecting a recent directory
293+ ipcMain . handle ( 'select-recent-directory' , async ( event , directory ) => {
294+ // Verify it's still a WordPress directory
295+ if ( await isWordPressDirectory ( directory ) ) {
296+ // Enable WP_DEBUG configuration
297+ await enableWPDebug ( directory ) ;
298+ // Create mu-plugin
299+ await createMuPlugin ( directory ) ;
300+ // Move this directory to the top of recent list
301+ addToRecentDirectories ( directory ) ;
302+ return directory ;
303+ } else {
304+ // Remove invalid directory from recent list
305+ if ( store ) {
306+ const recentDirectories = store . get ( 'recentDirectories' , [ ] ) ;
307+ const filteredDirectories = recentDirectories . filter ( dir => dir !== directory ) ;
308+ store . set ( 'recentDirectories' , filteredDirectories ) ;
309+ }
310+ throw new Error ( 'Selected directory is no longer a valid WordPress installation' ) ;
311+ }
312+ } ) ;
313+
259314// Start watching debug.log file
260315ipcMain . handle ( 'watch-debug-log' , async ( event , wpDirectory ) => {
261316 const debugLogPath = path . join ( wpDirectory , 'wp-content' , 'debug.log' ) ;
@@ -389,6 +444,7 @@ const cleanup = async () => {
389444} ;
390445
391446app . whenReady ( ) . then ( async ( ) => {
447+ await initStore ( ) ;
392448 createMenu ( ) ;
393449 await createTray ( ) ;
394450 createWindow ( ) ;
0 commit comments