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
19 changes: 19 additions & 0 deletions src/main/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as lsp from './lsp/index'
import { app, ipcMain } from 'electron'
import { Settings } from '../types/settings.type'
import os from 'os'
import { isWindows } from './system/platform.ts'

const homeDir = os.homedir()

Expand Down Expand Up @@ -36,11 +37,29 @@ const defaultSettings: Settings = {

export const init = async () => {
ipcMain.on('settings.store', async (_event: any, data: Settings) => {
data.php = handlePhpExecutable(_event, data.php)
setSettings(data)
await lsp.init()
})
}

const handlePhpExecutable = (_event: any, phpPath: string) => {
try {
if (fs.existsSync(phpPath) && fs.lstatSync(phpPath).isDirectory()) {
const phpExecutable = isWindows() ? 'php.exe' : 'php'
let potentialPath = path.join(phpPath, phpExecutable)

if (fs.existsSync(potentialPath)) {
phpPath = potentialPath
_event.sender.send('settings.php-located', potentialPath)
}
}
} catch (err) {
// Ignore errors as path may no longer exist or has been changed etc..
}
return phpPath
}

export const setSettings = async (data: Settings) => {
fs.writeFileSync(settingsPath, JSON.stringify(data))
}
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/views/settings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
import { useSettingsStore } from '../../stores/settings'
import SelectInput from '../../components/SelectInput.vue'
import TextInput from '../../components/TextInput.vue'
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import UpdateApp from '../../components/UpdateApp.vue'

const saved = ref(false)
const settingsStore = useSettingsStore()

onMounted(() => {
window.ipcRenderer.on('settings.php-located', updatePhpSetting)
})

const updatePhpSetting = (newPhpSetting: string) => {
settingsStore.settings.php = newPhpSetting
}

const saveSettings = () => {
saved.value = true
settingsStore.update()
Expand Down