chore: add hide from dock preference to settings

This commit is contained in:
haritabh-z01 2025-12-12 00:08:54 +05:30
parent df8c2fa42f
commit b7c2dd8843
6 changed files with 81 additions and 11 deletions

View file

@ -49,6 +49,11 @@ const defaultSettings: AppSettingsData = {
ui: {
theme: "system",
},
preferences: {
launchAtLogin: true,
showWidgetWhileInactive: true,
showInDock: true,
},
transcription: {
language: "en",
autoTranscribe: true,

View file

@ -158,6 +158,7 @@ export interface AppSettingsData {
launchAtLogin?: boolean;
minimizeToTray?: boolean;
showWidgetWhileInactive?: boolean;
showInDock?: boolean;
};
telemetry?: {
enabled?: boolean;

View file

@ -183,13 +183,15 @@ export class AppManager {
}
private setupSettingsEventListeners(settingsService: SettingsService): void {
// Handle preference changes (widget visibility)
// Handle preference changes (widget visibility, dock visibility)
settingsService.on(
"preferences-changed",
async ({
showWidgetWhileInactiveChanged,
showInDockChanged,
}: {
showWidgetWhileInactiveChanged: boolean;
showInDockChanged: boolean;
}) => {
if (showWidgetWhileInactiveChanged) {
const recordingManager =
@ -197,6 +199,9 @@ export class AppManager {
const isIdle = recordingManager.getState() === "idle";
await this.updateWidgetVisibility(isIdle);
}
if (showInDockChanged) {
settingsService.syncDockVisibility();
}
},
);
@ -231,17 +236,21 @@ export class AppManager {
this.windowManager.createOrShowMainWindow();
// Apply dock visibility based on user preference (macOS only)
if (app.dock) {
app.dock
.show()
.then(() => {
logger.main.info("Explicitly showing app in dock");
})
.catch((error) => {
logger.main.error("Error showing app in dock", error);
});
} else {
logger.main.warn("app.dock is not available");
if (preferences.showInDock) {
app.dock
.show()
.then(() => {
logger.main.info("Showing app in dock based on preference");
})
.catch((error) => {
logger.main.error("Error showing app in dock", error);
});
} else {
app.dock.hide();
logger.main.info("Hiding app from dock based on preference");
}
}
}

View file

@ -40,10 +40,18 @@ export default function PreferencesSettingsPage() {
});
};
const handleShowInDockChange = (checked: boolean) => {
updatePreferencesMutation.mutate({
showInDock: checked,
});
};
const showWidgetWhileInactive =
preferencesQuery.data?.showWidgetWhileInactive ?? true;
const minimizeToTray = preferencesQuery.data?.minimizeToTray ?? false;
const launchAtLogin = preferencesQuery.data?.launchAtLogin ?? true;
const showInDock = preferencesQuery.data?.showInDock ?? true;
const isMac = window.electronAPI.platform === "darwin";
return (
<div className="container mx-auto p-6 max-w-5xl">
@ -115,6 +123,29 @@ export default function PreferencesSettingsPage() {
<Separator />
{/* Show in Dock Section (macOS only) */}
{isMac && (
<>
<div className="flex items-center justify-between">
<div className="space-y-1">
<Label className="text-base font-medium text-foreground">
Show app in dock
</Label>
<p className="text-xs text-muted-foreground">
Display the application icon in the macOS dock
</p>
</div>
<Switch
checked={showInDock}
onCheckedChange={handleShowInDockChange}
disabled={updatePreferencesMutation.isPending}
/>
</div>
<Separator />
</>
)}
{/* Theme Section */}
<div className="flex items-center justify-between">
<div className="space-y-1">

View file

@ -22,6 +22,7 @@ export interface AppPreferences {
launchAtLogin: boolean;
minimizeToTray: boolean;
showWidgetWhileInactive: boolean;
showInDock: boolean;
}
export class SettingsService extends EventEmitter {
@ -289,6 +290,7 @@ export class SettingsService extends EventEmitter {
launchAtLogin: preferences?.launchAtLogin ?? true,
minimizeToTray: preferences?.minimizeToTray ?? true,
showWidgetWhileInactive: preferences?.showWidgetWhileInactive ?? true,
showInDock: preferences?.showInDock ?? true,
};
}
@ -315,6 +317,7 @@ export class SettingsService extends EventEmitter {
changes: preferences,
showWidgetWhileInactiveChanged:
preferences.showWidgetWhileInactive !== undefined,
showInDockChanged: preferences.showInDock !== undefined,
});
}
@ -332,6 +335,26 @@ export class SettingsService extends EventEmitter {
});
}
/**
* Sync the dock visibility setting with macOS
* This ensures the dock visibility matches our stored preference
*/
syncDockVisibility(): void {
// Only applicable on macOS where app.dock exists
if (!app.dock) {
return;
}
// Get the current preference asynchronously and apply it
this.getPreferences().then((preferences) => {
if (preferences.showInDock) {
app.dock?.show();
} else {
app.dock?.hide();
}
});
}
/**
* Get telemetry settings
*/

View file

@ -41,6 +41,7 @@ const AppPreferencesSchema = z.object({
launchAtLogin: z.boolean().optional(),
minimizeToTray: z.boolean().optional(),
showWidgetWhileInactive: z.boolean().optional(),
showInDock: z.boolean().optional(),
});
const UIThemeSchema = z.object({