Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ jobs:
- name: Tests
run: pytest tests/ -v

rust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
with:
workspaces: src-tauri -> target
- name: Run tests
run: cargo test -p kopdeltav --manifest-path src-tauri/Cargo.toml
- name: Clippy
run: cargo clippy -p kopdeltav --manifest-path src-tauri/Cargo.toml -- -D warnings

frontend:
runs-on: ubuntu-latest
defaults:
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ jobs:
- name: Install Tauri CLI
run: cargo install tauri-cli --version "^2"

- name: Copy Python backend into Tauri resources
run: |
mkdir -p src-tauri/resources/kopdeltav
cp api.py src-tauri/resources/
cp launcher.py src-tauri/resources/
cp kopdeltav/*.py src-tauri/resources/kopdeltav/
cp requirements.txt src-tauri/resources/
shell: bash

- name: Build Tauri app
run: cargo tauri build --bundles nsis
working-directory: src-tauri
Expand All @@ -66,5 +57,5 @@ jobs:
with:
draft: true
name: "KSPDeltaVForMods ${{ github.ref_name }}"
body: "Windows desktop build.\n\n**Requirements:**\n- Python 3.10+\n- `pip install fastapi uvicorn[standard] python-multipart`"
body: "Windows desktop build. No external dependencies required."
files: src-tauri/target/release/bundle/nsis/*.exe
3 changes: 2 additions & 1 deletion frontend/src/components/upload/ConfigUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ async function onFileSelect(event: FileUploadSelectEvent): Promise<void> {

uploading.value = true
try {
const uploadResult = await api.uploadConfig(file)
const fileContent = await file.text()
const uploadResult = await api.uploadConfig(fileContent)
await afterSuccess(uploadResult.count)
} catch (err) {
toast.add({
Expand Down
126 changes: 42 additions & 84 deletions frontend/src/composables/useApi.ts
Original file line number Diff line number Diff line change
@@ -1,117 +1,75 @@
import { invoke } from '@tauri-apps/api/core'
import { useToast } from 'primevue/usetoast'
import type {
AtmoProfileResponse,
BodyDetail,
BodySummary,
DestinationEntry,
HealthResponse,
HohmannRequest,
HohmannResponse,
LaunchRequest,
LaunchResponse,
RouteRequest,
RouteResponse,
ScanRequest,
SystemResponse,
TsiolkovskyRequest,
TsiolkovskyResponse,
UploadResponse,
DestinationEntry,
} from '@/types/api'

const API_ORIGIN = import.meta.env.DEV
? `${window.location.protocol}//${window.location.host}`
: 'http://localhost:8000'
const API_PREFIX = import.meta.env.DEV ? '/api' : ''

function buildUrl(path: string, lang?: string): string {
const url = new URL(`${API_PREFIX}${path}`, API_ORIGIN)
if (lang) {
url.searchParams.set('lang', lang)
}
return url.toString()
}

async function request<T>(
path: string,
options: RequestInit = {},
lang?: string,
): Promise<T> {
const response = await fetch(buildUrl(path, lang), {
headers: { 'Content-Type': 'application/json', ...options.headers },
...options,
})
if (!response.ok) {
const body = await response.json().catch(() => ({ detail: response.statusText }))
throw new Error(body.detail ?? `HTTP ${response.status}`)
}
return response.json() as Promise<T>
}

/** Wait for the backend to become available (used by Tauri on startup). */
export async function waitForBackend(
maxRetries = 60,
intervalMs = 1000,
): Promise<boolean> {
for (let i = 0; i < maxRetries; i++) {
try {
const res = await fetch(buildUrl('/health'))
if (res.ok) return true
} catch {
// Backend not ready yet
}
await new Promise((r) => setTimeout(r, intervalMs))
}
return false
}

export function useApi(lang?: string) {
const toast = useToast()

function handleError(err: unknown): void {
const message = err instanceof Error ? err.message : String(err)
toast.add({ severity: 'error', summary: 'API Error', detail: message, life: 5000 })
toast.add({ severity: 'error', summary: 'Error', detail: message, life: 5000 })
}

return {
health: () => request<HealthResponse>('/health'),
listBodies: () => request<BodySummary[]>('/bodies', {}, lang),
getBody: (name: string) => request<BodyDetail>(`/bodies/${encodeURIComponent(name)}`, {}, lang),
health: () => invoke<HealthResponse>('health'),
listBodies: () => invoke<BodySummary[]>('list_bodies', { lang }),
getBody: (name: string) => invoke<BodyDetail>('get_body', { name, lang }),
getBodyMoons: (name: string) =>
request<DestinationEntry[]>(`/bodies/${encodeURIComponent(name)}/moons`),
invoke<DestinationEntry[]>('get_body_moons', { name }),

uploadConfig: async (file: File) => {
const formData = new FormData()
formData.append('file', file)
const response = await fetch(buildUrl('/upload-config', lang), {
method: 'POST',
body: formData,
})
if (!response.ok) {
const body = await response.json().catch(() => ({ detail: response.statusText }))
throw new Error(body.detail ?? `HTTP ${response.status}`)
}
return response.json() as Promise<UploadResponse>
},
uploadConfig: (fileContent: string) =>
invoke<UploadResponse>('upload_config', { fileContent }),

scan: (req: ScanRequest) =>
request<UploadResponse>('/scan', { method: 'POST', body: JSON.stringify(req) }),
invoke<UploadResponse>('scan_gamedata', {
path: req.gamedata_path,
exclude: req.exclude_dirs,
}),

calcLaunch: (req: { body_name: string; target_altitude: number }) =>
invoke<LaunchResponse>('calc_launch', {
bodyName: req.body_name,
targetAltitude: req.target_altitude,
}),

calcHohmann: (req: { body_name: string; parking_altitude: number; target_sma: number }) =>
invoke<HohmannResponse>('calc_hohmann', {
bodyName: req.body_name,
parkingAlt: req.parking_altitude,
targetSma: req.target_sma,
}),

calcTsiolkovsky: (req: { delta_v: number; isp: number; wet_mass: number }) =>
invoke<TsiolkovskyResponse>('calc_tsiolkovsky', {
deltaV: req.delta_v,
isp: req.isp,
wetMass: req.wet_mass,
}),

calcLaunch: (req: LaunchRequest) =>
request<LaunchResponse>('/calc/launch', { method: 'POST', body: JSON.stringify(req) }, lang),
calcHohmann: (req: HohmannRequest) =>
request<HohmannResponse>('/calc/hohmann', { method: 'POST', body: JSON.stringify(req) }, lang),
calcTsiolkovsky: (req: TsiolkovskyRequest) =>
request<TsiolkovskyResponse>('/calc/tsiolkovsky', { method: 'POST', body: JSON.stringify(req) }, lang),
getSystem: () => invoke<SystemResponse>('get_system'),
getDestinations: () => invoke<DestinationEntry[]>('get_destinations'),

getSystem: () => request<SystemResponse>('/system'),
getDestinations: () => request<DestinationEntry[]>('/system/destinations'),
calcRoute: (req: RouteRequest) =>
request<RouteResponse>('/calc/route', { method: 'POST', body: JSON.stringify(req) }),
calcRoute: (req: { destination: string | null; moon: string | null }) =>
invoke<RouteResponse>('calc_route', {
destination: req.destination,
moon: req.moon,
}),

getAtmoProfile: (name: string, steps?: number) => {
const params = steps ? `?steps=${steps}` : ''
return request<AtmoProfileResponse>(`/atmo-profile/${encodeURIComponent(name)}${params}`, {}, lang)
},
getAtmoProfile: (name: string, steps?: number) =>
invoke<AtmoProfileResponse>('get_atmo_profile', { name, steps }),

handleError,
}
Expand Down
47 changes: 13 additions & 34 deletions frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,21 @@ import 'primeicons/primeicons.css'
import App from './App.vue'
import router from './router'
import i18n from './i18n'
import { waitForBackend } from './composables/useApi'
import './assets/styles/main.css'

async function bootstrap(): Promise<void> {
// In production (Tauri), wait for the Python backend to start
if (!import.meta.env.DEV) {
const ready = await waitForBackend()
if (!ready) {
const el = document.getElementById('app')
if (el) {
el.textContent =
'Failed to connect to Python backend. Ensure Python 3.10+ is installed and on PATH.'
el.style.color = '#ef4444'
el.style.padding = '2rem'
el.style.fontFamily = 'sans-serif'
}
return
}
}
const app = createApp(App)

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(i18n)
app.use(PrimeVue, {
theme: {
preset: Aura,
options: {
darkModeSelector: '.app-dark',
},
app.use(createPinia())
app.use(router)
app.use(i18n)
app.use(PrimeVue, {
theme: {
preset: Aura,
options: {
darkModeSelector: '.app-dark',
},
})
app.use(ToastService)

app.mount('#app')
}
},
})
app.use(ToastService)

bootstrap()
app.mount('#app')
7 changes: 0 additions & 7 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,5 @@ export default defineConfig({
},
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
})
Loading
Loading