v0.9.0: the history lives in ~/Documents/bubble-data
On its first launch bubble copies ~/Documents/voipms-desktop-data to ~/Documents/bubble-data (through a .partial folder, renamed only once the copy is whole) and uses that. The old folder stays as a backup with a "MOVED TO bubble-data.txt" note, to delete once everything looks right. A data folder chosen in Settings elsewhere stays put; if the copy fails, bubble keeps using the old folder rather than starting empty. Tried with a throwaway home holding the sandbox's made-up history: the copy, the note, the chats loading from the new folder, no second copy on the next launch, and a saved pointer to the old folder moving along with it.
This commit is contained in:
+42
-2
@@ -1,6 +1,6 @@
|
||||
// Where the data lives + non-secret preferences.
|
||||
//
|
||||
// The message database defaults to ~/Documents/voipms-desktop-data so Déjà Dup
|
||||
// The message database defaults to ~/Documents/bubble-data so Déjà Dup
|
||||
// backs it up (it excludes ~/.config, ~/.local and ~/.cache). A small pointer
|
||||
// file in Electron's userData remembers a custom location if one is chosen.
|
||||
import { app } from 'electron'
|
||||
@@ -19,7 +19,47 @@ const DEFAULTS: Settings = {
|
||||
const pointerFile = (): string => path.join(app.getPath('userData'), 'data-location.json')
|
||||
|
||||
export function defaultDataDir(): string {
|
||||
return path.join(app.getPath('documents'), 'voipms-desktop-data')
|
||||
return path.join(app.getPath('documents'), 'bubble-data')
|
||||
}
|
||||
|
||||
// Where it lived before the app was called bubble.
|
||||
const OLD_NAME = 'voipms-desktop-data'
|
||||
|
||||
// Once, before anything opens the database: copy ~/Documents/voipms-desktop-data
|
||||
// to ~/Documents/bubble-data (via a .partial folder, renamed only when the
|
||||
// copy is whole) and use that. The old folder stays as a backup, with a note
|
||||
// saying so, for its owner to delete. Only the default place moves: a folder
|
||||
// chosen in Settings stays where it is. If the copy fails, carry on in the old
|
||||
// folder rather than starting an empty history.
|
||||
export function moveToBubbleData(): void {
|
||||
if (process.env['VOIPMS_DATA_DIR']) return
|
||||
const old = path.join(app.getPath('documents'), OLD_NAME)
|
||||
const dest = defaultDataDir()
|
||||
let pointed: string | undefined
|
||||
try {
|
||||
pointed = (JSON.parse(fs.readFileSync(pointerFile(), 'utf8')) as { dataDir?: string }).dataDir
|
||||
} catch {
|
||||
/* no pointer: the default place */
|
||||
}
|
||||
if (pointed && path.resolve(pointed) !== path.resolve(old)) return
|
||||
if (!fs.existsSync(path.join(old, 'messages.db')) || fs.existsSync(dest)) return
|
||||
const partial = `${dest}.partial`
|
||||
try {
|
||||
fs.rmSync(partial, { recursive: true, force: true }) // a copy cut short last time
|
||||
console.log(`[data] copying ${old} to ${dest}`)
|
||||
fs.cpSync(old, partial, { recursive: true, preserveTimestamps: true, errorOnExist: true })
|
||||
fs.renameSync(partial, dest)
|
||||
if (pointed) setDataDir(dest)
|
||||
fs.writeFileSync(
|
||||
path.join(old, 'MOVED TO bubble-data.txt'),
|
||||
`bubble copied this folder to ${dest} on ${new Date().toString()} and uses that one now.\n` +
|
||||
`This is the backup from before the move: once bubble looks right, it can be deleted.\n`
|
||||
)
|
||||
} catch (e) {
|
||||
console.error('[data] copy to bubble-data failed; staying in the old folder:', e)
|
||||
fs.rmSync(partial, { recursive: true, force: true })
|
||||
setDataDir(old)
|
||||
}
|
||||
}
|
||||
|
||||
export function getDataDir(): string {
|
||||
|
||||
Reference in New Issue
Block a user