Преглед на файлове

allows to pass additional arguments

UwU преди 2 месеца
родител
ревизия
1f55142949

+ 8 - 0
src/main/ipc/config.handlers.ts

@@ -9,6 +9,8 @@ import {
   getLweRepoUrl,
   getLweRepoBranch,
   setLweRepo,
+  getLweCmakeArgs,
+  setLweCmakeArgs,
   importWEConfigFile,
   createFreshConfig,
   getConfiguredBackupPath,
@@ -41,6 +43,7 @@ export function registerConfigHandlers(): void {
     defaultFps: getDefaultFps(),
     lweRepoUrl: getLweRepoUrl(),
     lweRepoBranch: getLweRepoBranch(),
+    lweCmakeArgs: getLweCmakeArgs(),
     defaultLweRepoUrl: DEFAULT_LWE_REPO,
     backupPath: getConfiguredBackupPath(),
     isBackupConfigured: isBackupPathConfigured(),
@@ -101,6 +104,11 @@ export function registerConfigHandlers(): void {
     return { ok: true }
   })
 
+  ipcMain.handle(IpcChannels.CONFIG_SET_LWE_CMAKE_ARGS, (_e, args: string | null) => {
+    setLweCmakeArgs(args)
+    return { ok: true }
+  })
+
   ipcMain.handle(IpcChannels.CONFIG_SET_WORKSHOP_PATH, (_e, newPath: string) => {
     setConfiguredWorkshopPath(newPath)
     restartWatcher()

+ 11 - 0
src/main/services/config.service.ts

@@ -9,6 +9,7 @@ interface AppConfig {
   defaultFps: number | null
   lweRepoUrl: string | null
   lweRepoBranch: string | null
+  lweCmakeArgs: string | null
   backupPath: string | null
   autoUnsubscribeAfterBackup: boolean
   trayEnabled: boolean
@@ -25,6 +26,7 @@ const store = new Store<AppConfig>({
     defaultFps: null,
     lweRepoUrl: null,
     lweRepoBranch: null,
+    lweCmakeArgs: null,
     backupPath: null,
     autoUnsubscribeAfterBackup: false,
     trayEnabled: false,
@@ -127,6 +129,15 @@ export function setLweRepo(url: string | null, branch: string | null): void {
   store.set('lweRepoBranch', branch?.trim() || null)
 }
 
+/** Extra cmake arguments (e.g. "-DENABLE_KDE_EXPERIMENTAL_FEATURES=ON"), appended to the build. */
+export function getLweCmakeArgs(): string | null {
+  return store.get('lweCmakeArgs')
+}
+
+export function setLweCmakeArgs(args: string | null): void {
+  store.set('lweCmakeArgs', args?.trim() || null)
+}
+
 /** Path where we store our copy of config.json */
 export function getWeConfigPath(): string {
   return path.join(app.getPath('userData'), 'we-config.json')

+ 31 - 2
src/main/services/lwe.service.ts

@@ -15,7 +15,7 @@ import {
   getXdgRuntimeDir
 } from '../utils/platform'
 import { getWorkshopPath, getLweManifestPath } from '../utils/paths'
-import { getLweRepoUrl, getLweRepoBranch } from './config.service'
+import { getLweRepoUrl, getLweRepoBranch, getLweCmakeArgs } from './config.service'
 import { DEFAULT_LWE_REPO } from '@shared/constants'
 
 const execFileAsync = promisify(execFile)
@@ -70,6 +70,34 @@ function writeLweManifest(manifest: LweInstallManifest): void {
   } catch { /* non-fatal */ }
 }
 
+function parseExtraCmakeArgs(raw: string | null): string[] {
+  if (!raw) return []
+  const args: string[] = []
+  let current = ''
+  let quote: string | null = null
+  let inToken = false
+  for (const ch of raw) {
+    if (quote) {
+      if (ch === quote) quote = null
+      else current += ch
+      continue
+    }
+    if (ch === '"' || ch === "'") {
+      quote = ch
+      inToken = true
+      continue
+    }
+    if (/\s/.test(ch)) {
+      if (inToken) { args.push(current); current = ''; inToken = false }
+      continue
+    }
+    current += ch
+    inToken = true
+  }
+  if (inToken) args.push(current)
+  return args
+}
+
 function findLweBinary(): string | undefined {
   for (const p of LWE_SEARCH_PATHS) {
     try {
@@ -278,7 +306,8 @@ export async function installLwe(win: BrowserWindow): Promise<void> {
       '-DCMAKE_BUILD_TYPE=Release',
       '-DCMAKE_INSTALL_PREFIX=/usr/local',
       '-DCMAKE_C_FLAGS=-Wno-error',
-      '-DCMAKE_CXX_FLAGS=-Wno-error'
+      '-DCMAKE_CXX_FLAGS=-Wno-error',
+      ...parseExtraCmakeArgs(getLweCmakeArgs())
     ], {
       cwd: cmakeBuild,
       timeout: 600_000,

+ 3 - 0
src/preload/index.ts

@@ -81,6 +81,7 @@ const api = {
       defaultFps: number | null
       lweRepoUrl: string | null
       lweRepoBranch: string | null
+      lweCmakeArgs: string | null
       defaultLweRepoUrl: string
       backupPath: string | null
       isBackupConfigured: boolean
@@ -98,6 +99,8 @@ const api = {
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_DEFAULT_FPS, fps),
     setLweRepo: (url: string | null, branch: string | null): Promise<{ ok: boolean }> =>
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_LWE_REPO, url, branch),
+    setLweCmakeArgs: (args: string | null): Promise<{ ok: boolean }> =>
+      ipcRenderer.invoke(IpcChannels.CONFIG_SET_LWE_CMAKE_ARGS, args),
     setBackupPath: (p: string): Promise<{ ok: boolean }> =>
       ipcRenderer.invoke(IpcChannels.CONFIG_SET_BACKUP_PATH, p),
     setAutoUnsubscribeAfterBackup: (enabled: boolean): Promise<{ ok: boolean }> =>

+ 16 - 1
src/renderer/src/components/settings/SettingsView.tsx

@@ -22,6 +22,7 @@ export default function SettingsView() {
   const [lweStatus, setLweStatus] = useState<LweStatus | null>(null)
   const [lweRepoUrl, setLweRepoUrl] = useState('')
   const [lweRepoBranch, setLweRepoBranch] = useState('')
+  const [lweCmakeArgs, setLweCmakeArgs] = useState('')
   const [defaultLweRepo, setDefaultLweRepo] = useState('')
   const [repoSaved, setRepoSaved] = useState(false)
   const [lweInstalling, setLweInstalling] = useState(false)
@@ -56,6 +57,7 @@ export default function SettingsView() {
       setDefaultFps(cfg.defaultFps != null ? String(cfg.defaultFps) : '')
       setLweRepoUrl(cfg.lweRepoUrl ?? '')
       setLweRepoBranch(cfg.lweRepoBranch ?? '')
+      setLweCmakeArgs(cfg.lweCmakeArgs ?? '')
       setDefaultLweRepo(cfg.defaultLweRepoUrl)
       setBackupPath(cfg.backupPath ?? '')
       setAutoUnsubscribeAfterBackup(cfg.autoUnsubscribeAfterBackup)
@@ -130,6 +132,7 @@ export default function SettingsView() {
 
   async function handleSaveRepo() {
     await window.electronAPI.config.setLweRepo(lweRepoUrl.trim() || null, lweRepoBranch.trim() || null)
+    await window.electronAPI.config.setLweCmakeArgs(lweCmakeArgs.trim() || null)
     setRepoSaved(true)
     setTimeout(() => setRepoSaved(false), 2000)
   }
@@ -138,8 +141,9 @@ export default function SettingsView() {
     setLweInstalling(true)
     setLweProgress({ stage: 'cloning', message: 'Starting installation...', percentage: 0 })
     try {
-      // Persist the repo fields first so the build uses what's on screen
+      // Persist the repo/cmake-args fields first so the build uses what's on screen
       await window.electronAPI.config.setLweRepo(lweRepoUrl.trim() || null, lweRepoBranch.trim() || null)
+      await window.electronAPI.config.setLweCmakeArgs(lweCmakeArgs.trim() || null)
       await window.electronAPI.lwe.install()
     } catch (err) {
       setLweProgress({
@@ -481,6 +485,17 @@ export default function SettingsView() {
                 {repoSaved ? 'Saved!' : 'Save'}
               </button>
             </div>
+            <label className="block text-xs text-gray-400">Extra cmake arguments</label>
+            <p className="text-xs text-gray-600">
+              Passed to cmake when configuring the build, e.g. -DENABLE_KDE_EXPERIMENTAL_FEATURES=ON
+            </p>
+            <input
+              type="text"
+              value={lweCmakeArgs}
+              onChange={(e) => { setLweCmakeArgs(e.target.value); setRepoSaved(false) }}
+              placeholder="-DENABLE_KDE_EXPERIMENTAL_FEATURES=ON"
+              className="w-full rounded-lg bg-white/5 px-3 py-2 text-sm text-gray-200 outline-none focus:ring-1 focus:ring-indigo-500 font-mono"
+            />
           </div>
 
           {lweStatus === null ? (

+ 1 - 0
src/shared/ipc-channels.ts

@@ -49,6 +49,7 @@ export const IpcChannels = {
   CONFIG_SET_WORKSHOP_PATH: 'config:set-workshop-path',
   CONFIG_SET_DEFAULT_FPS: 'config:set-default-fps',
   CONFIG_SET_LWE_REPO: 'config:set-lwe-repo',
+  CONFIG_SET_LWE_CMAKE_ARGS: 'config:set-lwe-cmake-args',
   CONFIG_SET_BACKUP_PATH: 'config:set-backup-path',
   CONFIG_SET_AUTO_UNSUBSCRIBE: 'config:set-auto-unsubscribe',
   CONFIG_PICK_FOLDER: 'config:pick-folder',