Skip to content

Commit

Permalink
electron: fallback when documents missing
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow-light committed Nov 3, 2024
1 parent ec76f70 commit 3863ef4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions electron/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,22 @@ if (app.isPackaged){
}


// Get user's documents dir
let docs_dir:string
try {
docs_dir = app.getPath('documents') // Not available in some Win/Mac setups for some reason
} catch {
// Fallback on appData which is the parent of userData, since it must exist
// In such cases there will be .../appData/stello & .../appData/Stello Files next to each other
docs_dir = app.getPath('appData')
}


// Internal data may be in `Stello Files` for new users or old locations for long-term users
// NOTE Also within `Stello Files` for Mac/Linux users who received 1.6.6 update before 1.6.7
const possible_data_locations = [
join(app_path, '..', 'Stello Files', 'Internal Data'), // Portable mode
join(app.getPath('documents'), 'Stello Files', 'Internal Data'), // Normal mode
join(docs_dir, 'Stello Files', 'Internal Data'), // Normal mode
join(app_path, '..', 'stello_data'), // Old portable location
app.getPath('userData'), // Old normal location
]
Expand All @@ -41,7 +52,7 @@ const data_dir = possible_data_locations.find(l => existsSync(join(l, 'IndexedDB
// It will either be the documents or portable location depending on whether data_dir is portable
const files_dir = [0, 2].includes(possible_data_locations.indexOf(data_dir))
? join(app_path, '..', 'Stello Files')
: join(app.getPath('documents'), 'Stello Files')
: join(docs_dir, 'Stello Files')


export function restrict_path(root_dir:string, relative_path:string){
Expand Down

0 comments on commit 3863ef4

Please sign in to comment.