upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbitflash <dev@bitflash.network>2026-08-19 09:23:01 -0300
committerbitflash <dev@bitflash.network>2026-08-19 09:23:01 -0300
commit8a47568dcfec8869bc08c555f0070be2d7ddddce (patch)
treecec783724ba5221bfb9bf09e8d5851d447f529da
parentb1c6d19fe2855c30d839dbc484165da58a8ee120 (diff)
gui: add a "Restart Now" button to the conversion wizard
After converting to SQLite the wizard said "restart to apply" but offered no way to do it, so a user could close the dialog and keep mining on the old Berkeley DB wallet without realizing the switch had not taken effect -- and coins mined in the meantime land only in wallet.dat, not the SQLite wallet they think they are now on. The post-conversion screen now offers "Restart Now", which relaunches Bitflash with the same command line and datadir (a short delay lets this instance release the network port and block-index files first) and asks this one to exit, so mining resumes on the SQLite wallet. "Later" keeps the old behaviour. A dimmed line warns that mining before the restart still credits the old wallet. wallet.dat is still never touched. The conversion action itself is unchanged (wallet-convert self-test still green); this is GUI wiring only.
-rw-r--r--src/gui.cpp82
1 files changed, 79 insertions, 3 deletions
diff --git a/src/gui.cpp b/src/gui.cpp
index 89a7ab6..81dd8e0 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -11,6 +11,9 @@
11#include <ctime> 11#include <ctime>
12#include <cstdio> 12#include <cstdio>
13#include <sstream> 13#include <sstream>
14#ifndef _WIN32
15#include <unistd.h>
16#endif
14#include <iomanip> 17#include <iomanip>
15#include <atomic> 18#include <atomic>
16#include <mutex> 19#include <mutex>
@@ -1400,6 +1403,67 @@ static void DrawAboutDialog()
1400static bool g_showBackendWizard = false; 1403static bool g_showBackendWizard = false;
1401static std::string g_wizardStatus; 1404static std::string g_wizardStatus;
1402static bool g_wizardConverted = false; 1405static bool g_wizardConverted = false;
1406static int g_restartArgc = 0;
1407static char** g_restartArgv = NULL;
1408
1409// Relaunch Bitflash with the same arguments and datadir, then ask this instance
1410// to exit. A short delay lets the old process release the network port and the
1411// block-index files before the new one opens them, so mining resumes cleanly on
1412// the SQLite wallet instead of both instances fighting over the same files.
1413static void RestartApplication()
1414{
1415#ifdef _WIN32
1416 char exePath[MAX_PATH];
1417 if (GetModuleFileNameA(NULL, exePath, MAX_PATH) == 0)
1418 return;
1419 std::string strArgs;
1420 bool fHasDataDir = false;
1421 for (int i = 1; i < g_restartArgc; i++)
1422 {
1423 std::string a = g_restartArgv[i] ? g_restartArgv[i] : "";
1424 if (a.find("-datadir=") == 0 || a.find("/datadir=") == 0)
1425 fHasDataDir = true;
1426 strArgs += " \"" + a + "\"";
1427 }
1428 if (!fHasDataDir)
1429 strArgs += " \"-datadir=" + GetAppDir() + "\"";
1430
1431 std::string strBat = GetAppDir() + "\\bitflash-restart.bat";
1432 FILE* pf = fopen(strBat.c_str(), "wb");
1433 if (pf)
1434 {
1435 // ping is the reliable no-console delay on Windows; timeout needs a tty.
1436 fprintf(pf,
1437 "@echo off\r\n"
1438 "ping 127.0.0.1 -n 3 >nul\r\n"
1439 "start \"\" \"%s\"%s\r\n"
1440 "del \"%%~f0\"\r\n",
1441 exePath, strArgs.c_str());
1442 fclose(pf);
1443 std::string strCmd = "cmd /c \"" + strBat + "\"";
1444 STARTUPINFOA si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si);
1445 PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi));
1446 if (CreateProcessA(NULL, (char*)strCmd.c_str(), NULL, NULL, FALSE,
1447 CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
1448 {
1449 CloseHandle(pi.hProcess);
1450 CloseHandle(pi.hThread);
1451 }
1452 }
1453#else
1454 pid_t pid = fork();
1455 if (pid == 0)
1456 {
1457 sleep(2);
1458 if (g_restartArgv)
1459 execv(g_restartArgv[0], g_restartArgv);
1460 _exit(127);
1461 }
1462#endif
1463 fShutdown = true;
1464 if (glfwGetCurrentContext())
1465 glfwSetWindowShouldClose(glfwGetCurrentContext(), true);
1466}
1403 1467
1404static void DrawBackendWizardDialog() 1468static void DrawBackendWizardDialog()
1405{ 1469{
@@ -1416,11 +1480,19 @@ static void DrawBackendWizardDialog()
1416 ImGui::TextWrapped("%s", g_wizardStatus.c_str()); 1480 ImGui::TextWrapped("%s", g_wizardStatus.c_str());
1417 ImGui::Spacing(); 1481 ImGui::Spacing();
1418 ImGui::TextWrapped( 1482 ImGui::TextWrapped(
1419 "Restart Bitflash to start using the SQLite wallet. Your Berkeley " 1483 "The switch takes effect when Bitflash restarts. Until then it is "
1420 "DB wallet.dat is kept untouched as a fallback."); 1484 "still running on the old Berkeley DB wallet. Your wallet.dat is "
1485 "kept untouched as a fallback.");
1421 ImGui::Spacing(); 1486 ImGui::Spacing();
1422 if (ImGui::Button("Close", ImVec2(120.0f, 0.0f))) 1487 if (ImGui::Button("Restart Now", ImVec2(140.0f, 0.0f)))
1488 RestartApplication();
1489 ImGui::SameLine();
1490 if (ImGui::Button("Later", ImVec2(120.0f, 0.0f)))
1423 g_showBackendWizard = false; 1491 g_showBackendWizard = false;
1492 ImGui::Spacing();
1493 ImGui::TextDisabled(
1494 "If you keep mining before restarting, new coins go to the old "
1495 "wallet until you switch.");
1424 } 1496 }
1425 else 1497 else
1426 { 1498 {
@@ -1535,6 +1607,10 @@ int RunGUI(int argc, char* argv[])
1535 g_mineRadio = nMineMode; 1607 g_mineRadio = nMineMode;
1536 strncpy(g_participantPool, strParticipantPool.c_str(), sizeof(g_participantPool)-1); 1608 strncpy(g_participantPool, strParticipantPool.c_str(), sizeof(g_participantPool)-1);
1537 1609
1610 // Kept for the wizard's "Restart Now": relaunch with the same command line.
1611 g_restartArgc = argc;
1612 g_restartArgv = argv;
1613
1538 // First run on a Berkeley DB wallet with no recorded choice yet: offer to 1614 // First run on a Berkeley DB wallet with no recorded choice yet: offer to
1539 // convert to SQLite. Never when already on SQLite, once wallet.sqlite exists, 1615 // convert to SQLite. Never when already on SQLite, once wallet.sqlite exists,
1540 // or once a choice has been recorded in the backend marker. 1616 // or once a choice has been recorded in the backend marker.