// Name: Finicky Default Browser // Description: Sets the default browser for Finicky // Author: Strajk import '@johnlindquist/kit' const finickyPath = home('.finicky.js') // List of possible browsers to select from const possibleBrowsers = [ 'Google Chrome', 'Google Chrome Dev', 'Firefox', 'Firefox Developer Edition', 'Safari', 'Opera', 'Brave', 'Microsoft Edge', 'Browserosaurus', ] try { // Read the content of the Finicky configuration file const configContent = await readFile(finickyPath, 'utf8') // Regular expression to find the default browser setting in the config const defaultBrowserRegex = /defaultBrowser:\s*"(.*?)",\s*\/\/(.*)/ const match = configContent.match(defaultBrowserRegex) // Extract the current default browser and comment from the config, if they exist const currentDefaultBrowser = match ? match[1] : null const currentComment = match ? match[2].trim() : null // Prompt the user to select a new default browser const selectedBrowser = await select({ message: 'Select a default browser:', choices: possibleBrowsers, defaultValue: currentDefaultBrowser, }) // Create a new comment based on the previously selected browser const newComment = currentDefaultBrowser ? ` Previously: ${currentDefaultBrowser}` : '' // Replace the old default browser setting with the new one, including the updated comment const newConfigContent = configContent.replace( defaultBrowserRegex, `defaultBrowser: "${selectedBrowser}", //${newComment}` ) // Write the updated content back to the Finicky configuration file await writeFile(finickyPath, newConfigContent) // Display a notification to confirm the update await notify({ title: 'Finicky Config Updated', message: `Default browser set to ${selectedBrowser}`, }) } catch (error) { // Handle errors, such as the config file not existing console.error(`Failed to update Finicky config: ${error}`) await notify({ title: 'Finicky Config Update Failed', message: `Error: ${error}`, }) }