diff --git a/buildWindows.ps1 b/buildWindows.ps1 new file mode 100644 index 0000000..b36ad42 --- /dev/null +++ b/buildWindows.ps1 @@ -0,0 +1,40 @@ +# Step 1: Build the Flutter Windows application +Write-Host "Building Flutter Windows app..." +flutter build windows + +# Define the source files and destination directory +# Adjust these paths according to your project's structure +$sourceFiles = @( + ".\windows\pactus-daemon.exe", + ".\windows\pactus-wallet.exe" +) +$destinationDir = ".\build\windows\x64\runner\Debug" # Adjust based on your build configuration +$releaseDestinationDir = ".\build\windows\x64\runner\Release" # Adjust based on your build configuration + + +# Function to copy files to a destination +function Copy-Files { + param ( + [string]$destinationDir + ) + # Ensure the destination directory exists + if (-not (Test-Path -Path $destinationDir)) { + Write-Host "Destination directory does not exist: $destinationDir" + return + } + + # Copy each source file to the destination directory + foreach ($file in $sourceFiles) { + Write-Host "Copying $file to $destinationDir" + Copy-Item -Path $file -Destination $destinationDir + } +} + +# Step 2: Copy files to Debug and Release directories +Copy-Files -destinationDir $destinationDir +Copy-Files -destinationDir $releaseDestinationDir + + +# Step 3: Run the Flutter Windows app +Write-Host "Running Flutter Windows app..." +flutter run -d windows diff --git a/lib/screens/init_screen.dart b/lib/screens/init_screen.dart index 35c6e24..2ee25a1 100644 --- a/lib/screens/init_screen.dart +++ b/lib/screens/init_screen.dart @@ -33,8 +33,23 @@ class InitialScreen extends ConsumerStatefulWidget { } class _HomePageState extends ConsumerState { - final List listEntries = ['Initialize mode', 'Wallet seed', 'Confirm seed', 'Master password', 'Validator Config', 'Initialization', 'Finish']; - final List listRestore = ['Initialize mode', 'Restoration seed', 'Master password', 'Validator Config', 'Initialization', 'Finish']; + final List listEntries = [ + 'Initialize mode', + 'Wallet seed', + 'Confirm seed', + 'Master password', + 'Validator Config', + 'Initialization', + 'Finish' + ]; + final List listRestore = [ + 'Initialize mode', + 'Restoration seed', + 'Master password', + 'Validator Config', + 'Initialization', + 'Finish' + ]; final pageController = PageController(); var restore = false; @@ -97,11 +112,11 @@ class _HomePageState extends ConsumerState { } }); }); - _runDaemon(); + _runDaemonWindows(); }); } - _runDaemon() async { + _runDaemonMac() async { print(Platform.environment['HOME']); String mainPath = Platform.resolvedExecutable; mainPath = mainPath.substring(0, mainPath.lastIndexOf("/")); @@ -114,14 +129,86 @@ class _HomePageState extends ConsumerState { if (file.path.contains("pactus-daemon")) { // res = await Process.run(file.path, ["init", "-w", "${Platform.environment['HOME']!}/wallet", // "--restore", "rate twin faculty success rather crucial parrot output toy quiz reason tumble", "--val-num", "7", "-p", "12345678"]); - res = await Process.run(file.path, ["start", "-w", "${Platform.environment['HOME']!}/wallet", "-p", "12345678"]); + res = await Process.run(file.path, [ + "start", + "-w", + "${Platform.environment['HOME']!}/wallet", + "-p", + "12345678" + ]); print(res.stdout); } } - Future.delayed(const Duration(seconds: 15), (){ + Future.delayed(const Duration(seconds: 15), () { try { - int pid= int.parse(res!.pid.toString()); + int pid = int.parse(res!.pid.toString()); + Process.killPid(pid); + print("Killed"); + } catch (e) { + print(e); + } + }); + } + + _runDaemonWindows() async { + print(Platform.environment['USERPROFILE']); + String mainPath = Platform.resolvedExecutable; + mainPath = mainPath.substring(0, mainPath.lastIndexOf("\\")); + Directory directoryExe = Directory(mainPath); + List files = directoryExe.listSync(); + ProcessResult? res; + String? path; + for (FileSystemEntity file in files) { + if (file.path.contains("pactus-daemon.exe")) { + path = file.path; + break; + } + } + if (path == null) { + return; + } + //check if the wallet directory exists + Directory walletDir = + Directory("${Platform.environment['USERPROFILE']!}/pactus-wallet"); + bool exists = walletDir.existsSync(); + if (!exists) { + print("Creating wallet directory"); + walletDir.createSync(); + res = await Process.run(path, [ + "init", + "-w", + "${Platform.environment['USERPROFILE']!}/pactus-wallet", + "--restore", + "rate twin faculty success rather crucial parrot output toy quiz reason tumble", + "--val-num", + "7", + "-p", + "12345678" + ]); + print(res.stdout); + await Future.delayed(const Duration(seconds: 2)); + res = await Process.run(path, [ + "start", + "-w", + "${Platform.environment['USERPROFILE']!}/pactus-wallet", + "-p", + "12345678" + ]); + }else { + res = await Process.run(path, [ + "start", + "-w", + "${Platform.environment['USERPROFILE']!}/pactus-wallet", + "-p", + "12345678" + ]); + print(res.stdout); + } + + Future.delayed(const Duration(seconds: 15), () { + try { + int pid = int.parse(res!.pid.toString()); Process.killPid(pid); print("Killed"); } catch (e) { @@ -144,160 +231,202 @@ class _HomePageState extends ConsumerState { children: [ Expanded( child: Row( - children: [ - //list - Padding( - padding: EdgeInsets.only(top:35.0.w), - child: SizedBox( - width: 240.w, - child: ListView.builder( - padding: EdgeInsets.zero, - itemCount: restore ? listRestore.length : listEntries.length, - itemBuilder: (BuildContext context, int index) { - return Container( - height: 40.h, - width: 240.w, - padding: EdgeInsetsDirectional.symmetric(horizontal: 20.w, vertical: 12.0.h), - decoration: BoxDecoration( - color: index <= slideIndex ? theme.isLightTheme(context) ? Colors.white : const Color(0xFF323232) : Colors.transparent, - ), - child: ListEntry( - title: restore ? listRestore[index] : listEntries[index], - selected: index <= slideIndex, - bold: index == slideIndex, - ), - ); - }, - ), - ), - ), - Container( - height: height, - width: 1, - color: theme.separator, + children: [ + //list + Padding( + padding: EdgeInsets.only(top: 35.0.w), + child: SizedBox( + width: 240.w, + child: ListView.builder( + padding: EdgeInsets.zero, + itemCount: + restore ? listRestore.length : listEntries.length, + itemBuilder: (BuildContext context, int index) { + return Container( + height: 40.h, + width: 240.w, + padding: EdgeInsetsDirectional.symmetric( + horizontal: 20.w, vertical: 12.0.h), + decoration: BoxDecoration( + color: index <= slideIndex + ? theme.isLightTheme(context) + ? Colors.white + : const Color(0xFF323232) + : Colors.transparent, + ), + child: ListEntry( + title: restore + ? listRestore[index] + : listEntries[index], + selected: index <= slideIndex, + bold: index == slideIndex, + ), + ); + }, ), - // Content - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: Padding( - padding: EdgeInsetsDirectional.symmetric(horizontal: 30.0.w, vertical: 30.0.h), - child: PageView.builder( - controller: pageController, - itemCount: restore ? slidesRestore.length : slides.length, - onPageChanged: (int index) { - ref.read(slideProvider.notifier).state = index; - }, - itemBuilder: (context, index) { - return restore ? slidesRestore[index] : slides[index]; - }, - ), - ), + ), + ), + Container( + height: height, + width: 1, + color: theme.separator, + ), + // Content + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: Padding( + padding: EdgeInsetsDirectional.symmetric( + horizontal: 30.0.w, vertical: 30.0.h), + child: PageView.builder( + controller: pageController, + itemCount: + restore ? slidesRestore.length : slides.length, + onPageChanged: (int index) { + ref.read(slideProvider.notifier).state = index; + }, + itemBuilder: (context, index) { + return restore + ? slidesRestore[index] + : slides[index]; + }, ), - Visibility( - visible: restore? slideIndex != 5 :slideIndex != 6, - child: Align( - alignment: Alignment.bottomLeft, - child: Container( - width: double.infinity, - height: 80.h, - decoration: BoxDecoration( - color: theme.buttonBar, - border: Border( - top: BorderSide( - color: theme.separator.withOpacity(0.08), - width: 1, - ), - ), + ), + ), + Visibility( + visible: restore ? slideIndex != 5 : slideIndex != 6, + child: Align( + alignment: Alignment.bottomLeft, + child: Container( + width: double.infinity, + height: 80.h, + decoration: BoxDecoration( + color: theme.buttonBar, + border: Border( + top: BorderSide( + color: theme.separator.withOpacity(0.08), + width: 1, ), - padding: const EdgeInsetsDirectional.symmetric(horizontal: 20.0, vertical: 20.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, + ), + ), + padding: const EdgeInsetsDirectional.symmetric( + horizontal: 20.0, vertical: 20.0), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + slideIndex == 0 + ? const SizedBox() + : SizedBox( + width: 96.w, + child: Button( + onPressed: () { + if (slideIndex == 0) { + context.go(WelcomeScreen.route); + } else { + setState(() { + ref + .read( + nextButtonDisableProvider + .notifier) + .state = false; + }); + goBack(ref, pageController); + } + }, + child: const Text('Back'), + ), + ), + //skip button + Row( children: [ - slideIndex == 0 - ? const SizedBox() - : SizedBox( - width: 96.w, - child: Button( + if (slideIndex == 3 && radioValue == 0) + Button( + style: ButtonStyle( + backgroundColor: + ButtonState.resolveWith( + (states) { + if (buttonControl) { + return Colors.grey + .withOpacity(0.2); + } + if (states.contains( + ButtonStates.hovering)) { + return Colors.grey + .withOpacity(0.05); + } + return Colors.transparent; + }), + foregroundColor: + ButtonState.all( + Colors.blue), + shape: ButtonState.all< + RoundedRectangleBorder>( + RoundedRectangleBorder( + borderRadius: + BorderRadius.circular( + 8))), + ), onPressed: () { - if (slideIndex == 0) { - context.go(WelcomeScreen.route); - } else { - setState(() { - ref.read(nextButtonDisableProvider.notifier).state = false; - }); - goBack(ref, pageController); - } + // ref.read(slideProvider.notifier).state++; + ref + .read(nextButtonDisableProvider + .notifier) + .state = false; + goForward(ref, pageController); }, - child: const Text('Back'), + child: const Text('Skip'), ), - ), - //skip button - Row( - children: [ - if (slideIndex == 3 && radioValue == 0) - Button( - style: ButtonStyle( - backgroundColor: ButtonState.resolveWith((states) { - if (buttonControl) { - return Colors.grey.withOpacity(0.2); - } - if (states.contains(ButtonStates.hovering)) { - return Colors.grey.withOpacity(0.05); - } - return Colors.transparent; - }), - foregroundColor: ButtonState.all(Colors.blue), - shape: ButtonState.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(8))), - ), - onPressed: () { - // ref.read(slideProvider.notifier).state++; - ref.read(nextButtonDisableProvider.notifier).state = false; - goForward(ref, pageController); - }, - child: const Text('Skip'), - ), - gapW16, - SizedBox( - width: 96.w, - child: Button( - onPressed: buttonControl - ? null - : () { - goForward(ref, pageController); - }, - style: ButtonStyle( - // backgroundColor: ButtonState.all(buttonControl ? Colors.grey.withOpacity(0.1) : Colors.blue), - backgroundColor: ButtonState.resolveWith((states) { - if (buttonControl) { - return Colors.grey.withOpacity(0.1); - } - if (states.contains(ButtonStates.hovering)) { - return Colors.blue.lightest; - } - return Colors.blue; - }), - foregroundColor: ButtonState.all(buttonControl ? Colors.black.withOpacity(0.1) : Colors.white), - ), - child: const Text('Next'), - ), + gapW16, + SizedBox( + width: 96.w, + child: Button( + onPressed: buttonControl + ? null + : () { + goForward( + ref, pageController); + }, + style: ButtonStyle( + // backgroundColor: ButtonState.all(buttonControl ? Colors.grey.withOpacity(0.1) : Colors.blue), + backgroundColor: + ButtonState.resolveWith( + (states) { + if (buttonControl) { + return Colors.grey + .withOpacity(0.1); + } + if (states.contains( + ButtonStates.hovering)) { + return Colors.blue.lightest; + } + return Colors.blue; + }), + foregroundColor: + ButtonState.all( + buttonControl + ? Colors.black + .withOpacity(0.1) + : Colors.white), ), - ], + child: const Text('Next'), + ), ), - ], ), - )), - ), - ], + ], + ), + )), ), - // Your buttons or gestures to change the slide index - ) - ], - )) + ], + ), + // Your buttons or gestures to change the slide index + ) + ], + )) ], )); } @@ -316,7 +445,7 @@ class _HomePageState extends ConsumerState { } void goForward(WidgetRef ref, PageController pageController, {int? page}) { - final currentIndex = ref.read(slideProvider.notifier).state; + final currentIndex = ref.read(slideProvider.notifier).state; final newIndex = page ?? currentIndex + 1; if (newIndex < slides.length) { pageController.animateToPage( @@ -327,7 +456,6 @@ class _HomePageState extends ConsumerState { ref.read(slideProvider.notifier).state = newIndex; } } - } class ListEntry extends StatelessWidget { @@ -335,7 +463,11 @@ class ListEntry extends StatelessWidget { final bool selected; final bool bold; - const ListEntry({super.key, required this.title, this.selected = false, this.bold = false}); + const ListEntry( + {super.key, + required this.title, + this.selected = false, + this.bold = false}); @override Widget build(BuildContext context) { @@ -343,7 +475,12 @@ class ListEntry extends StatelessWidget { height: 40.h, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: Opacity(opacity: selected ? 1.0 : 0.2, child: Text(title, style: TextStyle(fontSize: 16.sp, fontWeight: bold ? FontWeight.w600 : FontWeight.w400))), + child: Opacity( + opacity: selected ? 1.0 : 0.2, + child: Text(title, + style: TextStyle( + fontSize: 16.sp, + fontWeight: bold ? FontWeight.w600 : FontWeight.w400))), ), ); }