BookmarkManager API
Complete API reference for the BookmarkManager class
BookmarkManager API Reference
The BookmarkManager class is the central orchestrator for all bookmark operations, UI communication, and system integration.
Class Overview
export class BookmarkManager {
private bookmarks: BookmarkData[];
private readonly SORT_PREFERENCES_KEY = 'sortPreferences';
private deps: IINARuntimeDependencies;
private persistence: BookmarkPersistence;
private importExport: BookmarkImportExport;
private cloudSync: CloudSyncHandler;
private eventIds: string[];
private idCounter: number;
constructor(dependencies: IINARuntimeDependencies)
}The BookmarkManager delegates specialized operations to focused modules: BookmarkPersistence for storage, BookmarkImportExport for data transformation, and CloudSyncHandler for cloud operations.
Constructor
Creates a new BookmarkManager instance and initializes all subsystems.
constructor(dependencies: IINARuntimeDependencies)Parameters:
dependencies- IINA runtime dependencies (console, core, preferences, menu, event, sidebar, overlay, standaloneWindow, utils, file, http)
Initialization sequence:
- Creates persistence, import/export, and cloud sync handlers
- Loads existing bookmarks from storage
- Loads sort preferences
- Sets up event listeners for file-loaded events
- Sets up web UI (sidebar, overlay, window)
- Sets up UI message listeners for all message types
Core Methods
addBookmark()
Creates a new bookmark with auto-populated defaults and validation.
async addBookmark(
title?: string,
timestamp?: number,
description?: string,
tags?: string[]
): Promise<void>Parameters:
title(optional) - Bookmark title. If omitted, auto-generated from filename and timestamp.timestamp(optional) - Playback position in seconds. If omitted, uses current playback position.description(optional) - User description. If omitted, auto-generated.tags(optional) - Array of tags. Defaults to empty array.
Behavior:
- Validates timestamp is within valid range (0 to MAX_TIMESTAMP)
- Enforces maximum bookmark limit from preferences (default: 1000)
- Auto-generates title from filename if not provided
- Sanitizes all inputs to prevent XSS (strips HTML tags)
- Generates unique ID using timestamp + counter + random component
- Saves immediately and refreshes all UIs
Example:
// Quick bookmark at current position with auto-generated title
await manager.addBookmark();
// Custom bookmark with full details
await manager.addBookmark(
"Epic Battle Scene",
2847.5,
"Amazing fight choreography",
["action", "favorite"]
);removeBookmark()
Removes a bookmark by ID.
removeBookmark(id: string): voidParameters:
id- Unique bookmark identifier
Behavior:
- Filters bookmark array to remove matching ID
- Logs warning if bookmark not found
- Saves immediately and refreshes all UIs
updateBookmark()
Updates bookmark properties.
updateBookmark(id: string, data: BookmarkUpdatableFields): voidParameters:
id- Unique bookmark identifierdata- Partial update object containing title, description, and/or tags
Behavior:
- Finds bookmark by ID
- Sanitizes updated fields (strips HTML tags)
- Updates
updatedAttimestamp - Saves immediately and refreshes all UIs
- Logs warning if bookmark not found
Example:
manager.updateBookmark("bookmark_123", {
title: "Updated Title",
description: "New description",
tags: ["updated", "favorite"]
});jumpToBookmark()
Seeks to the bookmark's timestamp in the current media.
jumpToBookmark(id: string): voidParameters:
id- Unique bookmark identifier
Behavior:
- Finds bookmark by ID
- Calls
iina.core.seekTo(timestamp)to jump to position - Logs error if bookmark not found or seek unavailable
- Shows OSD message if seek operation fails
getBookmarksForFile()
Retrieves bookmarks filtered by file path.
getBookmarksForFile(filepath?: string): BookmarkData[]Parameters:
filepath(optional) - Absolute path to media file. If omitted, returns all bookmarks.
Returns:
- Array of matching bookmarks
Example:
// Get all bookmarks
const all = manager.getBookmarksForFile();
// Get bookmarks for specific file
const movieBookmarks = manager.getBookmarksForFile('/Movies/Inception.mp4');getAllBookmarks()
Returns a copy of all bookmarks.
getAllBookmarks(): BookmarkData[]Returns:
- Array copy of all bookmarks (prevents external mutation)
getBookmarkCount()
Returns the total number of bookmarks.
getBookmarkCount(): numberReturns:
- Total bookmark count
destroy()
Cleans up event listeners registered by this instance.
destroy(): voidBehavior:
- Unregisters all file-loaded event listeners
- Clears event ID array
Call this method before discarding a BookmarkManager instance to prevent memory leaks.
Private Methods
The BookmarkManager uses several private methods for internal operations:
UI Communication
setupWebUI()- Loads sidebar, overlay, and window HTML filessetupUIMessageListeners()- Registers message handlers for all UI message typeshandleUIMessage()- Routes incoming messages to appropriate handlersgetUITarget()- Returns the correct UI API object (sidebar/overlay/window)sendCurrentFilePath()- Sends current media file path to UIsendBookmarksToUI()- Sends filtered bookmarks to UIsendBookmarkDefaults()- Sends auto-populated bookmark defaults for creationrefreshUI()- Refreshes all three UI interfaces
Event Handling
setupEventListeners()- Registers file-loaded events and menu itemsloadSortPreferences()- Loads and sends sort preferences to all UIssaveSortPreferencesFromUI()- Saves sort preferences from UI
Data Management
saveBookmarks()- Delegates to BookmarkPersistence, then refreshes UIsimportBookmarks()- Delegates to BookmarkImportExportexportBookmarks()- Delegates to BookmarkImportExporthandleCloudSync()- Delegates to CloudSyncHandler
File Reconciliation
handleReconcileFiles()- Finds bookmarks with missing fileshandleFileReconciliation()- Routes reconciliation actions (update_path, remove_bookmark, search_similar)updateBookmarkPath()- Updates a bookmark's file pathsearchForSimilarFiles()- Placeholder for similar file search (not yet implemented)
Utilities
generateId()- Generates unique bookmark IDs using timestamp + counter + random
UI Message Protocol
The BookmarkManager handles the following messages from UIs:
Incoming Messages (UI → Backend):
UI_READY- UI initialization complete, triggers bookmark syncREQUEST_FILE_PATH- Request current media file pathREQUEST_BOOKMARK_DEFAULTS- Request auto-populated defaults for new bookmarkADD_BOOKMARK- Create new bookmarkDELETE_BOOKMARK- Remove bookmark by IDUPDATE_BOOKMARK- Update bookmark fieldsJUMP_TO_BOOKMARK- Seek to bookmark timestampHIDE_OVERLAY- Hide overlay UIIMPORT_BOOKMARKS- Import bookmarks from external dataEXPORT_BOOKMARKS- Export bookmarks to JSON/CSVCLOUD_SYNC_REQUEST- Perform cloud sync operationFILE_RECONCILIATION_REQUEST- Handle file path reconciliationRECONCILE_FILES- Show file reconciliation dialogSAVE_SORT_PREFERENCES- Save sort preferences
Outgoing Messages (Backend → UI):
BOOKMARKS_UPDATED- Current bookmarks for fileCURRENT_FILE_PATH- Current media file pathBOOKMARK_ADDED- Confirmation of bookmark creationBOOKMARK_DELETED- Confirmation of bookmark deletionBOOKMARK_JUMPED- Confirmation of seek operationBOOKMARK_DEFAULTS- Auto-populated bookmark defaultsSORT_PREFERENCES- Current sort preferencesIMPORT_RESULT- Import operation resultEXPORT_RESULT- Export operation resultCLOUD_SYNC_RESULT- Cloud sync operation resultSHOW_FILE_RECONCILIATION_DIALOG- Trigger reconciliation dialogFILE_RECONCILIATION_RESULT- File reconciliation result
Example Usage
// Initialize BookmarkManager with IINA runtime dependencies
const manager = new BookmarkManager({
console: iina.console,
core: iina.core,
preferences: iina.preferences,
menu: iina.menu,
event: iina.event,
sidebar: iina.sidebar,
overlay: iina.overlay,
standaloneWindow: iina.standaloneWindow,
utils: iina.utils,
file: iina.file,
http: httpAdapter
});
// Add a bookmark at current position
await manager.addBookmark();
// Add a bookmark with custom details
await manager.addBookmark(
"Important Scene",
1234.5,
"Key plot point revealed",
["plot", "important"]
);
// Get bookmarks for current file
const currentPath = iina.core.status.path;
const bookmarks = manager.getBookmarksForFile(currentPath);
// Jump to a bookmark
manager.jumpToBookmark("bookmark_id_here");
// Update bookmark
manager.updateBookmark("bookmark_id", {
title: "Updated Title",
tags: ["updated"]
});
// Remove bookmark
manager.removeBookmark("bookmark_id");
// Clean up when done
manager.destroy();BookmarkManager delegates to internal modules: BookmarkPersistence (file I/O), BookmarkImportExport (import/export), and CloudSyncHandler (cloud sync). See the Interfaces page for their type definitions.