Commit graph

17 commits

Author SHA1 Message Date
Kristijan Ribarić
c8deb36100 Re-implemented workspace reordering to be based on dragging. 2024-10-16 10:08:45 +02:00
Kristijan Ribarić
17cace3097 feat: Allow workspace reordering
This commit introduces the ability to reorder workspaces in the workspace manager. This adds functionality to move workspaces up and down within the list, allowing users to customize the order in which they appear.

- Added new buttons for moving workspaces up and down.
- Implemented `moveWorkspaceUp` and `moveWorkspaceDown` methods in `ZenWorkspacesStorage` to handle workspace reordering.
- Updated `ZenWorkspaces` to handle the new reorder mode and button events.
- Modified the workspace list UI to display reorder buttons and indicate when reorder mode is active.

These changes provide users with more control over their workspace organization and improve the overall usability of the workspace manager.
2024-10-15 20:05:07 +02:00
Kristijan Ribarić
b296405a45 Fix: Use integer positions for workspaces
This commit changes the `position` column in the `workspaces` table to be an `INTEGER` instead of a `REAL` data type. This change is made to ensure that workspace positions are always whole numbers, which prevents issues with floating-point precision and ensures consistent ordering of workspaces.

Additionally, it updates the logic for calculating new workspace positions to use `Math.floor` to round down to the nearest integer, ensuring that positions are always integers.

This change also adjusts the `minGap` constant used in the `shouldReorderWorkspaces` function to `1`, which reflects the minimum allowed gap between workspace positions now that they are integers.
2024-10-09 19:49:45 +02:00
Kristijan Ribarić
8ca8157e61 feat: Improve workspace ordering and changes tracking
This commit introduces improvements to workspace ordering and change tracking in the Zen Workspaces system:

- **Workspace Ordering:**
    - Uses `REAL` data type for `position` in `zen_workspaces` table, allowing for more precise and efficient ordering.
    - Introduces a new `updateWorkspaceOrder` method to update workspace positions.
    - Reorders workspaces with large increments to avoid frequent reordering, ensuring consistent ordering after changes.
    - Implements a mechanism to check for necessary reordering after position updates and reorder all workspaces if required.
- **Changes Tracking:**
    - Tracks changes to workspaces by inserting a record in `zen_workspaces_changes` for each modified workspace.
    - Adds an index on `uuid` column in `zen_workspaces_changes` table for faster querying.
    - Updates `getLastChangeTimestamp` method to return the last change timestamp from the changes tracking table, providing accurate timestamp for changes.

These changes optimize workspace management, improve accuracy of ordering, and enhance the performance of change tracking.
2024-10-09 19:38:06 +02:00
Kristijan Ribarić
24d7af3da0 Fix: Ensure tab context works after moving a tab to different workspace.
Calling to _workspaces() always gets the fresh data from db, moved caching responsibility to db for getWorkspaces().
2024-10-09 18:14:09 +02:00
Kristijan Ribarić
9abd2d9cc1 feat(workspaces): Migrate workspaces from JSON to the new storage after sync engine has been registered. 2024-10-06 08:35:53 +02:00
Kristijan Ribarić
d3ac1895e5 feat(workspaces): Improve workspace change notification and handling
This commit improves the notification and handling of workspace changes by:

- **Introducing a dedicated observer notification system:** The `ZenWorkspacesStorage` now uses a private helper method (`_notifyWorkspacesChanged`) to notify observers with a list of changed workspace UUIDs. This provides a more efficient and flexible notification system.
- **Updating `ZenWorkspacesTracker` to parse UUIDs:** The `ZenWorkspacesTracker` now correctly parses the JSON stringified array of UUIDs received from the observer, allowing it to handle multiple workspace changes in a single notification.
- **Refactoring `saveWorkspace`, `removeWorkspace`, `setDefaultWorkspace`, and `updateWorkspaceOrder`:** These methods now consistently collect and notify observers about changed UUIDs.
- **Removing unnecessary code:** The previous approach of notifying observers individually for each change has been removed, leading to code simplification and reduced complexity.

This commit ensures that workspace changes are more reliably and efficiently tracked, leading to a smoother and more responsive workspace management experience.
2024-10-05 22:09:54 +02:00
Kristijan Ribarić
86578cb4d3 feat(workspace): Move observer notifications to workspaces storage 2024-10-05 21:16:07 +02:00
Kristijan Ribarić
863dcfa705 feat(workspaces): remove unused used field from workspaces
This commit removes the `used` field from the Workspaces database table and Zen Workspace objects.

The `used` field was originally intended to track whether a workspace was currently being used, but it turned out to be unnecessary. This change simplifies the data model and removes redundant information.
2024-10-05 20:16:20 +02:00
Kristijan Ribarić
0d161326ef feat: Add workspace ordering and changes tracking
This commit introduces workspace ordering and a new mechanism for tracking changes to workspaces.

**Changes:**

- **Workspace Ordering:** Workspaces can now be ordered using a `position` field. This allows for user-defined ordering of workspaces, improving usability.
- **Changes Tracking:** A new `zen_workspaces_changes` table is added to track changes to workspaces. This allows for more efficient sync operations and improved error handling.

**Benefits:**

- **Improved Workspace Management:** Users can now customize the order of their workspaces.
- **More Efficient Sync:** Changes tracking enables faster and more accurate synchronization of workspaces across devices.
- **Enhanced Error Handling:** Changes tracking helps to identify and resolve conflicts during sync.

**Notes:**

- This change requires deleting the zen_workspaces table in places db
2024-10-05 19:20:19 +02:00
Kristijan Ribarić
e366e624d1 Fix: Ensure only one workspace is marked as default
This commit ensures that only one workspace can be marked as default. Previously, multiple workspaces could be marked as default, leading to unexpected behavior.

The commit introduces a transaction to update all workspaces, setting `is_default` to `0` for all workspaces except the one being saved as default. This prevents multiple workspaces from being marked as default.
2024-10-04 22:40:09 +02:00
mauro-balades
76d22a1f15
Made the code look cleaner 2024-10-04 18:21:39 +02:00
mauro-balades
5822df61e5
Refactor: Migrate workspaces from JSON to new storage system 2024-10-03 22:31:07 +02:00
mauro-balades
1ed9227c01
Added workspaces migration system 2024-10-03 19:38:51 +02:00
Kristijan Ribarić
9bcb66c768 feat(workspaces): Use preferences to manage active workspace
This commit updates the workspaces system to use preferences to manage the active workspace, instead of storing the active state in each workspace object.

The following changes were made:

- **ZenWorkspaces.mjs:**
    - Removed the `used` property from workspace objects and replaced it with a preference (`zen.workspaces.active`) to store the active workspace ID.
    - Modified the `getActiveWorkspace` and `changeWorkspace` methods to use preferences instead of the `used` property.
    - Added a new `isWorkspaceActive` method to check if a workspace is active.
- **ZenWorkspacesStorage.mjs:**
    - Removed the `is_active` column from the `zen_workspaces` table.
    - Removed the `setActiveWorkspace` method as the active workspace is now managed by preferences.

This change simplifies the code and makes it easier to manage the active workspace across multiple browser windows and doesn't write to the database on every workspace change. Additionaly, it enables local active workspace selection when workspace sync is implemented.
2024-10-03 10:19:18 +02:00
Kristijan Ribarić
511281c688 feat(db): rename workspace table to zen_workspaces
Renames the `moz_workspaces` table to `zen_workspaces` for consistency and better organization.
2024-10-02 15:32:47 +02:00
Kristijan Ribarić
de8a857549 feat(workspaces): Store workspaces in a database
This commit introduces a new `ZenWorkspacesStorage` class to handle the persistence of workspaces in a database. The previous implementation used JSON files, but this approach brings several advantages, including:

- Improved performance and scalability
- Easier data management and synchronization
- Enhanced security and data integrity

This change removes the reliance on JSON files and streamlines workspace management, leading to a more robust and reliable system.
2024-10-02 09:37:09 +02:00