Skip to content

Conversation

@ILDaviz
Copy link
Member

@ILDaviz ILDaviz commented Aug 9, 2025

This Pull Request introduces a persistent database into the application and implements one of the most important features for user experience: change history with Undo/Redo.

To achieve this, SQLite has been integrated via the better-sqlite3 package, chosen for its excellent performance and solid integration with the Node.js/Electron environment. The introduction of the database lays the foundation for future features that require data persistence.

The main changes included in this PR are:

  1. Database Integration with SQLite (better-sqlite3) The better-sqlite3 dependency has been added to provide a robust, fast, local SQL database. All database interaction logic is handled in Electron's main process to ensure security and performance. The build process has been updated to correctly handle this native dependency across all platforms (macOS, Windows, Linux).

  2. Migration System: A basic migration logic has been added to manage the evolution of the database schema in a controlled and versioned manner. On application startup, the migration script checks the user's database state and applies any necessary changes, ensuring the schema is always up-to-date with the latest required version.

  3. Code History with Undo/Redo: A complete history of code changes has been implemented for each tab, offering users a safety net during editing. The history is non-destructive and uses a pointer-based system to navigate between past and future code states. It saves not only the code content but also the exact cursor position for a faithful restoration of the editing state. It supports standard keyboard shortcuts: Ctrl/Cmd+Z for Undo and Ctrl/Cmd+Y (or Ctrl/Cmd+Shift+Z) for Redo. To optimize performance, a new state is added only if the code has actually changed, avoiding unnecessary duplicates.

Related Improvements to the Build Process
To properly support the native better-sqlite3 dependency across all platforms, the build and Continuous Integration process has been significantly improved. These changes are intended to resolve the previous cross-platform build failures: The build scripts (package.json, build.js) have been refactored to follow electron-builder best practices. The GitHub Actions workflow (.github/workflows/build.yml) has been updated to use npm ci and OS-specific caches, resolving previous build failures and ensuring maximum reliability. Builds for macOS, Windows, and Linux are now stable, reliable, and fully automated.

How to Test
Pull this branch.

  • Run npm install (or npm ci).
  • Start the application in dev mode (npm run dev).
  • Open a tab, then write and edit some code.
  • Verify that Undo works correctly.
  • Verify that Redo works correctly.
  • Close and reopen the application: the code in the tab should be persistent.

Let me know if you have any questions or feedback!

@ILDaviz ILDaviz changed the title Features/add sqlite migration history [Draft] Features/add sqlite migration history Aug 9, 2025
@ILDaviz ILDaviz changed the title [Draft] Features/add sqlite migration history [Draft] Feature Added Database (SQLite) and Code History with Undo/Redo Aug 11, 2025
@ILDaviz ILDaviz changed the title [Draft] Feature Added Database (SQLite) and Code History with Undo/Redo Feature Added Database (SQLite) and Code History with Undo/Redo Aug 21, 2025
@ILDaviz ILDaviz changed the title Feature Added Database (SQLite) and Code History with Undo/Redo [Draft] Feature Added Database (SQLite) and Code History with Undo/Redo Aug 21, 2025
@ILDaviz ILDaviz changed the title [Draft] Feature Added Database (SQLite) and Code History with Undo/Redo [Test] Feature Added Database (SQLite) and Code History with Undo/Redo Aug 31, 2025
@ILDaviz ILDaviz changed the title [Test] Feature Added Database (SQLite) and Code History with Undo/Redo Feature Added Database (SQLite) and Code History with Undo/Redo Aug 31, 2025
@ILDaviz ILDaviz changed the title Feature Added Database (SQLite) and Code History with Undo/Redo [Test] Feature Added Database (SQLite) and Code History with Undo/Redo Sep 6, 2025
@ILDaviz ILDaviz self-assigned this Sep 7, 2025
@ILDaviz ILDaviz changed the title [Test] Feature Added Database (SQLite) and Code History with Undo/Redo Feature Added Database (SQLite) and Code History with Undo/Redo Sep 19, 2025
@ILDaviz ILDaviz changed the title Feature Added Database (SQLite) and Code History with Undo/Redo [test] Feature Added Database (SQLite) and Code History with Undo/Redo Sep 19, 2025
@ILDaviz ILDaviz changed the title [test] Feature Added Database (SQLite) and Code History with Undo/Redo Feature Added Database (SQLite) and Code History with Undo/Redo Sep 20, 2025
@luanfreitasdev luanfreitasdev self-requested a review September 20, 2025 14:40
@luanfreitasdev
Copy link
Member

I've tested on macOS and Windows, and it works fine

@saeedvaziry saeedvaziry merged commit 922702e into tweakphp:main Sep 27, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants