diff --git a/.vscode/launch.json b/.vscode/launch.json index d9ef816..681cf34 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,5 +23,11 @@ "port": 9222, "webRoot": "${workspaceRoot}/ui" } + ], + "compounds": [ + { + "name": "Debug Main and Renderer", + "configurations": ["Debug Main Process", "Attach to Render Process"] + } ] } \ No newline at end of file diff --git a/main.js b/main.js index e8263e3..176617a 100644 --- a/main.js +++ b/main.js @@ -14,6 +14,8 @@ const LOGGING_DIR = app.isPackaged ? path.join("logs") const LOGGING_FILE_PATH = path.join(LOGGING_DIR, LOGGING_FILE_NAME) +const PLUGIN_PATH = app.isPackaged ? path.join(app.getPath("userData"), "plugins") : path.join(__dirname, "ui", "src", "plugins") + if (!fs.existsSync(LOGGING_DIR)) fs.mkdirSync(LOGGING_DIR) const loggingStream = fs.createWriteStream(LOGGING_FILE_PATH) @@ -31,28 +33,18 @@ function createWindow () { webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true, - sandbox: false + sandbox: false, + nodeIntegration: true }, logo: path.join(__dirname, 'assets', 'logo.png') }) win.loadFile(path.join(__dirname, 'ui', 'index.html')) - - // if (!app.isPackaged) { - // win.webContents.openDevTools() - // } } let tmpDir app.whenReady().then(() => { - // if (!app.isPackaged) { - // const { default: installExtension, REACT_DEVELOPER_TOOLS } = require("electron-devtools-installer") - // installExtension(REACT_DEVELOPER_TOOLS) - // .then((ex_name) => console.log(`Added "${ex_name}" Extension`)) - // .catch((err) => console.log("An error occured when attempting to install extensions:", err)) - // } - createWindow() ipcMain.handle("settings:get", (event) => { @@ -73,42 +65,23 @@ app.whenReady().then(() => { loggingStream.write(`[${level.toUpperCase()}] ${message}` + "\n") }) - // When working with local scripts, use these functions - // ipcMain.handle("file:createTempScriptDir", (event, name, cb) => { - // try { - // tmpDir = fs.mkdtemp(path.join(tmpdir(), "proton", name)) - // cb(tmpDir) - // } catch (e) { - // console.error(e) - // } finally { - // try { - // if (tmpDir) { - // fs.rm(tmpDir, { recursive: true }) - // } - // } catch (e) { - // console.error(e) - // } - // } - // }) - - // ipcMain.handle("script:watchForChanges", (event, scriptDir, cb) => { - // fs.watch(scriptDir, (event, filename) => { - // console.log(`Change found in ${filename}`, e) - // if (filename) { - // cb(event, filename) - // } else { - // console.warn("No file found") - // } - // }) - // }) - - ipcMain.handle("getPlugins", (event, pluginDir) => { - return fs.readdirSync(pluginDir) + ipcMain.handle("getDev", (event) => { + return app.isPackaged + }) + + ipcMain.handle("getUserDir", (event) => { + return app.getPath("userData") + }) + + ipcMain.handle("getPlugins", (event) => { + let result = fs.readdirSync(PLUGIN_PATH) + console.log(result) + return result }) - ipcMain.handle("getPlugin", (event, pluginDir, pluginName) => { - const plugin = require(path.join(pluginDir, pluginName)) - const pluginConfig = require(path.join(pluginDir, pluginName, "proton.config.js")) + ipcMain.handle("getPlugin", (event, pluginName) => { + const plugin = require(path.join(PLUGIN_PATH, pluginName)) + const pluginConfig = require(path.join(PLUGIN_PATH, pluginName, "proton.config.js")) return JSON.stringify({plugin: plugin, pluginConfig: pluginConfig}) }) diff --git a/preload.js b/preload.js index 407f5c9..4a88f7e 100644 --- a/preload.js +++ b/preload.js @@ -2,12 +2,19 @@ const { default: ProtonPlugin } = require("@techstudent10/plugin") const { contextBridge, ipcRenderer } = require("electron") const path = require("path") +let PLUGIN_PATH; + +ipcRenderer.invoke("getDev").then(isDev => { + ipcRenderer.invoke("getUserDir").then(userDir => { + PLUGIN_PATH = isDev ? path.join(userDir, "plugins") : path.join(__dirname, "ui", "src", "plugins") + }) +}) contextBridge.exposeInMainWorld("electronAPI", { getSettings: () => ipcRenderer.invoke("settings:get"), - getPlugins: (pluginPath) => ipcRenderer.invoke("getPlugins", pluginPath), - getPlugin: (pluginPath, pluginName) => { - const plugin = require(path.join(pluginPath, pluginName)) + getPlugins: () => ipcRenderer.invoke("getPlugins"), + getPlugin: (pluginName) => { + const plugin = require(path.join(PLUGIN_PATH, pluginName)) // console.log(plugin) const newPlugin = new ProtonPlugin(undefined) @@ -19,7 +26,7 @@ contextBridge.exposeInMainWorld("electronAPI", { newPlugin[name] = pluginObj[name] }) - const pluginConfig = require(path.join(pluginPath, pluginName, "proton.config.js")) + const pluginConfig = require(path.join(PLUGIN_PATH, pluginName, "proton.config.js")) return {plugin: newPlugin, pluginConfig: pluginConfig} }, logInfo: (message) => ipcRenderer.send("log", "info", message), diff --git a/renderer.d.ts b/renderer.d.ts index 36b0042..3e166ec 100644 --- a/renderer.d.ts +++ b/renderer.d.ts @@ -1,7 +1,7 @@ export interface IElectronAPI { getSettings: () => {}, - getPlugins: (pluginPath: string) => Promise, - getPlugin: (pluginPath: string, pluginName: string) => any, + getPlugins: () => Promise, + getPlugin: (pluginName: string) => any, logInfo: (message: string) => void, logWarn: (message: string) => void, logErr: (message: string) => void, diff --git a/ui/src/libs/plugin/index.ts b/ui/src/libs/plugin/index.ts index 8897384..587d4df 100644 --- a/ui/src/libs/plugin/index.ts +++ b/ui/src/libs/plugin/index.ts @@ -20,7 +20,7 @@ class PluginManager { this.PLUGIN_PATH = options.path } - window.electronAPI.getPlugins(this.PLUGIN_PATH).then((data: Array) => { + window.electronAPI.getPlugins().then((data: Array) => { this.load(data) }) } @@ -30,7 +30,7 @@ class PluginManager { pluginFiles.map(filename => { // console.log("a", filename) try { - const pluginObj = window.electronAPI.getPlugin(this.PLUGIN_PATH, filename) + const pluginObj = window.electronAPI.getPlugin(filename) const plugin = pluginObj.plugin const pluginConfig = pluginObj.pluginConfig // console.log(plugin, "\n", pluginConfig) diff --git a/ui/src/screens/editor/TextEditor.tsx b/ui/src/screens/editor/TextEditor.tsx index 09d0151..cd72454 100644 --- a/ui/src/screens/editor/TextEditor.tsx +++ b/ui/src/screens/editor/TextEditor.tsx @@ -7,7 +7,6 @@ import * as monaco from "monaco-editor" loader.config({ monaco }) import Tabs, { Tab } from './Tabs'; -import 'react-responsive-tabs/styles.css'; import TextEditorFileList from "./TextEditorFileList"; diff --git a/ui/src/screens/editor/react-responsive-tabs.d.ts b/ui/src/screens/editor/react-responsive-tabs.d.ts deleted file mode 100644 index 6101c8a..0000000 --- a/ui/src/screens/editor/react-responsive-tabs.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'react-responsive-tabs';