Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

1.3 KB
Raw Blame
import type { ConfigOpenResult } from './config-file.types'
import { stat } from 'node:fs/promises'
import { dirname } from 'node:path'
import { defineService, openDirectory, openUrl } from 'dsh-tauri'
import { resolveSettingsFilePath } from '../utils/paths'

/** 设置文件:存在就用系统默认应用打开,未创建则退到所在目录(编辑器选择交给官方 open-in-app)。 */
export const configFile = defineService({
  async resolve(): Promise<ConfigOpenResult> {
    const path = resolveSettingsFilePath()
    return { ok: true, path, opened: 'file' }
  },
  async open(): Promise<ConfigOpenResult> {
    const path = resolveSettingsFilePath()
    try {
      const servesFile = await isFile(path)
      if (servesFile)
        await openUrl(path)
      else
        await openDirectory(dirname(path))
      return { ok: true, path: servesFile ? path : dirname(path), opened: servesFile ? 'file' : 'directory' }
    }
    catch (error) {
      return { ok: false, path, error: error instanceof Error ? error.message : String(error) }
    }
  },
})

async function isFile(path: string): Promise<boolean> {
  try {
    return (await stat(path)).isFile()
  }
  catch (error) {
    if ((error as NodeJS.ErrnoException).code === 'ENOENT')
      return false
    throw error
  }
}