run method
Implementation
@override
Future<void> run() async {
final isDry = argResults!.flag('dry');
final now = DateTime.now();
final tzMinTotal = now.timeZoneOffset.inMinutes;
final separator = tzMinTotal.isNegative ? '-' : '+';
final tzHours = (tzMinTotal / 60).floor().abs().toString().padLeft(2, '0');
final tzRemainMins = (tzMinTotal % 60).abs().toString().padLeft(2, '0');
final date = now.toIso8601String().replaceAll(':', '_');
final String stamper = '$date$separator${tzHours}_$tzRemainMins';
if (isDry) {
print(' --- ⚠️ Running in Dry mode, not actually changing your data -- ');
}
// print('Backup stamp will be: $stamper');
final appInfo = await AppInfo.make();
if (appInfo.sessions.isEmpty) {
print('⚠️ No active sessions found.');
} else {
final encoded = json.encode(appInfo.sessions);
final filePath = p.join(appInfo.appDocPath, 'sessions_backup_$stamper');
final f = await File(filePath).create(exclusive: true);
if (!isDry) f.writeAsString(encoded);
print('✔️ Sessions backed up to: $filePath');
}
if (appInfo.accounts.isEmpty) {
print('⚠️ No account data found.');
} else {
for (final a in appInfo.accounts) {
final oldPath = p.join(appInfo.appDocPath, a);
final newPath = p.join(appInfo.appDocPath, '${a}_backup_$stamper');
if (!isDry) await Directory(oldPath).rename(newPath);
print('✔️ $a backed up: $newPath');
}
}
if (!isDry) {
await ActerSdk.storage.write(
key: Env.defaultActerSession,
value: json.encode([]),
);
}
print('✔️ All reset');
exit(0);
}