55import path from 'path'
66import fs from 'fs'
77import os from 'os'
8+ import { app } from 'electron'
89
910export const execPath = process . execPath
1011
@@ -18,36 +19,40 @@ export const execPath = process.execPath
1819 * Note: Currently unused; included only for documentation purpose.
1920 */
2021/* eslint-disable no-unused-vars */
21- const appData = app => app . getPath ( 'appData' )
22+ const appData = app . getPath ( 'appData' )
2223/* eslint-enable no-unused-vars */
2324
2425/**
2526 * The directory for storing your app's configuration files,
2627 * which by default it is the appData directory appended
2728 * with your app's name.
29+ *
30+ * NOTE: Starting with v32.x Electron unconditionally deletes 'databases' directory
31+ * where we used to store all databases.
32+ * REFERENCE: https://github.com/electron/electron/issues/45396
2833 */
29- const userData = app => app . getPath ( 'userData' )
34+ const userData = app . getPath ( 'userData' )
3035
3136/**
3237 * The current application directory.
3338 */
34- const appPath = app => app . getAppPath ( )
39+ const appPath = app . getAppPath ( )
3540
3641/**
3742 * Directory to store all main/renderer databases.
3843 */
39- export const databases = app => path . join ( userData ( app ) , 'databases' )
44+ export const databases = path . join ( userData , 'leveldb' )
45+ const databasesLegacy = path . join ( userData , 'databases' )
4046
4147/**
4248 * Directory to store main/master database.
4349 */
44- export const master = app => path . join ( databases ( app ) , 'master' )
50+ export const master = path . join ( databases , 'master' )
4551
4652/**
4753 * .env file for providing user related environment settings
48- *
4954 */
50- export const dotenv = app => path . join ( userData ( app ) , '.env' )
55+ export const dotenv = path . join ( userData , '.env' )
5156
5257/**
5358 * (Recusively) create directory for given path.
@@ -95,4 +100,15 @@ export const metadata = (location, uuid) => path.join(projects(location), uuid,
95100 */
96101export const preferences = ( location , uuid ) => path . join ( projects ( location ) , uuid , 'preferences.json' )
97102
98- export const staticIndexPage = app => path . join ( appPath ( app ) , 'dist' , 'index.html' )
103+ export const staticIndexPage = path . join ( appPath , 'dist' , 'index.html' )
104+
105+ /**
106+ *
107+ */
108+ export const initStorageLocation = ( ) => {
109+ if ( fs . existsSync ( databasesLegacy ) ) {
110+ fs . renameSync ( databasesLegacy , databases )
111+ } else if ( ! fs . existsSync ( databases ) ) {
112+ mkdir ( databases )
113+ }
114+ }
0 commit comments