@@ -17,6 +17,7 @@ import fs from 'fs';
1717import path from 'path' ;
1818import stream from 'stream' ;
1919
20+ import Electron from 'electron' ;
2021import XDGAppPaths from 'xdg-app-paths' ;
2122const paths = XDGAppPaths ( { name : 'rancher-desktop' } ) ;
2223const logDir = path . join ( paths . runtime ( ) || paths . state ( ) , 'logs' ) ;
@@ -110,13 +111,19 @@ export default new Proxy(logging, {
110111 * main process, and due to how imports work, only ever called once.
111112 * Unforunately, this must be done synchronously to avoid deleting log files
112113 * that are newly created.
114+ *
115+ * This is only done if we have the electron single-instance lock, as we do not
116+ * want to delete logs for existing instances - this should not be an issue, as
117+ * we will quit shortly.
113118 */
114119// The main process is 'browser', as opposed to 'renderer'.
115120if ( process . type === 'browser' ) {
116- fs . mkdirSync ( logDir , { recursive : true } ) ;
117- for ( const entry of fs . readdirSync ( logDir , { withFileTypes : true } ) ) {
118- if ( entry . isFile ( ) && entry . name . endsWith ( '.log' ) ) {
119- fs . unlinkSync ( path . join ( logDir , entry . name ) ) ;
121+ if ( Electron . app . requestSingleInstanceLock ( ) ) {
122+ fs . mkdirSync ( logDir , { recursive : true } ) ;
123+ for ( const entry of fs . readdirSync ( logDir , { withFileTypes : true } ) ) {
124+ if ( entry . isFile ( ) && entry . name . endsWith ( '.log' ) ) {
125+ fs . unlinkSync ( path . join ( logDir , entry . name ) ) ;
126+ }
120127 }
121128 }
122129}
0 commit comments