[🔨] Mass refactor
This commit is contained in:
parent
36201f4af1
commit
3402faf74e
15 changed files with 163 additions and 192 deletions
55
src/HTML.ts
55
src/HTML.ts
|
|
@ -6,11 +6,7 @@ export default class HTML {
|
||||||
* @param elm The HTML element to be created or classified from.
|
* @param elm The HTML element to be created or classified from.
|
||||||
*/
|
*/
|
||||||
constructor (elm: string | HTMLElement) {
|
constructor (elm: string | HTMLElement) {
|
||||||
if (elm instanceof HTMLElement) {
|
this.elm = elm instanceof HTMLElement ? elm : document.createElement(elm === '' ? 'div' : elm)
|
||||||
this.elm = elm
|
|
||||||
} else {
|
|
||||||
this.elm = document.createElement(elm === '' ? 'div' : elm)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -57,11 +53,7 @@ export default class HTML {
|
||||||
* @returns a new HTML
|
* @returns a new HTML
|
||||||
*/
|
*/
|
||||||
qs (query: string): HTML | null {
|
qs (query: string): HTML | null {
|
||||||
if (this.elm.querySelector(query) != null) {
|
return this.elm.querySelector(query) != null ? HTML.from(this.elm.querySelector(query) as HTMLElement) : null
|
||||||
return HTML.from(this.elm.querySelector(query) as HTMLElement)
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,13 +62,11 @@ export default class HTML {
|
||||||
* @returns a new HTML
|
* @returns a new HTML
|
||||||
*/
|
*/
|
||||||
qsa (query: string): Array<HTML | null> | null {
|
qsa (query: string): Array<HTML | null> | null {
|
||||||
if (this.elm.querySelector(query) != null) {
|
return this.elm.querySelector(query) != null
|
||||||
return Array.from(this.elm.querySelectorAll(query)).map((e) =>
|
? Array.from(this.elm.querySelectorAll(query)).map((e) =>
|
||||||
HTML.from(e as HTMLElement)
|
HTML.from(e as HTMLElement)
|
||||||
)
|
)
|
||||||
} else {
|
: null
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -95,8 +85,8 @@ export default class HTML {
|
||||||
* @returns HTML
|
* @returns HTML
|
||||||
*/
|
*/
|
||||||
class (...val: string[]): HTML {
|
class (...val: string[]): HTML {
|
||||||
for (let i = 0; i < val.length; i++) {
|
for (const element of val) {
|
||||||
this.elm.classList.toggle(val[i])
|
this.elm.classList.toggle(element)
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
@ -107,8 +97,8 @@ export default class HTML {
|
||||||
* @returns HTML
|
* @returns HTML
|
||||||
*/
|
*/
|
||||||
classOn (...val: string[]): HTML {
|
classOn (...val: string[]): HTML {
|
||||||
for (let i = 0; i < val.length; i++) {
|
for (const element of val) {
|
||||||
this.elm.classList.add(val[i])
|
this.elm.classList.add(element)
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
@ -119,8 +109,8 @@ export default class HTML {
|
||||||
* @returns HTML
|
* @returns HTML
|
||||||
*/
|
*/
|
||||||
classOff (...val: string[]): HTML {
|
classOff (...val: string[]): HTML {
|
||||||
for (let i = 0; i < val.length; i++) {
|
for (const element of val) {
|
||||||
this.elm.classList.remove(val[i])
|
this.elm.classList.remove(element)
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
@ -234,10 +224,10 @@ export default class HTML {
|
||||||
*/
|
*/
|
||||||
attr (obj: { [x: string]: any }): HTML {
|
attr (obj: { [x: string]: any }): HTML {
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (obj[key] !== null && obj[key] !== undefined) {
|
if (obj[key] == null) {
|
||||||
this.elm.setAttribute(key, obj[key])
|
|
||||||
} else {
|
|
||||||
this.elm.removeAttribute(key)
|
this.elm.removeAttribute(key)
|
||||||
|
} else {
|
||||||
|
this.elm.setAttribute(key, obj[key])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
|
|
@ -296,8 +286,7 @@ export default class HTML {
|
||||||
static from (elm: HTMLElement | string): HTML | null {
|
static from (elm: HTMLElement | string): HTML | null {
|
||||||
if (typeof elm === 'string') {
|
if (typeof elm === 'string') {
|
||||||
const element = HTML.qs(elm)
|
const element = HTML.qs(elm)
|
||||||
if (element === null) return null
|
return element === null ? null : element
|
||||||
else return element
|
|
||||||
} else {
|
} else {
|
||||||
return new HTML(elm)
|
return new HTML(elm)
|
||||||
}
|
}
|
||||||
|
|
@ -309,11 +298,7 @@ export default class HTML {
|
||||||
* @returns a new HTML
|
* @returns a new HTML
|
||||||
*/
|
*/
|
||||||
static qs (query: string): HTML | null {
|
static qs (query: string): HTML | null {
|
||||||
if (document.querySelector(query) != null) {
|
return document.querySelector(query) != null ? HTML.from(document.querySelector(query) as HTMLElement) : null
|
||||||
return HTML.from(document.querySelector(query) as HTMLElement)
|
|
||||||
} else {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -322,12 +307,10 @@ export default class HTML {
|
||||||
* @returns a new HTML
|
* @returns a new HTML
|
||||||
*/
|
*/
|
||||||
static qsa (query: string): Array<HTML | null> | null {
|
static qsa (query: string): Array<HTML | null> | null {
|
||||||
if (document.querySelector(query) != null) {
|
return document.querySelector(query) != null
|
||||||
return Array.from(document.querySelectorAll(query)).map((e) =>
|
? Array.from(document.querySelectorAll(query)).map((e) =>
|
||||||
HTML.from(e as HTMLElement)
|
HTML.from(e as HTMLElement)
|
||||||
)
|
)
|
||||||
} else {
|
: null
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ async function enableDebug (): Promise<void> {
|
||||||
return await Promise.resolve()
|
return await Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.get('debug') !== null && params.get('debug') !== undefined) {
|
if (params.get('debug') != null) {
|
||||||
enableDebug().catch(e => console.error(e))
|
enableDebug().catch(e => console.error(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ export default class Kernel {
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
} catch {
|
} catch {
|
||||||
if (this.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
if (this.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
||||||
const dataURL = 'data:text/javascript;base64,' + Buffer.from(await this.fs.readFile('/opt/' + url + '.js')).toString('base64')
|
const dataURL = `data:text/javascript;base64,${Buffer.from(await this.fs.readFile(`/opt/${url}.js`)).toString('base64')}`
|
||||||
const importedExecutable = await import(dataURL)
|
const importedExecutable = await import(dataURL)
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
}
|
}
|
||||||
|
|
@ -81,32 +81,26 @@ export default class Kernel {
|
||||||
else if (this.packageList[executable.config.name].url !== url) throw new Error(`Package name conflict: ${executable.config.name}`)
|
else if (this.packageList[executable.config.name].url !== url) throw new Error(`Package name conflict: ${executable.config.name}`)
|
||||||
|
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
switch (executable.config.type) {
|
if (executable.config.type === 'process') {
|
||||||
case 'process': {
|
const executableProcess = executable as Process
|
||||||
const executableProcess = executable as Process
|
console.group(`Starting ${url}`)
|
||||||
console.group(`Starting ${url}`)
|
const pid = ProcLib.findEmptyPID(this)
|
||||||
const pid = ProcLib.findEmptyPID(this)
|
const token = uuid()
|
||||||
const token = uuid()
|
const procLib = new ProcessLib(url, pid, token, permission, data, executableProcess, this)
|
||||||
const procLib = new ProcessLib(url, pid, token, permission, data, executableProcess, this)
|
this.processList.push({
|
||||||
this.processList.push({
|
pid,
|
||||||
pid,
|
token,
|
||||||
token,
|
name: executableProcess.config.name
|
||||||
name: executableProcess.config.name
|
})
|
||||||
})
|
document.dispatchEvent(new CustomEvent('update_process', {}))
|
||||||
|
executableProcess.run(procLib).then((value: any) => {
|
||||||
|
if (value !== undefined) procLib.kill().catch(e => console.error(e))
|
||||||
document.dispatchEvent(new CustomEvent('update_process', {}))
|
document.dispatchEvent(new CustomEvent('update_process', {}))
|
||||||
executableProcess.run(procLib).then((value: any) => {
|
resolve({ procLib, value })
|
||||||
if (value !== undefined) procLib.kill().catch(e => console.error(e))
|
}).catch(e => console.error(e))
|
||||||
document.dispatchEvent(new CustomEvent('update_process', {}))
|
return
|
||||||
resolve({ procLib, value })
|
|
||||||
}).catch(e => console.error(e))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
reject(new Error(`Unknown executable type: ${executable.config.type as string}`))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
reject(new Error(`Unknown executable type: ${executable.config.type as string}`))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +113,7 @@ export default class Kernel {
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
} catch {
|
} catch {
|
||||||
if (this.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
if (this.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
||||||
const dataURL = 'data:text/javascript;base64,' + Buffer.from(await this.fs.readFile('/opt/' + url + '.js')).toString('base64')
|
const dataURL = `data:text/javascript;base64,${Buffer.from(await this.fs.readFile(`/opt/${url}.js`)).toString('base64')}`
|
||||||
const importedExecutable = await import(dataURL)
|
const importedExecutable = await import(dataURL)
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export default class ProcessLib {
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
} catch {
|
} catch {
|
||||||
if (this._kernel.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
if (this._kernel.fs === undefined) throw new Error('Filesystem hasn\'t been initiated.')
|
||||||
const dataURL = 'data:text/javascript;base64,' + Buffer.from(await this._kernel.fs.readFile('/opt/' + url + '.js')).toString('base64')
|
const dataURL = `data:text/javascript;base64,${Buffer.from(await this._kernel.fs.readFile(`/opt/${url}.js`)).toString('base64')}`
|
||||||
const importedExecutable = await import(dataURL)
|
const importedExecutable = await import(dataURL)
|
||||||
executable = importedExecutable.default
|
executable = importedExecutable.default
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,11 @@ const BootLoader: Process = {
|
||||||
console.warn('Persistent storage is not supported.')
|
console.warn('Persistent storage is not supported.')
|
||||||
}
|
}
|
||||||
const fileSystem = await read()
|
const fileSystem = await read()
|
||||||
fileSystem === undefined ? await write(defaultFS) : await setFileSystem(fileSystem)
|
if (fileSystem === undefined) {
|
||||||
|
await write(defaultFS)
|
||||||
|
} else {
|
||||||
|
await setFileSystem(fileSystem)
|
||||||
|
}
|
||||||
|
|
||||||
const config = Buffer.from(await fs.readFile('/etc/flow')).toString()
|
const config = Buffer.from(await fs.readFile('/etc/flow')).toString()
|
||||||
process.kernel.setFS(fs)
|
process.kernel.setFS(fs)
|
||||||
|
|
@ -46,7 +50,7 @@ const BootLoader: Process = {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await navigator.serviceWorker.register('/uv-sw.js?url=' + encodeURIComponent(btoa(process.kernel.config.SERVER)) + '&e=' + uuid(), {
|
await navigator.serviceWorker.register(`/uv-sw.js?url=${encodeURIComponent(btoa(process.kernel.config.SERVER))}&e=${uuid()}`, {
|
||||||
scope: '/service/'
|
scope: '/service/'
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -81,7 +85,7 @@ const BootLoader: Process = {
|
||||||
}).appendTo(apps)
|
}).appendTo(apps)
|
||||||
new HTML('img').attr({
|
new HTML('img').attr({
|
||||||
src: executable.config.icon ?? nullIcon,
|
src: executable.config.icon ?? nullIcon,
|
||||||
alt: executable.config.name + ' icon'
|
alt: `${executable.config.name} icon`
|
||||||
}).appendTo(appElement)
|
}).appendTo(appElement)
|
||||||
new HTML('div').text(executable.config.name).appendTo(appElement)
|
new HTML('div').text(executable.config.name).appendTo(appElement)
|
||||||
})
|
})
|
||||||
|
|
@ -102,7 +106,7 @@ const BootLoader: Process = {
|
||||||
|
|
||||||
statusBar.element.html(`
|
statusBar.element.html(`
|
||||||
<div class="outlined" data-toolbar-id="start"><span class="material-symbols-rounded">space_dashboard</span></div>
|
<div class="outlined" data-toolbar-id="start"><span class="material-symbols-rounded">space_dashboard</span></div>
|
||||||
${/* <div class="outlined" data-toolbar-id="widgets"><span class="material-symbols-rounded">widgets</span></div> */ ''}
|
|
||||||
<div data-toolbar-id="apps"></div>
|
<div data-toolbar-id="apps"></div>
|
||||||
<flex></flex>
|
<flex></flex>
|
||||||
<div class="outlined" data-toolbar-id="plugins"><span class="material-symbols-rounded">expand_less</span></div>
|
<div class="outlined" data-toolbar-id="plugins"><span class="material-symbols-rounded">expand_less</span></div>
|
||||||
|
|
@ -111,9 +115,7 @@ const BootLoader: Process = {
|
||||||
<span class="material-symbols-rounded signal">signal_cellular_4_bar</span>
|
<span class="material-symbols-rounded signal">signal_cellular_4_bar</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="outlined" data-toolbar-id="calendar"></div>
|
<div class="outlined" data-toolbar-id="calendar"></div>
|
||||||
${/* <div class="outlined" data-toolbar-id="notifications">
|
|
||||||
<span class="material-symbols-rounded">notifications</span>
|
|
||||||
</div> */ ''}
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
setInterval((): any => {
|
setInterval((): any => {
|
||||||
|
|
@ -127,14 +129,14 @@ const BootLoader: Process = {
|
||||||
})
|
})
|
||||||
|
|
||||||
if ('getBattery' in navigator) {
|
if ('getBattery' in navigator) {
|
||||||
(navigator as any).getBattery().then(function (battery: any) {
|
(navigator as any).getBattery().then((battery: any) => {
|
||||||
statusBar.updateBatteryIcon(battery)
|
statusBar.updateBatteryIcon(battery)
|
||||||
|
|
||||||
battery.addEventListener('levelchange', function () {
|
battery.addEventListener('levelchange', () => {
|
||||||
statusBar.updateBatteryIcon(battery)
|
statusBar.updateBatteryIcon(battery)
|
||||||
})
|
})
|
||||||
|
|
||||||
battery.addEventListener('chargingchange', function () {
|
battery.addEventListener('chargingchange', () => {
|
||||||
statusBar.updateBatteryIcon(battery)
|
statusBar.updateBatteryIcon(battery)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
@ -157,12 +159,12 @@ const BootLoader: Process = {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval((): any => ping(performance.now()), 10000)
|
setInterval((): any => ping(performance.now()), 10_000)
|
||||||
|
|
||||||
document.addEventListener('app_opened', (e: AppOpenedEvent): void => {
|
document.addEventListener('app_opened', (e: AppOpenedEvent): void => {
|
||||||
new HTML('app').appendMany(
|
new HTML('app').appendMany(
|
||||||
new HTML('img').attr({
|
new HTML('img').attr({
|
||||||
alt: e.detail.proc.config.name + ' icon',
|
alt: `${e.detail.proc.config.name} icon`,
|
||||||
'data-id': e.detail.token,
|
'data-id': e.detail.token,
|
||||||
src: e.detail.proc.config.icon ?? nullIcon
|
src: e.detail.proc.config.icon ?? nullIcon
|
||||||
}).on('click', () => {
|
}).on('click', () => {
|
||||||
|
|
|
||||||
|
|
@ -9,41 +9,42 @@ const UserAccessControl: Process = {
|
||||||
targetVer: '1.0.0-indev.0'
|
targetVer: '1.0.0-indev.0'
|
||||||
},
|
},
|
||||||
run: async (process) => {
|
run: async (process) => {
|
||||||
if (Object.keys(process.data).length > 0) {
|
if (Object.keys(process.data).length <= 0) {
|
||||||
const initiator = process.data.process.process
|
return
|
||||||
const target = process.data.executable
|
|
||||||
return await new Promise((resolve) => {
|
|
||||||
process.loadLibrary('lib/WindowManager').then(async wm => {
|
|
||||||
let message
|
|
||||||
switch (process.data.type) {
|
|
||||||
case 'launch': {
|
|
||||||
message = `${initiator.config.name as string} wants to launch ${target.config.name as string}`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'kill': {
|
|
||||||
message = `${initiator.config.name as string} wants to kill ${process.data.name as string}`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
case 'fs': {
|
|
||||||
message = `${initiator.config.name as string} wants to modify/access ${process.data.path as string}`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wm.createModal('User Account Control', message, process)
|
|
||||||
.then(async ({ value, win }: {
|
|
||||||
value: boolean
|
|
||||||
win: FlowWindow
|
|
||||||
}) => {
|
|
||||||
if (value) {
|
|
||||||
resolve(true)
|
|
||||||
} else {
|
|
||||||
resolve(false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}).catch((e) => console.error(e))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
const initiator = process.data.process.process
|
||||||
|
const target = process.data.executable
|
||||||
|
return await new Promise((resolve) => {
|
||||||
|
process.loadLibrary('lib/WindowManager').then(async wm => {
|
||||||
|
let message
|
||||||
|
switch (process.data.type) {
|
||||||
|
case 'launch': {
|
||||||
|
message = `${initiator.config.name as string} wants to launch ${target.config.name as string}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'kill': {
|
||||||
|
message = `${initiator.config.name as string} wants to kill ${process.data.name as string}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'fs': {
|
||||||
|
message = `${initiator.config.name as string} wants to modify/access ${process.data.path as string}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wm.createModal('User Account Control', message, process)
|
||||||
|
.then(async ({ value, win }: {
|
||||||
|
value: boolean
|
||||||
|
win: FlowWindow
|
||||||
|
}) => {
|
||||||
|
if (value) {
|
||||||
|
resolve(true)
|
||||||
|
} else {
|
||||||
|
resolve(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).catch((e) => console.error(e))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,12 @@ const BrowserApp: Process = {
|
||||||
}
|
}
|
||||||
(this.header.querySelector('.title') as HTMLElement).innerText = 'Tab'
|
(this.header.querySelector('.title') as HTMLElement).innerText = 'Tab'
|
||||||
this.iframe.src = (win.content.querySelector('input')?.value as string)
|
this.iframe.src = (win.content.querySelector('input')?.value as string)
|
||||||
} else {
|
return
|
||||||
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}`
|
|
||||||
}
|
}
|
||||||
|
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}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,20 +137,21 @@ const BrowserApp: Process = {
|
||||||
|
|
||||||
setActiveTab (tab: Tab): void {
|
setActiveTab (tab: Tab): void {
|
||||||
this.tabs.forEach((tab) => {
|
this.tabs.forEach((tab) => {
|
||||||
if (tab.active) {
|
if (!tab.active) {
|
||||||
tab.active = false
|
return
|
||||||
tab.iframe.style.display = 'none'
|
|
||||||
tab.header.classList.remove('active')
|
|
||||||
}
|
}
|
||||||
|
tab.active = false
|
||||||
|
tab.iframe.style.display = 'none'
|
||||||
|
tab.header.classList.remove('active')
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!tab.proxy) {
|
if (tab.proxy) {
|
||||||
|
try { (win.content.querySelector('.inp') as HTMLInputElement).value = xor.decode((tab.iframe.contentWindow as Window).location.href.split('/service/')[1]) } catch (e) { (win.content.querySelector('.inp') as HTMLInputElement).value = 'about:blank' }
|
||||||
|
(win.content.querySelector('.toggle') as HTMLElement).innerHTML = 'toggle_on'
|
||||||
|
} else {
|
||||||
(tab.header.querySelector('.title') as HTMLElement).textContent = 'Tab'
|
(tab.header.querySelector('.title') as HTMLElement).textContent = 'Tab'
|
||||||
try { (win.content.querySelector('.inp') as HTMLInputElement).value = (tab.iframe.contentWindow as Window).location.href } catch (e) { (win.content.querySelector('.inp') as HTMLInputElement).value = 'about:blank' }
|
try { (win.content.querySelector('.inp') as HTMLInputElement).value = (tab.iframe.contentWindow as Window).location.href } catch (e) { (win.content.querySelector('.inp') as HTMLInputElement).value = 'about:blank' }
|
||||||
(win.content.querySelector('.toggle') as HTMLElement).innerHTML = 'toggle_off'
|
(win.content.querySelector('.toggle') as HTMLElement).innerHTML = 'toggle_off'
|
||||||
} else {
|
|
||||||
try { (win.content.querySelector('.inp') as HTMLInputElement).value = xor.decode((tab.iframe.contentWindow as Window).location.href.split('/service/')[1]) } catch (e) { (win.content.querySelector('.inp') as HTMLInputElement).value = 'about:blank' }
|
|
||||||
(win.content.querySelector('.toggle') as HTMLElement).innerHTML = 'toggle_on'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tab.active = true
|
tab.active = true
|
||||||
|
|
@ -166,11 +167,7 @@ const BrowserApp: Process = {
|
||||||
|
|
||||||
win.content.querySelector('.inp')?.addEventListener('keydown', (event: KeyboardEvent) => {
|
win.content.querySelector('.inp')?.addEventListener('keydown', (event: KeyboardEvent) => {
|
||||||
if (event.key === 'Enter') {
|
if (event.key === 'Enter') {
|
||||||
if (tabManager.activeTab.proxy) {
|
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 = `/service/${xor.encode((win.content.querySelector('.inp') as HTMLInputElement).value) as string}`
|
|
||||||
} else {
|
|
||||||
tabManager.activeTab.iframe.src = (win.content.querySelector('.inp') as HTMLInputElement).value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -195,18 +192,14 @@ const BrowserApp: Process = {
|
||||||
}
|
}
|
||||||
|
|
||||||
win.content.onfullscreenchange = () => {
|
win.content.onfullscreenchange = () => {
|
||||||
if (document.fullscreenElement !== null) {
|
(win.content.querySelector('.fullscreen') as HTMLElement).innerHTML = document.fullscreenElement !== null ? 'fullscreen_exit' : 'fullscreen'
|
||||||
(win.content.querySelector('.fullscreen') as HTMLElement).innerHTML = 'fullscreen_exit'
|
|
||||||
} else {
|
|
||||||
(win.content.querySelector('.fullscreen') as HTMLElement).innerHTML = 'fullscreen'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(win.content.querySelector('.fullscreen') as HTMLElement).onclick = async () => {
|
(win.content.querySelector('.fullscreen') as HTMLElement).onclick = async () => {
|
||||||
if (document.fullscreenElement !== null) {
|
if (document.fullscreenElement === null) {
|
||||||
await document.exitFullscreen().catch(e => console.error)
|
|
||||||
} else {
|
|
||||||
await win.content.requestFullscreen().catch((e: any) => console.error)
|
await win.content.requestFullscreen().catch((e: any) => console.error)
|
||||||
|
} else {
|
||||||
|
await document.exitFullscreen().catch(e => console.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,12 @@ const Editor: Process = {
|
||||||
win.content.style.display = 'flex'
|
win.content.style.display = 'flex'
|
||||||
win.content.style.flexDirection = 'column'
|
win.content.style.flexDirection = 'column'
|
||||||
|
|
||||||
if (data != null) {
|
if (data == null) {
|
||||||
|
await process.launch('lib/FileManager')
|
||||||
|
setTimeout(() => {
|
||||||
|
win.close()
|
||||||
|
}, 10)
|
||||||
|
} else {
|
||||||
const render = async (): Promise<void> => {
|
const render = async (): Promise<void> => {
|
||||||
win.content.innerHTML = `
|
win.content.innerHTML = `
|
||||||
<div style="padding: 5px;display: flex;align-items: center;gap: 5px;">
|
<div style="padding: 5px;display: flex;align-items: center;gap: 5px;">
|
||||||
|
|
@ -203,16 +208,11 @@ const Editor: Process = {
|
||||||
document.addEventListener('fs_update', () => {
|
document.addEventListener('fs_update', () => {
|
||||||
render().catch(e => console.error(e))
|
render().catch(e => console.error(e))
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
await process.launch('lib/FileManager')
|
|
||||||
setTimeout(() => {
|
|
||||||
win.close()
|
|
||||||
}, 10)
|
|
||||||
}
|
}
|
||||||
} else {
|
return
|
||||||
await process.kill()
|
|
||||||
await process.launch('apps/Files')
|
|
||||||
}
|
}
|
||||||
|
await process.kill()
|
||||||
|
await process.launch('apps/Files')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,14 +48,14 @@ const Files: Process = {
|
||||||
|
|
||||||
(win.content.querySelector('.file') as HTMLElement).onclick = async () => {
|
(win.content.querySelector('.file') as HTMLElement).onclick = async () => {
|
||||||
const title: string | null | undefined = prompt('Enter file name')
|
const title: string | null | undefined = prompt('Enter file name')
|
||||||
if (title !== null && title !== undefined) {
|
if (title != null) {
|
||||||
await fs.writeFile(`${dir}/${title}`, '')
|
await fs.writeFile(`${dir}/${title}`, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(win.content.querySelector('.folder') as HTMLElement).onclick = async () => {
|
(win.content.querySelector('.folder') as HTMLElement).onclick = async () => {
|
||||||
const title: string | null | undefined = prompt('Enter folder name')
|
const title: string | null | undefined = prompt('Enter folder name')
|
||||||
if (title !== null && title !== undefined) {
|
if (title != null) {
|
||||||
await fs.mkdir(`${dir}/${title}`, '')
|
await fs.mkdir(`${dir}/${title}`, '')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ const ImageViewer: Process = {
|
||||||
document.addEventListener('fs_update', () => {
|
document.addEventListener('fs_update', () => {
|
||||||
render().catch(e => console.error(e))
|
render().catch(e => console.error(e))
|
||||||
})
|
})
|
||||||
} else {
|
return
|
||||||
await process.kill()
|
|
||||||
await process.launch('apps/Files')
|
|
||||||
}
|
}
|
||||||
|
await process.kill()
|
||||||
|
await process.launch('apps/Files')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ const Store: Process = {
|
||||||
|
|
||||||
win.content.style.background = 'var(--base)'
|
win.content.style.background = 'var(--base)'
|
||||||
|
|
||||||
fetch(process.kernel.config.SERVER as string + '/apps/list/')
|
fetch(`${process.kernel.config.SERVER as string}/apps/list/`)
|
||||||
.then(async (res) => await res.json())
|
.then(async (res) => await res.json())
|
||||||
.then(handle)
|
.then(handle)
|
||||||
.catch(e => console.error(e))
|
.catch(e => console.error(e))
|
||||||
document.addEventListener('fs_update', () => {
|
document.addEventListener('fs_update', () => {
|
||||||
fetch(process.kernel.config.SERVER as string + '/apps/list/')
|
fetch(`${process.kernel.config.SERVER as string}/apps/list/`)
|
||||||
.then(async (res) => await res.json())
|
.then(async (res) => await res.json())
|
||||||
.then(handle)
|
.then(handle)
|
||||||
.catch(e => console.error(e))
|
.catch(e => console.error(e))
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ const TaskManager: Process = {
|
||||||
}).appendTo(win.content)
|
}).appendTo(win.content)
|
||||||
|
|
||||||
const render = (): void => {
|
const render = (): void => {
|
||||||
const processList = process.kernel.processList
|
const { processList } = process.kernel
|
||||||
table.html('')
|
table.html('')
|
||||||
|
|
||||||
new HTML('thead').appendTo(table)
|
new HTML('thead').appendTo(table)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ import FlowLogo from '../../assets/flow.png'
|
||||||
import { Library } from '../../types'
|
import { Library } from '../../types'
|
||||||
import LibraryLib from '../../structures/LibraryLib'
|
import LibraryLib from '../../structures/LibraryLib'
|
||||||
|
|
||||||
let library: LibraryLib, kernel: Kernel
|
let library: LibraryLib
|
||||||
|
let kernel: Kernel
|
||||||
|
|
||||||
const SplashScreen: Library = {
|
const SplashScreen: Library = {
|
||||||
config: {
|
config: {
|
||||||
|
|
|
||||||
|
|
@ -29,24 +29,22 @@ const StatusBar: Library = {
|
||||||
} else if (battery.level >= 0) {
|
} else if (battery.level >= 0) {
|
||||||
iconHTML = 'battery_charging_20'
|
iconHTML = 'battery_charging_20'
|
||||||
}
|
}
|
||||||
} else {
|
} else if (battery.level === 1) {
|
||||||
if (battery.level === 1) {
|
iconHTML = 'battery_full'
|
||||||
iconHTML = 'battery_full'
|
} else if (battery.level >= 0.6) {
|
||||||
} else if (battery.level >= 0.6) {
|
iconHTML = 'battery_6_bar'
|
||||||
iconHTML = 'battery_6_bar'
|
} else if (battery.level >= 0.5) {
|
||||||
} else if (battery.level >= 0.5) {
|
iconHTML = 'battery_5_bar'
|
||||||
iconHTML = 'battery_5_bar'
|
} else if (battery.level >= 0.4) {
|
||||||
} else if (battery.level >= 0.4) {
|
iconHTML = 'battery_4_bar'
|
||||||
iconHTML = 'battery_4_bar'
|
} else if (battery.level >= 0.3) {
|
||||||
} else if (battery.level >= 0.3) {
|
iconHTML = 'battery_3_bar'
|
||||||
iconHTML = 'battery_3_bar'
|
} else if (battery.level >= 0.2) {
|
||||||
} else if (battery.level >= 0.2) {
|
iconHTML = 'battery_2_bar'
|
||||||
iconHTML = 'battery_2_bar'
|
} else if (battery.level >= 0.1) {
|
||||||
} else if (battery.level >= 0.1) {
|
iconHTML = 'battery_1_bar'
|
||||||
iconHTML = 'battery_1_bar'
|
} else if (battery.level >= 0) {
|
||||||
} else if (battery.level >= 0) {
|
iconHTML = 'battery_0_bar'
|
||||||
iconHTML = 'battery_0_bar'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const batteryDiv = document.querySelector('div[data-toolbar-id="controls"] > .battery')
|
const batteryDiv = document.querySelector('div[data-toolbar-id="controls"] > .battery')
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,8 @@ export const setFileSystem = async (fileSystemObject: { root: Directory }): Prom
|
||||||
|
|
||||||
export let db: IDBDatabase
|
export let db: IDBDatabase
|
||||||
let fileSystem: { root: Directory }
|
let fileSystem: { root: Directory }
|
||||||
let kernel: Kernel, process: ProcessLib
|
let kernel: Kernel
|
||||||
|
let process: ProcessLib
|
||||||
|
|
||||||
export const initializeDatabase = async (dbName: string): Promise<boolean> => {
|
export const initializeDatabase = async (dbName: string): Promise<boolean> => {
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
|
|
@ -315,9 +316,7 @@ const save = async (): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePermissions = async (path: string): Promise<void> => {
|
const handlePermissions = async (path: string): Promise<void> => {
|
||||||
let current
|
let { current } = (await navigatePath(path))
|
||||||
|
|
||||||
current = (await navigatePath(path)).current
|
|
||||||
|
|
||||||
if (current === undefined) current = (await navigatePathParent(path)).current
|
if (current === undefined) current = (await navigatePathParent(path)).current
|
||||||
|
|
||||||
|
|
@ -374,7 +373,7 @@ const VirtualFS: Library = {
|
||||||
|
|
||||||
Reflect.deleteProperty(current.children, filename)
|
Reflect.deleteProperty(current.children, filename)
|
||||||
|
|
||||||
console.debug('unlink ' + path)
|
console.debug(`unlink ${path}`)
|
||||||
await save()
|
await save()
|
||||||
},
|
},
|
||||||
readFile: async (path: string): Promise<Buffer> => {
|
readFile: async (path: string): Promise<Buffer> => {
|
||||||
|
|
@ -384,7 +383,7 @@ const VirtualFS: Library = {
|
||||||
|
|
||||||
if (current.type !== 'file') throw new Error(Errors.EISDIR)
|
if (current.type !== 'file') throw new Error(Errors.EISDIR)
|
||||||
|
|
||||||
console.debug('read ' + path)
|
console.debug(`read ${path}`)
|
||||||
return current.content
|
return current.content
|
||||||
},
|
},
|
||||||
writeFile: async (path: string, content: string | Buffer): Promise<void> => {
|
writeFile: async (path: string, content: string | Buffer): Promise<void> => {
|
||||||
|
|
@ -392,11 +391,11 @@ const VirtualFS: Library = {
|
||||||
|
|
||||||
let permission
|
let permission
|
||||||
|
|
||||||
if (typeof current.children[filename] !== 'undefined') {
|
if (typeof current.children[filename] === 'undefined') {
|
||||||
|
permission = Permission.USER
|
||||||
|
} else {
|
||||||
await handlePermissions(path)
|
await handlePermissions(path)
|
||||||
permission = current.children[filename].permission
|
permission = current.children[filename].permission
|
||||||
} else {
|
|
||||||
permission = Permission.USER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current.children[filename] = {
|
current.children[filename] = {
|
||||||
|
|
@ -406,7 +405,7 @@ const VirtualFS: Library = {
|
||||||
content: Buffer.from(content)
|
content: Buffer.from(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('write ' + path)
|
console.debug(`write ${path}`)
|
||||||
await save()
|
await save()
|
||||||
},
|
},
|
||||||
mkdir: async (path: string): Promise<void> => {
|
mkdir: async (path: string): Promise<void> => {
|
||||||
|
|
@ -414,11 +413,11 @@ const VirtualFS: Library = {
|
||||||
|
|
||||||
let permission
|
let permission
|
||||||
|
|
||||||
if (typeof current.children[filename] !== 'undefined') {
|
if (typeof current.children[filename] === 'undefined') {
|
||||||
|
permission = Permission.USER
|
||||||
|
} else {
|
||||||
await handlePermissions(path)
|
await handlePermissions(path)
|
||||||
permission = current.children[filename].permission
|
permission = current.children[filename].permission
|
||||||
} else {
|
|
||||||
permission = Permission.USER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
current.children[filename] = {
|
current.children[filename] = {
|
||||||
|
|
@ -428,7 +427,7 @@ const VirtualFS: Library = {
|
||||||
children: {}
|
children: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug('mkdir ' + path)
|
console.debug(`mkdir ${path}`)
|
||||||
await save()
|
await save()
|
||||||
},
|
},
|
||||||
rmdir: async (path: string): Promise<void> => {
|
rmdir: async (path: string): Promise<void> => {
|
||||||
|
|
@ -441,7 +440,7 @@ const VirtualFS: Library = {
|
||||||
|
|
||||||
Reflect.deleteProperty(current.children, filename)
|
Reflect.deleteProperty(current.children, filename)
|
||||||
|
|
||||||
console.debug('rmdir ' + path)
|
console.debug(`rmdir ${path}`)
|
||||||
await save()
|
await save()
|
||||||
},
|
},
|
||||||
readdir: async (path: string): Promise<string[]> => {
|
readdir: async (path: string): Promise<string[]> => {
|
||||||
|
|
@ -450,13 +449,13 @@ const VirtualFS: Library = {
|
||||||
if (current.type === 'file') throw new Error(Errors.ENOTDIR)
|
if (current.type === 'file') throw new Error(Errors.ENOTDIR)
|
||||||
const result = await Promise.all(Object.keys(current.children ?? {}))
|
const result = await Promise.all(Object.keys(current.children ?? {}))
|
||||||
|
|
||||||
console.debug('readdir ' + path)
|
console.debug(`readdir ${path}`)
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
stat: async (path: string): Promise<{ isDirectory: () => boolean, isFile: () => boolean }> => {
|
stat: async (path: string): Promise<{ isDirectory: () => boolean, isFile: () => boolean }> => {
|
||||||
const { current } = await navigatePath(path)
|
const { current } = await navigatePath(path)
|
||||||
|
|
||||||
console.debug('stat ' + path)
|
console.debug(`stat ${path}`)
|
||||||
return {
|
return {
|
||||||
isDirectory: () => current.type === 'directory',
|
isDirectory: () => current.type === 'directory',
|
||||||
isFile: () => current.type === 'file'
|
isFile: () => current.type === 'file'
|
||||||
|
|
@ -475,11 +474,11 @@ const VirtualFS: Library = {
|
||||||
newCurrent.children[newFilename] = oldCurrent.children[oldFilename]
|
newCurrent.children[newFilename] = oldCurrent.children[oldFilename]
|
||||||
Reflect.deleteProperty(oldCurrent.children, oldFilename)
|
Reflect.deleteProperty(oldCurrent.children, oldFilename)
|
||||||
|
|
||||||
console.debug('rename ' + oldPath + ' -> ' + newPath)
|
console.debug(`rename ${oldPath} -> ${newPath}`)
|
||||||
await save()
|
await save()
|
||||||
},
|
},
|
||||||
exists: async (path: string): Promise<boolean> => {
|
exists: async (path: string): Promise<boolean> => {
|
||||||
console.debug('exists ' + path)
|
console.debug(`exists ${path}`)
|
||||||
try {
|
try {
|
||||||
const { current } = await navigatePath(path)
|
const { current } = await navigatePath(path)
|
||||||
return current !== undefined
|
return current !== undefined
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ const XOR: Library = {
|
||||||
|
|
||||||
return indCheck ? String.fromCharCode(char.charCodeAt(0) ^ 2) : char
|
return indCheck ? String.fromCharCode(char.charCodeAt(0) ^ 2) : char
|
||||||
})
|
})
|
||||||
.join('') + ((search.length > 0) ? '?' + search.join('?') : '')
|
.join('') + ((search.length > 0) ? `?${search.join('?')}` : '')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue