// Sandbox mode, for trying the app (and UI work) without going anywhere near
// the real account: VOIPMS_SANDBOX=
(or VOIPMS_DEMO=1, which uses a temp
// dir) keeps *everything* under -- the Electron profile (so no saved
// voip.ms password and no Google sign-in), settings, and the message database
// -- skips the system address book, and fills an empty database with made-up
// conversations. Imported first by index.ts so it applies before anything
// reads a path.
import { app } from 'electron'
import os from 'node:os'
import path from 'node:path'
import type { MessageDb, NewMessage } from './db'
import { gvMessageId } from './gvoice/sync'
export const SANDBOX: string | undefined =
process.env['VOIPMS_SANDBOX'] || (process.env['VOIPMS_DEMO'] ? path.join(os.tmpdir(), 'voipms-sandbox') : undefined)
if (SANDBOX) {
app.setPath('userData', path.join(SANDBOX, 'profile'))
process.env['VOIPMS_DATA_DIR'] = path.join(SANDBOX, 'data')
console.log(`[sandbox] everything lives in ${SANDBOX}`)
} else {
// The app was "voip.ms Messages" before it was bubble, and Electron names
// the profile folder after the app: keep using the old one so the saved
// login, Google sign-in and data-location pointer carry over.
app.setPath('userData', path.join(app.getPath('appData'), 'voip.ms Messages'))
}
// Fictional numbers (555-01xx is reserved for fiction).
export const DEMO_VOIP = '5415550100'
export const DEMO_GV = '5415550177'
export function seedDemo(db: MessageDb): void {
if (db.count() > 0) return
const now = Date.now()
const min = 60_000
const group = '5415550101,5415550102,5415550103'
let id = 1000
const v = (contact: string, direction: 'in' | 'out', body: string, ago: number): NewMessage => ({
id: id++,
did: DEMO_VOIP,
contact,
direction,
body,
ts: now - ago * min
})
const g = (contact: string, direction: 'in' | 'out', body: string, ago: number, sender?: string): NewMessage => ({
id: gvMessageId(`demo-${id++}`),
did: DEMO_GV,
contact,
direction,
body,
ts: now - ago * min,
...(sender ? { sender } : {})
})
db.upsertMessages([
v('5415550110', 'in', 'Are we still on for Saturday?', 300),
v('5415550110', 'out', 'Yep! 10am at the market', 290),
v('5415550111', 'in', 'Your table is ready', 2000),
g('5415550120', 'in', 'Package left at the front door', 90),
g('5415550120', 'out', 'Thanks!', 85),
g(group, 'in', 'Who is bringing snacks to the hike?', 40, '5415550101'),
g(group, 'in', 'I can do chips', 38, '5415550102'),
g(group, 'in', 'and salsa', 37, '5415550102'),
g(group, 'out', 'I’ll bring cookies 🍪', 30),
g(group, 'in', 'Loved “I’ll bring cookies 🍪”', 29, '5415550101'),
g(group, 'in', 'Laughed at “I’ll bring cookies 🍪”', 28, '5415550103'),
g(group, 'in', 'Perfect, see everyone at 9', 5, '5415550103'),
g(group, 'in', 'Emphasized “Perfect, see everyone at 9”', 4, '5415550102')
])
db.setGvThread(DEMO_GV, group, 'g.demo')
db.set('unread_floor', '0')
db.set('gv_number', DEMO_GV)
db.set('dids', JSON.stringify([{ did: DEMO_VOIP, description: 'Demo', smsEnabled: true }]))
}