Skip to content

Commit b018571

Browse files
committed
feat: add support for extensions
1 parent 14f477a commit b018571

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

src/gui/src/UI/Settings/UIWindowSettings.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import Placeholder from '../../util/Placeholder.js';
21-
import UIElement from '../UIElement.js';
2221
import UIWindow from '../UIWindow.js'
2322

2423
def(Symbol('TSettingsTab'), 'ui.traits.TSettingsTab');
@@ -70,8 +69,6 @@ async function UIWindowSettings(options){
7069
h += `</div>`;
7170
h += `</div>`;
7271

73-
h += ``;
74-
7572
const el_window = await UIWindow({
7673
title: 'Settings',
7774
app: 'settings',
@@ -95,6 +92,8 @@ async function UIWindowSettings(options){
9592
show_in_taskbar: false,
9693
draggable_body: false,
9794
onAppend: function(this_window){
95+
// send event settings-window-opened
96+
window.dispatchEvent(new CustomEvent('settings-window-opened', { detail: { window: this_window } }));
9897
},
9998
window_class: 'window-settings',
10099
body_css: {
@@ -130,7 +129,7 @@ async function UIWindowSettings(options){
130129

131130
// Run on_show handlers
132131
const tab = tabs.find((tab) => tab.id === settings);
133-
if (tab.on_show) {
132+
if (tab?.on_show) {
134133
tab.on_show($content);
135134
}
136135
})

src/gui/webpack/BaseConfig.cjs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,32 @@
11
const path = require('path');
2+
const fs = require('fs');
23
const EmitPlugin = require('./EmitPlugin.cjs');
4+
35
module.exports = async (options = {}) => {
6+
// Directory containing extension files
7+
const extensionsDir = path.join(__dirname, '../src/extensions');
8+
9+
// Read and process extension entries from the extensions directory
10+
const entries = fs.readdirSync(extensionsDir, { withFileTypes: true })
11+
.map(entry => {
12+
// Case 1: Direct JavaScript files in extensions directory
13+
if (entry.isFile() && entry.name.endsWith('.js')) {
14+
return `./src/extensions/${entry.name}`;
15+
}
16+
// Case 2: Extension directories with index.js files
17+
if (entry.isDirectory()) {
18+
const indexPath = path.join(extensionsDir, entry.name, 'index.js');
19+
// Check if directory contains an index.js file
20+
if (fs.existsSync(indexPath)) {
21+
return `./src/extensions/${entry.name}/index.js`;
22+
}
23+
}
24+
// Skip entries that don't match either case
25+
return null;
26+
})
27+
// Remove null entries from the array
28+
.filter(entry => entry !== null);
29+
430
const config = {};
531
config.entry = [
632
'./src/init_sync.js',
@@ -12,6 +38,7 @@ module.exports = async (options = {}) => {
1238
'./src/i18n/i18n.js',
1339
'./src/keyboard.js',
1440
'./src/index.js',
41+
...entries,
1542
];
1643
config.output = {
1744
path: path.resolve(__dirname, '../dist'),
@@ -24,4 +51,4 @@ module.exports = async (options = {}) => {
2451
}),
2552
];
2653
return config;
27-
};
54+
};

src/gui/webpack/EmitPlugin.cjs

-17
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,4 @@ module.exports = async ({ dir, options }) => {
6060
banner: prefix_text,
6161
raw: true,
6262
});
63-
64-
// -----------------------------------------------
65-
// Webpack understands this code better than I do
66-
// -----------------------------------------------
67-
// Object.keys(compilation.assets).forEach((assetName) => {
68-
// if (assetName.endsWith('.js')) {
69-
// const asset = compilation.assets[assetName];
70-
// const originalSource = asset.source();
71-
// const newSource = `${prefix_text}\n${originalSource}`;
72-
// compilation.assets[assetName] = {
73-
// source: () => newSource,
74-
// size: () => newSource.length,
75-
// };
76-
// }
77-
// });
78-
79-
console.log('END');
8063
};

0 commit comments

Comments
 (0)