Improve Open In apps settings (#4668)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -19,6 +19,7 @@ import { TASK_PROVIDERS } from './task-providers'
|
||||
import { DEFAULT_WORKTREE_CARD_PROPERTIES } from './worktree-card-properties'
|
||||
import { getDefaultSourceControlAiSettings } from './source-control-ai'
|
||||
import { DEFAULT_APP_ICON_ID } from './app-icon'
|
||||
import { DEFAULT_OPEN_IN_APPLICATIONS } from './open-in-applications'
|
||||
|
||||
export { DEFAULT_STATUS_BAR_ITEMS } from './status-bar-defaults'
|
||||
export {
|
||||
@@ -235,7 +236,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
|
||||
httpProxyBypassRules: '',
|
||||
electronHttp1CompatibilityMode: false,
|
||||
openLinksInApp: true,
|
||||
openInApplications: [],
|
||||
openInApplications: [...DEFAULT_OPEN_IN_APPLICATIONS],
|
||||
rightSidebarOpenByDefault: true,
|
||||
showGitIgnoredFiles: true,
|
||||
sourceControlViewMode: 'list',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { normalizeOpenInApplications } from './open-in-applications'
|
||||
import { DEFAULT_OPEN_IN_APPLICATIONS, normalizeOpenInApplications } from './open-in-applications'
|
||||
|
||||
describe('normalizeOpenInApplications', () => {
|
||||
it('trims fields, drops invalid rows, keeps first duplicate id, and caps list', () => {
|
||||
@@ -44,4 +44,11 @@ describe('normalizeOpenInApplications', () => {
|
||||
{ id: 'gen-2', label: 'Zed', command: 'zed' }
|
||||
])
|
||||
})
|
||||
|
||||
it('seeds defaults only when the persisted field is missing', () => {
|
||||
expect(normalizeOpenInApplications(undefined, { seedDefaults: true })).toEqual(
|
||||
DEFAULT_OPEN_IN_APPLICATIONS
|
||||
)
|
||||
expect(normalizeOpenInApplications([], { seedDefaults: true })).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { OpenInApplication } from './types'
|
||||
|
||||
export const OPEN_IN_APPLICATIONS_MAX = 8
|
||||
export const DEFAULT_OPEN_IN_APPLICATIONS: OpenInApplication[] = [
|
||||
{ id: 'vscode', label: 'VS Code', command: 'code' }
|
||||
]
|
||||
|
||||
type NormalizeOpenInApplicationsOptions = {
|
||||
createId?: () => string
|
||||
seedDefaults?: boolean
|
||||
}
|
||||
|
||||
function normalizeToken(value: unknown): string {
|
||||
@@ -19,7 +23,7 @@ export function normalizeOpenInApplications(
|
||||
options: NormalizeOpenInApplicationsOptions = {}
|
||||
): OpenInApplication[] {
|
||||
if (!Array.isArray(value)) {
|
||||
return []
|
||||
return options.seedDefaults ? [...DEFAULT_OPEN_IN_APPLICATIONS] : []
|
||||
}
|
||||
|
||||
const normalized: OpenInApplication[] = []
|
||||
|
||||
Reference in New Issue
Block a user