2018-03-15 11:00:24 +01:00
|
|
|
# Copyright 2017-2018 Xuan Sang LE <xsang.le AT gmail DOT com>
|
|
|
|
|
|
|
|
# AnTOS Web desktop is is licensed under the GNU General Public
|
|
|
|
# License v3.0, see the LICENCE file for more information
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of
|
|
|
|
# the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
#along with this program. If not, see https://www.gnu.org/licenses/.
|
|
|
|
|
2018-03-09 10:11:15 +01:00
|
|
|
'use strict'
|
2017-08-16 00:27:32 +02:00
|
|
|
#define the OS object
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant = this
|
|
|
|
Ant.OS or=
|
2017-08-16 00:27:32 +02:00
|
|
|
|
2017-08-27 23:40:02 +02:00
|
|
|
API: {}
|
|
|
|
GUI: {}
|
|
|
|
APP: {}
|
|
|
|
setting:
|
|
|
|
user: {}
|
|
|
|
applications: {}
|
2018-01-26 18:57:28 +01:00
|
|
|
desktop: {}
|
2017-08-27 23:40:02 +02:00
|
|
|
appearance: {}
|
2018-01-28 02:01:21 +01:00
|
|
|
VFS: {}
|
2018-01-29 19:16:29 +01:00
|
|
|
system: {}
|
2017-08-24 01:53:13 +02:00
|
|
|
register: (name, x) ->
|
2020-02-20 18:28:03 +01:00
|
|
|
if x.type is 3 then Ant.OS.GUI.subwindows[name] = x else Ant.OS.APP[name] = x
|
2017-08-16 00:27:32 +02:00
|
|
|
|
|
|
|
PM:
|
|
|
|
pidalloc: 0
|
2017-08-27 23:40:02 +02:00
|
|
|
processes: {}
|
|
|
|
createProcess: (app, cls, args) ->
|
2018-02-16 18:38:14 +01:00
|
|
|
f = () ->
|
|
|
|
#if it is single ton
|
|
|
|
# and a process is existing
|
|
|
|
# just return it
|
2020-02-20 18:28:03 +01:00
|
|
|
if cls.singleton and Ant.OS.PM.processes[app] and Ant.OS.PM.processes[app].length == 1
|
|
|
|
Ant.OS.PM.processes[app][0].show()
|
2018-02-16 18:38:14 +01:00
|
|
|
else
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.PM.processes[app] = [] if not Ant.OS.PM.processes[app]
|
2018-02-16 18:38:14 +01:00
|
|
|
obj = new cls(args)
|
|
|
|
obj.birth = (new Date).getTime()
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.PM.pidalloc++
|
|
|
|
obj.pid = Ant.OS.PM.pidalloc
|
|
|
|
Ant.OS.PM.processes[app].push obj
|
|
|
|
if cls.type is 1 then Ant.OS.GUI.dock obj, cls.meta else Ant.OS.GUI.attachservice obj
|
2018-02-16 18:38:14 +01:00
|
|
|
if cls.type is 2
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.announcer.trigger "srvroutineready", app
|
2018-02-16 18:38:14 +01:00
|
|
|
if cls.dependencies
|
|
|
|
libs = (v for v in cls.dependencies)
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.API.requires libs, f
|
2017-08-16 00:27:32 +02:00
|
|
|
else
|
2018-02-16 18:38:14 +01:00
|
|
|
f()
|
2017-08-16 00:27:32 +02:00
|
|
|
appByPid: (pid) ->
|
|
|
|
app = undefined
|
|
|
|
find = (l) ->
|
|
|
|
return a for a in l when a.pid is pid
|
2020-02-20 18:28:03 +01:00
|
|
|
for k, v of Ant.OS.PM.processes
|
2017-08-16 00:27:32 +02:00
|
|
|
app = find v
|
|
|
|
break if app
|
|
|
|
app
|
|
|
|
|
|
|
|
kill: (app) ->
|
2020-02-20 18:28:03 +01:00
|
|
|
return if not app.name or not Ant.OS.PM.processes[app.name]
|
2017-08-16 00:27:32 +02:00
|
|
|
|
2020-02-20 18:28:03 +01:00
|
|
|
i = Ant.OS.PM.processes[app.name].indexOf app
|
2017-08-16 00:27:32 +02:00
|
|
|
if i >= 0
|
2020-02-20 18:28:03 +01:00
|
|
|
if Ant.OS.APP[app.name].type == 1 then Ant.OS.GUI.undock app else Ant.OS.GUI.detachservice app
|
|
|
|
Ant.OS.announcer.unregister app
|
|
|
|
delete Ant.OS.PM.processes[app.name][i]
|
|
|
|
Ant.OS.PM.processes[app.name].splice i, 1
|
2017-08-27 23:40:02 +02:00
|
|
|
|
2018-03-21 11:21:33 +01:00
|
|
|
killAll: (app, force) ->
|
2020-02-20 18:28:03 +01:00
|
|
|
return unless Ant.OS.PM.processes[app]
|
|
|
|
a.quit(force) for a in Ant.OS.PM.processes[app]
|
2017-08-16 00:27:32 +02:00
|
|
|
|
2018-01-04 11:51:12 +01:00
|
|
|
cleanup: ->
|
2018-02-28 17:18:00 +01:00
|
|
|
console.log "Clean up system"
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.PM.killAll a, true for a, v of Ant.OS.PM.processes
|
|
|
|
Ant.OS.announcer.observable.off("*") if Ant.OS.announcer.observable
|
2018-03-24 00:21:53 +01:00
|
|
|
$(window).off('keydown')
|
2018-03-26 14:21:55 +02:00
|
|
|
($ "#workspace").off("mouseover")
|
2020-02-20 18:28:03 +01:00
|
|
|
delete Ant.OS.announcer.observable
|
2018-01-04 11:51:12 +01:00
|
|
|
($ "#wrapper").empty()
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.GUI.clearTheme()
|
|
|
|
Ant.OS.announcer.observable = riot.observable()
|
|
|
|
Ant.OS.announcer.quota = 0
|
|
|
|
Ant.OS.APP = {}
|
|
|
|
Ant.OS.setting =
|
2018-01-30 14:47:27 +01:00
|
|
|
user: {}
|
|
|
|
applications: {}
|
|
|
|
desktop: {}
|
|
|
|
appearance: {}
|
|
|
|
VFS: {}
|
|
|
|
system: {}
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.PM.processes = {}
|
|
|
|
Ant.OS.PM.pidalloc = 0
|
2018-01-04 11:51:12 +01:00
|
|
|
|
2017-08-16 00:27:32 +02:00
|
|
|
boot: ->
|
2017-08-27 23:40:02 +02:00
|
|
|
#first login
|
2018-02-28 17:18:00 +01:00
|
|
|
console.log "Booting sytem"
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.API.handle.auth (d) ->
|
2017-08-27 23:40:02 +02:00
|
|
|
# in case someone call it more than once :)
|
|
|
|
if d.error
|
|
|
|
# show login screen
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.GUI.login()
|
2017-08-27 23:40:02 +02:00
|
|
|
else
|
|
|
|
# startX :)
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.GUI.startAntOS d.result
|
2018-03-04 12:35:19 +01:00
|
|
|
|
2020-02-20 18:28:03 +01:00
|
|
|
cleanupHandles: {}
|
2018-03-04 12:35:19 +01:00
|
|
|
exit: ->
|
|
|
|
#do clean up first
|
2020-02-20 18:28:03 +01:00
|
|
|
f() for n, f of Ant.OS.cleanupHandles
|
|
|
|
Ant.OS.API.handle.setting (r) ->
|
|
|
|
Ant.OS.cleanup()
|
|
|
|
Ant.OS.API.handle.logout()
|
2018-03-04 12:35:19 +01:00
|
|
|
onexit: (n, f) ->
|
2020-02-20 18:28:03 +01:00
|
|
|
Ant.OS.cleanupHandles[n] = f unless Ant.OS.cleanupHandles[n]
|