Skip to content

Commit

Permalink
attempt manual migration instructinos
Browse files Browse the repository at this point in the history
  • Loading branch information
waozixyz committed Sep 23, 2024
1 parent edce27e commit 33f7cbe
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 218 deletions.
28 changes: 0 additions & 28 deletions lib/providers/user_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,32 +351,4 @@ class UserProvider with ChangeNotifier {

return sessions;
}

String compressUserData() {
try {
final allData = getAllData();
final jsonString = jsonEncode(allData);
final compressedBytes = gzip.encode(utf8.encode(jsonString));
return base64Url.encode(compressedBytes);
} catch (e) {
print('Error in compressUserData: $e');
return '';
}
}

Future<void> importCompressedData(String compressedData) async {
try {
final compressedBytes = base64Url.decode(compressedData);
final jsonString = utf8.decode(gzip.decode(compressedBytes));
final decodedData = jsonDecode(jsonString);
await importData(decodedData);
} catch (e) {
print('Error in importCompressedData: $e');
throw Exception('Failed to import compressed data: $e');
}
}
String generateMigrationUrl() {
final compressedData = compressUserData();
return 'https://v1.inbreeze.xyz/#/migrate?data=$compressedData';
}
}
42 changes: 9 additions & 33 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

import 'guide_router.dart';
import 'exercise_router.dart';
import 'package:inner_breeze/screens/title_screen.dart';
Expand All @@ -8,65 +8,41 @@ import 'package:inner_breeze/screens/splash_screen.dart';
import 'package:inner_breeze/screens/results_screen.dart';
import 'package:inner_breeze/screens/progress_screen.dart';
import 'package:inner_breeze/screens/breathing_settings_screen.dart';
import 'package:inner_breeze/widgets/migration_handler.dart';

// GoRouter configuration
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => MigrationWrapper(child: SplashScreen()),
),

GoRoute(
path: '/migrate',
builder: (context, state) {
final data = state.uri.queryParameters['data'];
return MigrationHandler(data: data);
},
builder: (context, state) => SplashScreen(),
),
GoRoute(
path: '/home',
builder: (context, state) => MigrationWrapper(child: TitleScreen()),
builder: (context, state) => TitleScreen(),
),
GoRoute(
path: '/progress',
builder: (context, state) => MigrationWrapper(child: ProgressScreen()),
builder: (context, state) => ProgressScreen(),
),
GoRoute(
path: '/guide/:page',
builder: (context, state) => MigrationWrapper(
child: GuideRouter(page: state.pathParameters['page']!),
),
builder: (context, state) => GuideRouter(page: state.pathParameters['page']!),
),
GoRoute(
path: '/exercise/:page',
builder: (context, state) => MigrationWrapper(
child: ExerciseRouter(page: state.pathParameters['page']!),
),
builder: (context, state) => ExerciseRouter(page: state.pathParameters['page']!),
),
GoRoute(
path: '/results',
builder: (context, state) => MigrationWrapper(child: ResultsScreen()),
builder: (context, state) => ResultsScreen(),
),
GoRoute(
path: '/settings',
builder: (context, state) => MigrationWrapper(child: SettingsScreen()),
builder: (context, state) => SettingsScreen(),
),
GoRoute(
path: '/breathing',
builder: (context, state) =>
MigrationWrapper(child: BreathingSettingsScreen()),
builder: (context, state) => BreathingSettingsScreen(),
),
],
);

class MigrationWrapper extends StatelessWidget {
final Widget child;
const MigrationWrapper({Key? key, required this.child}) : super(key: key);

@override
Widget build(BuildContext context) {
return child;
}
}
169 changes: 100 additions & 69 deletions lib/screens/title_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,80 @@ import 'package:inner_breeze/widgets/breeze_bottom_nav.dart';
import 'package:localization/localization.dart';
import 'package:provider/provider.dart';
import 'package:inner_breeze/providers/user_provider.dart';

// Conditionally import dart:html
import 'package:universal_html/html.dart' if (dart.library.html) 'dart:html'
as html;

import 'package:flutter/foundation.dart';
import 'package:universal_html/html.dart' if (dart.library.html) 'dart:html' as html;

bool isOldDomain() {
if (kIsWeb) {
try {
final currentUrl = html.window.location.href;
return currentUrl.contains('web.inner-breeze.app');
} catch (e) {
// Handle any potential errors when accessing window.location
print('Error checking domain: $e');
return false;
}
}
return false; // Return false for non-web platforms
return false;
}

class MigrationInstructionsModal extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('Data Migration Instructions'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('To migrate your data to the new version:'),
SizedBox(height: 10),
Text('1. Go to Settings'),
Text('2. Tap on "Export Data"'),
Text('3. Save the exported file'),
Text('4. Open the new version of the app at:'),
Text('https://v1.inbreeze.xyz', style: TextStyle(fontWeight: FontWeight.bold)),
Text('5. In the new version, go to Settings'),
Text('6. Tap on "Import Data"'),
Text('7. Select the file you exported from this version'),
],
),
),
actions: <Widget>[
TextButton(
child: Text('Got it'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
}
}


class MigrationBanner extends StatelessWidget {
final VoidCallback onMigrate;
const MigrationBanner({Key? key, required this.onMigrate}) : super(key: key);
final VoidCallback onTap;

const MigrationBanner({Key? key, required this.onTap}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
color: Colors.yellow,
padding: EdgeInsets.all(8),
child: Row(
children: [
Expanded(
child: Text(
'Click here to migrate your data to the new domain',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
ElevatedButton(
onPressed: onMigrate,
child: Text('Migrate'),
),
],
return GestureDetector(
onTap: onTap,
child: Container(
width: double.infinity,
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
color: Color(0xFFD35400), // Dark orange color
child: Text(
'Click here for migration instructions',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
);
}
}


class TitleScreen extends StatefulWidget {
@override
State<TitleScreen> createState() => _TitleScreenState();
Expand All @@ -67,62 +93,67 @@ class _TitleScreenState extends State<TitleScreen> {
});
}

void _showMigrationInstructions() {
showDialog(
context: context,
builder: (BuildContext context) {
return MigrationInstructionsModal();
},
);
}

@override
void initState() {
super.initState();
if (isOldDomain()) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_showMigrationInstructions();
});
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Center(
child: Column(
children: [
if (isOldDomain())
MigrationBanner(
onMigrate: () {
final userProvider =
Provider.of<UserProvider>(context, listen: false);
final migrationUrl = userProvider.generateMigrationUrl();
if (kIsWeb) {
html.window.open(migrationUrl, '_blank');
} else {
// Handle non-web platforms (e.g., show a dialog or navigate to a new screen)
print('Migration not supported on this platform');
}
},
),
SizedBox(height: 60),
SizedBox(
width: 256,
child: Image.asset(
'assets/images/logo.png',
fit: BoxFit.cover,
),
),
Text(
'Inner Breeze',
style: BreezeStyle.header,
),
SizedBox(height: 32),
OutlinedButton(
style: OutlinedButton.styleFrom(
minimumSize: Size(180, 60),
),
child: Text(
"start_button".i18n(),
style: BreezeStyle.bodyBig,
body: Column(
children: [
if (isOldDomain()) MigrationBanner(onTap: _showMigrationInstructions),
Expanded(
child: SingleChildScrollView(
child: Center(
child: Column(
children: [
SizedBox(height: 60),
SizedBox(
width: 256,
child: Image.asset(
'assets/images/logo.png',
fit: BoxFit.cover,
),
),
Text(
'Inner Breeze',
style: BreezeStyle.header,
),
SizedBox(height: 32),
OutlinedButton(
style: OutlinedButton.styleFrom(
minimumSize: Size(180, 60),
),
child: Text(
"start_button".i18n(),
style: BreezeStyle.bodyBig,
),
onPressed: _navigateToExercise,
),
],
),
onPressed: () {
_navigateToExercise();
},
),
],
),
),
),
],
),
bottomNavigationBar: BreezeBottomNav(),
);
}
}
}
Loading

0 comments on commit 33f7cbe

Please sign in to comment.