import { Alert } from './gui/Alert' import { CreateKeyboardListeners } from './input/keyboard' import { Wush } from './shell/Wush' import { Terminal } from './terminal/Terminal' import { EventBroadcaster } from './utils/EventBroadcaster' export const WEBSHELL_VERSION = "0.1.0" // initialize object store for webfs let WebfsDatabase: IDBDatabase | null = null const request = indexedDB.open("webshell") request.onupgradeneeded = event => { console.log("creating database") WebfsDatabase = (event.target as any).result as IDBDatabase WebfsDatabase.createObjectStore("webfs") } request.onerror = _ => { new Alert( "webfs error", "Failed to initialize the webfs database using IndexedDB. Make sure webshell does not have any IndexedDB related permissions disabled and try again.", 'critical', ).Show() } request.onsuccess = event => { WebfsDatabase = (event.target as any).result as IDBDatabase console.log("database initialized") // initialize the app after the database init() } export const GetWebfsDatabase = (): IDBDatabase | null => WebfsDatabase // terminal management let CurrentTerminal: Terminal export const SetCurrentTerminal = (terminal: Terminal) => CurrentTerminal = terminal export const GetCurrentTerminal = (): Terminal => CurrentTerminal // Initializes the app const init = async () => { const localBroadcaster = new EventBroadcaster() // creates keyboard listeners for the local event broadcaster CreateKeyboardListeners( (key: string, isCharacter: boolean) => localBroadcaster.emit('keydown', key, isCharacter), (key: string, isCharacter: boolean) => localBroadcaster.emit('keyup', key, isCharacter), ) const terminal = new Terminal() await terminal.LoadShell(new Wush(localBroadcaster, terminal)) }