fix: make tests pass again

This commit is contained in:
ThinLiquid 2024-01-22 16:43:40 +00:00
parent 99f2577ee0
commit 0cf920970f
No known key found for this signature in database
GPG key ID: 17538DC3DF6A7387
8 changed files with 186 additions and 12 deletions

View file

@ -31,8 +31,7 @@ const handle = async (type: 'target' | 'service' | 'mount', name: string, Instan
name
)
console.groupEnd()
if (typeof Instance === 'object') return data
else return instance
return typeof Instance === 'object' ? data : instance
} catch (e) {
print.failed('Failed', `to start ${name}`, e)
console.error(`${spaces}${e.stack.split('\n').join(`\n${spaces}`) as string}`)

View file

@ -18,6 +18,7 @@ export default class ProcessLib {
[key: string]: Package
}
config: any
setConfig: (config: any) => any
}
readonly permission: Permission
@ -41,7 +42,10 @@ export default class ProcessLib {
getExecutable: kernel.getExecutable.bind(kernel),
processList: kernel.processList,
packageList: kernel.packageList,
config: kernel.config
config: kernel.config,
setConfig: (config) => {
if (this.permission >= Permission.ELEVATED) kernel.config = config
}
}
this.process = process
this.data = data

171
src/system/BootLoader.ts Normal file
View file

@ -0,0 +1,171 @@
import HTML from '../HTML'
import { AppClosedEvent, AppOpenedEvent, Process } from '../types'
import { getTime } from '../utils'
import nullIcon from '../assets/icons/application-default-icon.svg'
import { parse } from 'js-ini'
import { v4 as uuid } from 'uuid'
const BootLoader: Process = {
config: {
name: 'Bootloader',
type: 'process',
targetVer: '1.0.0-indev.0'
},
run: async (process) => {
const splashScreen = await process.loadLibrary('lib/SplashScreen')
const splashElement = splashScreen.getElement()
splashElement.appendTo(document.body)
const { fs } = process
const wm = await process.loadLibrary('lib/WindowManager')
const launcher = await process.loadLibrary('lib/Launcher')
const config = Buffer.from(await fs.readFile('/etc/flow')).toString()
process.kernel.setConfig(parse(config))
if ('serviceWorker' in navigator) {
const registrations = await navigator.serviceWorker.getRegistrations()
for (const registration of registrations) {
await registration.unregister()
}
try {
await navigator.serviceWorker.register(`/uv-sw.js?url=${encodeURIComponent(btoa(process.kernel.config.SERVER))}&e=${uuid()}`, {
scope: '/service/'
})
} catch (e) {
console.error(e)
}
} else {
console.warn('Service workers are not supported.')
}
const input = new HTML('input').attr({
type: 'text',
placeholder: 'Search'
}).on('keyup', () => {
apps.elm.innerHTML = ''
renderApps().catch(e => console.error(e))
}).appendTo(launcher.element)
const apps = new HTML('apps').appendTo(launcher.element)
const renderApps = async (): Promise<void> => {
apps.html('')
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((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
const appElement = new HTML('app').on('click', () => {
process.launch(path).catch((e: any) => console.error(e))
launcher.toggle()
}).appendTo(apps)
new HTML('img').attr({
src: executable.config.icon ?? nullIcon,
alt: `${executable.config.name} icon`
}).appendTo(appElement)
new HTML('div').text(executable.config.name).appendTo(appElement)
}).catch((e: any) => console.error(e))
})
}
await renderApps()
document.addEventListener('fs_update', () => {
renderApps().catch(e => console.error(e))
})
launcher.element.on('click', (e: Event) => {
if (e.target !== e.currentTarget) return
launcher.toggle()
})
const statusBar = await process.loadLibrary('lib/StatusBar')
statusBar.element.html(`
<div class="outlined" data-toolbar-id="start"><span class="material-symbols-rounded">space_dashboard</span></div>
<div data-toolbar-id="apps"></div>
<flex></flex>
<div class="outlined" data-toolbar-id="plugins"><span class="material-symbols-rounded">expand_less</span></div>
<div class="outlined" data-toolbar-id="controls">
<span class="material-symbols-rounded battery">battery_2_bar</span>
<span class="material-symbols-rounded signal">signal_cellular_4_bar</span>
</div>
<div class="outlined" data-toolbar-id="calendar"></div>
`)
setInterval((): any => {
getTime().then((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', () => {
launcher.toggle()
})
if ('getBattery' in navigator) {
(navigator as any).getBattery().then((battery: any) => {
statusBar.updateBatteryIcon(battery)
battery.addEventListener('levelchange', () => {
statusBar.updateBatteryIcon(battery)
})
battery.addEventListener('chargingchange', () => {
statusBar.updateBatteryIcon(battery)
})
})
} else {
const batteryDiv = document.querySelector('div[data-toolbar-id="controls"] > .battery')
if (batteryDiv != null) {
batteryDiv.innerHTML = 'battery_unknown'
}
}
async function ping (startTime: number): Promise<void> {
fetch(`${process.kernel.config.SERVER as string}/bare/`)
.then(() => {
const endTime = performance.now()
const pingTime = endTime - startTime
statusBar.updateIcon(pingTime)
})
.catch(() => {
(document.querySelector('div[data-toolbar-id="controls"] > .signal') as HTMLElement).innerHTML = 'signal_cellular_connected_no_internet_4_bar'
})
}
setInterval((): any => ping(performance.now()), 10_000)
document.addEventListener('app_opened', (e: AppOpenedEvent): void => {
new HTML('app').appendMany(
new HTML('img').attr({
alt: `${e.detail.proc.config.name} icon`,
'data-id': e.detail.token,
src: e.detail.proc.config.icon ?? nullIcon
}).on('click', () => {
e.detail.win.focus()
e.detail.win.toggleMin()
})
).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()
})
document.body.style.flexDirection = 'column-reverse'
await statusBar.element.appendTo(document.body)
await launcher.element.appendTo(document.body)
await wm.windowArea.appendTo(document.body)
splashElement.cleanup()
}
}
export default BootLoader

View file

@ -241,6 +241,7 @@ class VirtualFS {
const getRequest = store?.get('fs')
return await new Promise((resolve, reject) => {
if (getRequest == null) return
getRequest.onsuccess = () => {
resolve(getRequest.result)
}
@ -262,6 +263,7 @@ class VirtualFS {
const putRequest = store?.put(this.fileSystem, 'fs')
return await new Promise((resolve, reject) => {
if (putRequest == null) return
putRequest.onsuccess = () => {
document.dispatchEvent(new CustomEvent('fs_update', {}))
resolve()

View file

@ -75,7 +75,7 @@ const BrowserApp: Process = {
iframe: HTMLIFrameElement = document.createElement('iframe')
constructor (url: string) {
this.iframe.src = `/service/${xor.encode(url)}`
this.iframe.src = `/service/${xor.encode(url) as string}`
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 ?? '')}`
this.iframe.src = `/service/${xor.encode(win.content.querySelector('input')?.value ?? '') as string}`
}
}
@ -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)}` : (win.content.querySelector('.inp') as HTMLInputElement).value
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
}
});

View file

@ -24,7 +24,7 @@ const Settings: Process = {
)
})
const fs = process.fs
const { fs } = process
const HTML = await process.loadLibrary('lib/HTML')
const { Input, Button } = await process.loadLibrary('lib/Components')

View file

@ -19,7 +19,7 @@ const Store: Process = {
}, process)
})
const fs = process.fs
const { fs } = process
const HTML = await process.loadLibrary('lib/HTML')
const { Button, Icon } = await process.loadLibrary('lib/Components')

View file

@ -16,18 +16,16 @@ export const getTime = async (): Promise<string> => {
if (hours === 0) {
hours = 12
} else if (hours > 12) {
hours = hours % 12
hours %= 12
}
}
hours = (hours < 10) ? `0${hours}` : hours
minutes = (minutes < 10) ? `0${minutes}` : minutes
const timeString = use24hrs
return use24hrs
? `${hours}:${minutes}`
: `${hours}:${minutes} ${period}`
return timeString
}
/**