diff --git a/src/structures/ProcessLib.ts b/src/structures/ProcessLib.ts index 71155e9d..3fa9bf99 100644 --- a/src/structures/ProcessLib.ts +++ b/src/structures/ProcessLib.ts @@ -1,6 +1,6 @@ import semver from 'semver' import Kernel from '../kernel' -import { Process, Executable, LibraryData, Package, Library, Permission } from '../types' +import { Process, Executable, Package, Library, Permission, LoadedLibrary, LibraryPath } from '../types' import FlowWindow from './FlowWindow' import LibraryLib from './LibraryLib' import ProcLib from './ProcLib' @@ -57,7 +57,7 @@ export default class ProcessLib { }) } - async loadLibrary (url: string): Promise { + async loadLibrary (url: T): Promise> { let executable: Executable try { const comps = import.meta.glob('../system/**/*.ts') diff --git a/src/system/BootLoader.ts b/src/system/BootLoader.ts index d98306a4..f9fad95d 100644 --- a/src/system/BootLoader.ts +++ b/src/system/BootLoader.ts @@ -83,7 +83,7 @@ const BootLoader: Process = { const files = await fs.readdir('/home/Applications/') files .filter((x: string) => x.endsWith('.app') && ((input.elm as HTMLInputElement) !== null ? x.toLowerCase().includes((input.elm as HTMLInputElement).value.toLowerCase()) : true)) - .forEach(async (file: string) => { + .forEach((file: string) => { fs.readFile(`/home/Applications/${file}`).then(async (data: Uint8Array) => { const path = Buffer.from(data).toString() const executable = await process.kernel.getExecutable(path) as Process @@ -97,7 +97,7 @@ const BootLoader: Process = { alt: `${executable.config.name} icon` }).appendTo(appElement) new HTML('div').text(executable.config.name).appendTo(appElement) - }) + }).catch((e: any) => console.error(e)) }) } @@ -129,11 +129,11 @@ const BootLoader: Process = { setInterval((): any => { getTime().then((time) => { - statusBar.element.qs('div[data-toolbar-id="calendar"]').text(time) + statusBar.element.qs('div[data-toolbar-id="calendar"]')?.text(time) }).catch(e => console.error) }, 1000) - statusBar.element.qs('div[data-toolbar-id="start"]').on('click', () => { + statusBar.element.qs('div[data-toolbar-id="start"]')?.on('click', () => { launcher.toggle() }) @@ -180,11 +180,11 @@ const BootLoader: Process = { e.detail.win.focus() e.detail.win.toggleMin() }) - ).appendTo(statusBar.element.qs('div[data-toolbar-id="apps"]')) + ).appendTo(statusBar.element.qs('div[data-toolbar-id="apps"]')?.elm as HTMLElement) }) document.addEventListener('app_closed', (e: AppClosedEvent): void => { - statusBar.element.qs('div[data-toolbar-id="apps"]').qs(`img[data-id="${e.detail.token}"]`).elm.parentElement.remove() + statusBar.element.qs('div[data-toolbar-id="apps"]')?.qs(`img[data-id="${e.detail.token}"]`)?.elm.parentElement?.remove() }) document.body.style.flexDirection = 'column-reverse' diff --git a/src/system/UserAccessControl.ts b/src/system/UserAccessControl.ts index 593ccca0..3b918e62 100644 --- a/src/system/UserAccessControl.ts +++ b/src/system/UserAccessControl.ts @@ -16,7 +16,7 @@ const UserAccessControl: Process = { const target = process.data.executable return await new Promise((resolve) => { process.loadLibrary('lib/WindowManager').then(async wm => { - let message + let message = 'Unknown action' switch (process.data.type) { case 'launch': { message = `${initiator.config.name as string} wants to launch ${target.config.name as string}` @@ -42,7 +42,7 @@ const UserAccessControl: Process = { } else { resolve(false) } - }) + }).catch((e) => console.error(e)) }).catch((e) => console.error(e)) }) } diff --git a/src/system/apps/Browser.ts b/src/system/apps/Browser.ts index 973d3790..3b6fbb24 100644 --- a/src/system/apps/Browser.ts +++ b/src/system/apps/Browser.ts @@ -9,7 +9,7 @@ const BrowserApp: Process = { targetVer: '1.0.0-indev.0' }, run: async (process) => { - const win = await process.loadLibrary('lib/WindowManager').then((wm: any) => { + const win = await process.loadLibrary('lib/WindowManager').then(wm => { return wm.createWindow({ title: 'Browser', icon, @@ -75,7 +75,7 @@ const BrowserApp: Process = { iframe: HTMLIFrameElement = document.createElement('iframe') constructor (url: string) { - this.iframe.src = `/service/${xor.encode(url) as string}` + this.iframe.src = `/service/${xor.encode(url)}` this.iframe.style.display = 'none' this.header.innerHTML = ` @@ -97,7 +97,7 @@ const BrowserApp: Process = { if (this === tabManager.activeTab) { (win.content.querySelector('.toggle') as HTMLElement).innerHTML = 'toggle_on' } - this.iframe.src = `/service/${xor.encode(win.content.querySelector('input').value) as string}` + this.iframe.src = `/service/${xor.encode(win.content.querySelector('input')?.value ?? '')}` } } @@ -167,7 +167,7 @@ const BrowserApp: Process = { win.content.querySelector('.inp')?.addEventListener('keydown', (event: KeyboardEvent) => { if (event.key === 'Enter') { - tabManager.activeTab.iframe.src = tabManager.activeTab.proxy ? `/service/${xor.encode((win.content.querySelector('.inp') as HTMLInputElement).value) as string}` : (win.content.querySelector('.inp') as HTMLInputElement).value + tabManager.activeTab.iframe.src = tabManager.activeTab.proxy ? `/service/${xor.encode((win.content.querySelector('.inp') as HTMLInputElement).value)}` : (win.content.querySelector('.inp') as HTMLInputElement).value } }); diff --git a/src/system/apps/Files.ts b/src/system/apps/Files.ts index bbcba406..7a9648ee 100644 --- a/src/system/apps/Files.ts +++ b/src/system/apps/Files.ts @@ -56,7 +56,7 @@ const Files: Process = { (win.content.querySelector('.folder') as HTMLElement).onclick = async () => { const title = prompt('Enter folder name') if (title != null) { - await fs.mkdir(`${dir}/${title}`, '') + await fs.mkdir(`${dir}/${title}`) } } @@ -69,7 +69,7 @@ const Files: Process = { const genIcon = (): string => { return `${(MIMETypes[file.split('.')[1]] === undefined ? 'draft' : MIMETypes[file.split('.')[1]].icon) as string}` } - const icon = fileStat.isDirectory() as boolean ? 'folder' : genIcon() + const icon = fileStat.isDirectory() ? 'folder' : genIcon() element.innerHTML += `${icon} ${file}delete_foreveredit`; (element.querySelector('.rename') as HTMLElement).onclick = async () => { @@ -79,7 +79,7 @@ const Files: Process = { } } (element.querySelector('.delete') as HTMLElement).onclick = async () => { - if (fileStat.isDirectory() as boolean) { + if (fileStat.isDirectory()) { await fs.rmdir(dir + seperator + file) } else { await fs.unlink(dir + seperator + file) @@ -101,7 +101,7 @@ const Files: Process = { } element.ondblclick = async () => { - if (fileStat.isDirectory() as boolean) { + if (fileStat.isDirectory()) { await setDir(dir + seperator + file) } else { await run(dir + seperator + file) diff --git a/src/system/apps/Store.ts b/src/system/apps/Store.ts index 59e6d667..7dd8176f 100644 --- a/src/system/apps/Store.ts +++ b/src/system/apps/Store.ts @@ -81,7 +81,7 @@ const Store: Process = { install(app.url) } } - }) + }).catch((e: any) => console.error(e)) }).catch((e: any) => console.error(e)) }) }) diff --git a/src/system/lib/MIMETypes.ts b/src/system/lib/MIMETypes.ts index 8a276c46..dca701bb 100644 --- a/src/system/lib/MIMETypes.ts +++ b/src/system/lib/MIMETypes.ts @@ -1,6 +1,6 @@ import { Library } from '../../types' -const MIME: Library = { +const MIMETypes: Library = { config: { name: 'MIMETypes', type: 'library', @@ -83,4 +83,4 @@ const MIME: Library = { } } -export default MIME +export default MIMETypes diff --git a/src/system/lib/VirtualFS.ts b/src/system/lib/VirtualFS.ts index 42d63e4c..ed81d8b4 100644 --- a/src/system/lib/VirtualFS.ts +++ b/src/system/lib/VirtualFS.ts @@ -1,6 +1,6 @@ import Kernel from '../../kernel' import ProcessLib from '../../structures/ProcessLib' -import { Directory, Errors, File, Library, Permission } from '../../types' +import { Directory, Errors, File, Library, Permission, Stats } from '../../types' console.debug = (...args: any[]) => { console.log('[VirtualFS]', ...args) @@ -421,7 +421,7 @@ const VirtualFS: Library = { console.debug(`readdir ${path}`) return result }, - stat: async (path: string): Promise<{ isDirectory: () => boolean, isFile: () => boolean }> => { + stat: async (path: string): Promise => { const { current } = await navigatePath(path) console.debug(`stat ${path}`) diff --git a/src/system/lib/XOR.ts b/src/system/lib/XOR.ts index 63d2f208..ab214e40 100644 --- a/src/system/lib/XOR.ts +++ b/src/system/lib/XOR.ts @@ -8,9 +8,6 @@ const XOR: Library = { }, init: (l, k, p) => {}, data: { - randomMax: 100, - randomMin: -100, - encode: (str: string): string => { return encodeURIComponent( str diff --git a/src/types.ts b/src/types.ts index 2e531741..a013c40e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,10 @@ +import HTML from './HTML' import Kernel from './kernel' import FlowWindow from './structures/FlowWindow' import LibraryLib from './structures/LibraryLib' import ProcessLib from './structures/ProcessLib' +import Components from './system/lib/Components' +import MIMETypes from './system/lib/MIMETypes' export interface AppClosedEvent extends CustomEvent { detail: { @@ -124,3 +127,61 @@ export interface KernelConfig { SERVER: string [key: string]: any } + +export interface Stats { + isDirectory: () => boolean + isFile: () => boolean +} + +export interface FileSystem { + unlink: (path: string) => Promise + readFile: (path: string) => Promise + writeFile: (path: string, content: string | Buffer) => Promise + mkdir: (path: string) => Promise + rmdir: (path: string) => Promise + readdir: (path: string) => Promise + stat: (path: string) => Promise + rename: (oldPath: string, newPath: string) => Promise + exists: (path: string) => Promise +} + +export interface ModalData { + value: boolean + win: FlowWindow +} +export interface WindowManager { + windowArea: HTML + windows: FlowWindow[] + getHighestZIndex: () => number + createWindow: (config: FlowWindowConfig, process: ProcessLib) => FlowWindow + createModal: (title: string, text: string, process: ProcessLib) => Promise +} + +export interface Launcher { + element: HTML + toggle: () => void +} + +export interface XOR { + encode: (str: string) => string + decode: (str: string) => string +} + +export interface StatusBar { + element: HTML + updateBatteryIcon: (battery: any) => void + updateIcon: (ms: number) => void +} + +export type LoadedLibrary = + T extends 'lib/VirtualFS' ? FileSystem : + T extends 'lib/WindowManager' ? WindowManager : + T extends 'lib/HTML' ? typeof HTML : + T extends 'lib/Launcher' ? Launcher : + T extends 'lib/XOR' ? XOR : + T extends 'lib/StatusBar' ? StatusBar : + T extends 'lib/MIMETypes' ? typeof MIMETypes.data : + T extends 'lib/Components' ? typeof Components.data : + any + +export type LibraryPath = 'lib/VirtualFS' | 'lib/WindowManager' | string