From 319217c3a58555d086b7a8f8400303ade02039e5 Mon Sep 17 00:00:00 2001 From: Guilherme I F L Weizenmann Date: Mon, 14 Nov 2022 08:59:43 -0300 Subject: [PATCH] Make config relative to installation (portable) --- applications/electron/package.json | 4 ++-- ...electron-main.js => eos-thesis-electron-main.js} | 13 +++++++++++-- .../src/node/eos-thesis-variables-server.ts | 6 ++++-- 3 files changed, 17 insertions(+), 6 deletions(-) rename applications/electron/scripts/{theia-electron-main.js => eos-thesis-electron-main.js} (55%) diff --git a/applications/electron/package.json b/applications/electron/package.json index 5e007b2..40b57f9 100644 --- a/applications/electron/package.json +++ b/applications/electron/package.json @@ -4,7 +4,7 @@ "description": "Eclipse Theia blueprint product", "productName": "Theia Blueprint", "version": "1.31.1", - "main": "scripts/theia-electron-main.js", + "main": "scripts/eos-thesis-electron-main.js", "license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", "author": "Eclipse Theia ", "homepage": "https://github.com/giflw/eos-thesis-ide#readme", @@ -120,7 +120,7 @@ "build": "theia rebuild:electron && yarn bundle", "bundle": "theia build", "watch": "concurrently -n compile,bundle \"theiaext watch --preserveWatchOutput\" \"theia build --watch --mode development\"", - "start": "electron scripts/theia-electron-main.js", + "start": "electron scripts/eos-thesis-electron-main.js", "start:debug": "yarn start --log-level=debug", "package": "yarn clean:dist && electron-builder -c.mac.identity=null --publish never", "deploy": "yarn clean:dist && electron-builder -c.mac.identity=null --publish always", diff --git a/applications/electron/scripts/theia-electron-main.js b/applications/electron/scripts/eos-thesis-electron-main.js similarity index 55% rename from applications/electron/scripts/theia-electron-main.js rename to applications/electron/scripts/eos-thesis-electron-main.js index a9da33c..6bfab03 100644 --- a/applications/electron/scripts/theia-electron-main.js +++ b/applications/electron/scripts/eos-thesis-electron-main.js @@ -1,5 +1,14 @@ const path = require('path') -const os = require('os') +const fs = require('fs') +const { app } = require('electron'); + +const userDataPath = path.resolve(app.getAppPath(), '../../', 'data/frontend'); +const pluginsPath = path.resolve(app.getAppPath(), '../../', 'data/plugins'); + +[userDataPath, pluginsPath].forEach(p => fs.existsSync(p) ? fs.mkdirSync(p, {recursive : true}) : null) + +app.setPath('userData', userDataPath); + // Update to override the supported VS Code API version. // process.env.VSCODE_API_VERSION = '1.50.0' @@ -9,7 +18,7 @@ process.env.THEIA_DEFAULT_PLUGINS = `local-dir:${path.resolve(__dirname, '..', ' // Lookup inside the user's home folder for more plugins, and accept user-defined paths. process.env.THEIA_PLUGINS = [ - process.env.THEIA_PLUGINS, `local-dir:${path.resolve(os.homedir(), '.theia', 'plugins')}`, + process.env.THEIA_PLUGINS, `local-dir:${pluginsPath}`, ].filter(Boolean).join(',') // Handover to the auto-generated electron application handler. diff --git a/eos-thesis-extensions/eos-thesis-product/src/node/eos-thesis-variables-server.ts b/eos-thesis-extensions/eos-thesis-product/src/node/eos-thesis-variables-server.ts index 3235a84..98ba9ad 100644 --- a/eos-thesis-extensions/eos-thesis-product/src/node/eos-thesis-variables-server.ts +++ b/eos-thesis-extensions/eos-thesis-product/src/node/eos-thesis-variables-server.ts @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import * as os from 'os'; +//import * as os from 'os'; import * as path from 'path'; import { injectable } from '@theia/core/shared/inversify'; import { FileUri } from '@theia/core/lib/node/file-uri'; @@ -23,7 +23,9 @@ import { EnvVariablesServerImpl } from '@theia/core/lib/node/env-variables'; @injectable() export class EosThesisEnvVariableServer extends EnvVariablesServerImpl { - protected readonly _configDirUri: string = FileUri.create(path.join(os.homedir(), '.eos-thesis')).toString(true); + //protected readonly _configDirUri: string = FileUri.create(path.join(os.homedir(), '.eos-thesis')).toString(true); + protected readonly _configDirUri: string = FileUri.create(path.resolve(process.execPath, '../data/backend')).toString(true); + async getConfigDirUri(): Promise { return this._configDirUri;