From b018571a86f4114eab9b5edde4ecd87e343d22a7 Mon Sep 17 00:00:00 2001 From: jelveh Date: Tue, 29 Oct 2024 18:37:32 -0700 Subject: [PATCH] feat: add support for extensions --- src/gui/src/UI/Settings/UIWindowSettings.js | 7 +++-- src/gui/webpack/BaseConfig.cjs | 29 ++++++++++++++++++++- src/gui/webpack/EmitPlugin.cjs | 17 ------------ 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/gui/src/UI/Settings/UIWindowSettings.js b/src/gui/src/UI/Settings/UIWindowSettings.js index 9af6b036..7c5a50c6 100644 --- a/src/gui/src/UI/Settings/UIWindowSettings.js +++ b/src/gui/src/UI/Settings/UIWindowSettings.js @@ -18,7 +18,6 @@ */ import Placeholder from '../../util/Placeholder.js'; -import UIElement from '../UIElement.js'; import UIWindow from '../UIWindow.js' def(Symbol('TSettingsTab'), 'ui.traits.TSettingsTab'); @@ -70,8 +69,6 @@ async function UIWindowSettings(options){ h += ``; h += ``; - h += ``; - const el_window = await UIWindow({ title: 'Settings', app: 'settings', @@ -95,6 +92,8 @@ async function UIWindowSettings(options){ show_in_taskbar: false, draggable_body: false, onAppend: function(this_window){ + // send event settings-window-opened + window.dispatchEvent(new CustomEvent('settings-window-opened', { detail: { window: this_window } })); }, window_class: 'window-settings', body_css: { @@ -130,7 +129,7 @@ async function UIWindowSettings(options){ // Run on_show handlers const tab = tabs.find((tab) => tab.id === settings); - if (tab.on_show) { + if (tab?.on_show) { tab.on_show($content); } }) diff --git a/src/gui/webpack/BaseConfig.cjs b/src/gui/webpack/BaseConfig.cjs index 7c736b35..640c8654 100644 --- a/src/gui/webpack/BaseConfig.cjs +++ b/src/gui/webpack/BaseConfig.cjs @@ -1,6 +1,32 @@ const path = require('path'); +const fs = require('fs'); const EmitPlugin = require('./EmitPlugin.cjs'); + module.exports = async (options = {}) => { + // Directory containing extension files + const extensionsDir = path.join(__dirname, '../src/extensions'); + + // Read and process extension entries from the extensions directory + const entries = fs.readdirSync(extensionsDir, { withFileTypes: true }) + .map(entry => { + // Case 1: Direct JavaScript files in extensions directory + if (entry.isFile() && entry.name.endsWith('.js')) { + return `./src/extensions/${entry.name}`; + } + // Case 2: Extension directories with index.js files + if (entry.isDirectory()) { + const indexPath = path.join(extensionsDir, entry.name, 'index.js'); + // Check if directory contains an index.js file + if (fs.existsSync(indexPath)) { + return `./src/extensions/${entry.name}/index.js`; + } + } + // Skip entries that don't match either case + return null; + }) + // Remove null entries from the array + .filter(entry => entry !== null); + const config = {}; config.entry = [ './src/init_sync.js', @@ -12,6 +38,7 @@ module.exports = async (options = {}) => { './src/i18n/i18n.js', './src/keyboard.js', './src/index.js', + ...entries, ]; config.output = { path: path.resolve(__dirname, '../dist'), @@ -24,4 +51,4 @@ module.exports = async (options = {}) => { }), ]; return config; -}; +}; \ No newline at end of file diff --git a/src/gui/webpack/EmitPlugin.cjs b/src/gui/webpack/EmitPlugin.cjs index 9e4fd6de..e511da54 100644 --- a/src/gui/webpack/EmitPlugin.cjs +++ b/src/gui/webpack/EmitPlugin.cjs @@ -60,21 +60,4 @@ module.exports = async ({ dir, options }) => { banner: prefix_text, raw: true, }); - - // ----------------------------------------------- - // Webpack understands this code better than I do - // ----------------------------------------------- - // Object.keys(compilation.assets).forEach((assetName) => { - // if (assetName.endsWith('.js')) { - // const asset = compilation.assets[assetName]; - // const originalSource = asset.source(); - // const newSource = `${prefix_text}\n${originalSource}`; - // compilation.assets[assetName] = { - // source: () => newSource, - // size: () => newSource.length, - // }; - // } - // }); - - console.log('END'); };