Skip to content

Commit

Permalink
fix: store LemMinX in appData path
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Mar 3, 2024
1 parent 1246008 commit 2d2d3eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src-electron/lsp.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
import { dialog } from 'electron'
import { app, dialog } from 'electron'
import { spawn } from 'node:child_process'
import { deferred } from 'fast-defer'
import initOptions from './lsp/init-options.js'
import { createWriteStream } from 'node:fs'
import fs from 'node:fs/promises'
import path from 'node:path'
import { pipeline } from 'node:stream/promises'
import got from 'got'
import { setTimeout } from 'node:timers/promises'

const platform = {
darwin: {
exec: 'lemminx-darwin',
execPath: path.join(app.getPath('appData'), app.name, 'lemminx-darwin'),
env: {}
},
linux: {
exec: 'lemminx-linux',
execPath: path.join(app.getPath('appData'), app.name, 'lemminx-linux'),
env: {}
},
win32: {
exec: 'lemminx-win32.exe',
execPath: path.join(app.getPath('appData'), app.name, 'lemminx-win32.exe'),
env: {
windowsHide: true
}
Expand All @@ -44,7 +48,7 @@ export default {

let isInstalled = false
try {
await fs.access(platformOpts.exec, fs.constants.X_OK)
await fs.access(platformOpts.execPath, fs.constants.X_OK)
isInstalled = true
} catch (err) {
console.warn('LSP server executable missing. Will download...')
Expand Down Expand Up @@ -81,17 +85,17 @@ export default {
}
await pipeline(
got.stream(`https://github.com/ietf-tools/lemminx/releases/latest/download/${downloadFile}`),
createWriteStream(platformOpts.exec)
createWriteStream(platformOpts.execPath)
)
if (process.platform !== 'win32') {
await fs.chmod(platformOpts.exec, '+x')
await fs.chmod(platformOpts.execPath, '+x')
}
await fs.access(platformOpts.exec, fs.constants.X_OK)
await fs.access(platformOpts.execPath, fs.constants.X_OK)
} catch (err) {
console.warn(err)
mainWindow.webContents.send('setProgressDialog', { isShown: false })
try {
await fs.unlink(platformOpts.exec)
await fs.unlink(platformOpts.execPath)
} catch (err) {}
throw new Error(`${err.message}: ${err.options?.url?.href}`)
}
Expand All @@ -109,7 +113,7 @@ export default {
const platformOpts = platform[process.platform]

// Spawn LSP process
this.lsp = spawn(platformOpts.exec)
this.lsp = spawn(platformOpts.execPath)

// -> Handle stdio
this.lsp.stdout.on('data', (data) => {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export const useDocsStore = defineStore('docs', {
},
persist: {
paths: [
'opened',
'active'
// 'opened',
// 'active'
]
}
})

0 comments on commit 2d2d3eb

Please sign in to comment.