const themeMod = require('./utils/theme') const cloud = require('./utils/cloud') App({ onLaunch() { // Init cloud storage (no-op if not configured) cloud.init() const settings = wx.getStorageSync('user_settings') if (!settings) { wx.setStorageSync('user_settings', { planId: 'beginner', dailyReminder: true, reminderTime: '08:00', voiceGuide: true, vibrate: true }) } const streak = wx.getStorageSync('current_streak') if (!streak) { wx.setStorageSync('current_streak', { count: 0, lastDate: '' }) } this.globalData.theme = themeMod.getCurrentTheme() // If local records are empty, try pulling from cloud const records = wx.getStorageSync('training_records') if (!records || Object.keys(records).length === 0) { cloud.pullAll().then((cloudData) => { if (!cloudData) return try { if (cloudData.records && Object.keys(cloudData.records).length > 0) { wx.setStorageSync('training_records', cloudData.records) } if (cloudData.settings) { wx.setStorageSync('user_settings', cloudData.settings) } if (cloudData.streak) { wx.setStorageSync('current_streak', cloudData.streak) } if (cloudData.themeId) { themeMod.setTheme(cloudData.themeId) } } catch (e) { console.error('Cloud restore failed:', e) } }) } }, globalData: { planId: 'beginner', theme: null } })