The Electron BrowserWindow to attach dialogs to
Optional
targetPath: stringOptional pre-defined export path (bypasses user prompt)
Promise resolving to object containing success status, message, and path
// Export all data with user-selected path
const result = await exportAllStatisticsToJSON(mainWindow);
if (result.success) {
showNotification(`Full backup saved to ${result.filePath}`);
}
export async function exportAllStatisticsToJSON(
mainWindow: BrowserWindow,
targetPath?: string,
): Promise<{ success: boolean; message?: string; filePath?: string }> {
try {
// Get all statistics data
const statistics = await getStatistics();
const skippedTracks = await getSkippedTracks();
const artistMetrics = await aggregateArtistSkipMetrics();
const libraryStats = await calculateLibrarySkipStatistics();
const timePatterns = await analyzeTimeBasedPatterns();
// Combine all data
const exportData = {
statistics,
skippedTracks,
artistMetrics,
libraryStats,
timePatterns,
exportDate: new Date().toISOString(),
version: app.getVersion(),
};
// Determine file path
let filePath = targetPath;
if (!filePath) {
const timestamp = new Date()
.toISOString()
.replace(/:/g, "-")
.split(".")[0];
const defaultFileName = `spotify_skip_tracker_data_${timestamp}.json`;
filePath = await promptForExportLocation(
mainWindow,
join(ensureExportDir(), defaultFileName),
[{ name: "JSON Files", extensions: ["json"] }],
);
if (!filePath) {
return { success: false, message: "Export was canceled" };
}
}
// Write the JSON file
writeFileSync(filePath, JSON.stringify(exportData, null, 2));
return {
success: true,
message: "All statistics data exported successfully",
filePath,
};
} catch (error) {
console.error("Error exporting statistics to JSON:", error);
return {
success: false,
message: `Error exporting data: ${error instanceof Error ? error.message : "Unknown error"}`,
};
}
}
Exports all statistics data to JSON
Creates a comprehensive JSON export containing the complete dataset of all statistics, metrics, and analyzed patterns. This is the most complete export option, providing structured data that preserves all relationships between different statistical elements.
The export includes:
This function is ideal for: