This commit addresses a potential crash that could occur when the active workspace no longer exists. The issue was that the code attempted to access the `uuid` property of the first workspace in the list even if the list was empty.
This commit fixes the issue by using optional chaining (`?.`) to safely access the `uuid` property, ensuring the code doesn't crash if the workspace list is empty.
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.
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.
This commit refactors the ZenTabUnloader class to add support for unloading inactive tabs. It introduces a new class called ZenTabsIntervalUnloader, which periodically checks for inactive tabs and discards them if they meet certain criteria. The criteria include being inactive for a specified timeout period and not meeting any exclusion URLs.
The commit also adds a new class called ZenTabsObserver, which listens to various tab events and notifies the ZenTabUnloader when a tab's activity changes.
These changes improve the efficiency of tab management and help reduce resource usage by unloading tabs that are not actively being used.