mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
feat: add support for extensions
This commit is contained in:
parent
14f477a633
commit
b018571a86
@ -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 += `</div>`;
|
||||
h += `</div>`;
|
||||
|
||||
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);
|
||||
}
|
||||
})
|
||||
|
@ -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;
|
||||
};
|
||||
};
|
@ -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');
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user