1
0
mirror of https://github.com/20kdc/OC-KittenOS.git synced 2024-11-23 10:58:06 +11:00

More memory improvements

This commit is contained in:
20kdc 2018-04-26 17:38:33 +01:00
parent 51c417b55c
commit 1338185eea
2 changed files with 86 additions and 90 deletions

View File

@ -111,9 +111,13 @@ local function getMonitorSettings(a)
return w, h, d, t
end
donkonitSPProvider(function (pkg, pid, sendSig)
targs[pid] = sendSig
return {
-- Settings API
local mBase = {
getSetting = function (name)
neo.ensureType(name, "string")
return settings[name]
end,
listSettings = function ()
local s = {}
for k, v in pairs(settings) do
@ -121,12 +125,7 @@ donkonitSPProvider(function (pkg, pid, sendSig)
end
return s
end,
-- NOTE: REPLICATED IN GB
getSetting = function (name)
neo.ensureType(name, "string")
return settings[name]
end,
delSetting = function (name)
delSetting = function ()
neo.ensureType(name, "string")
local val = nil
if name == "password" or name == "pub.clipboard" then val = "" end
@ -144,14 +143,6 @@ donkonitSPProvider(function (pkg, pid, sendSig)
sRattle(name, val)
pcall(saveSettings)
end,
--
registerForShutdownEvent = function ()
targsSD[pid] = sendSig
end,
registerSavingThrow = function (st)
neo.ensureType(st, "function")
targsST[pid] = st
end,
shutdown = function (reboot)
neo.ensureType(reboot, "boolean")
if shuttingDown then return end
@ -174,6 +165,22 @@ donkonitSPProvider(function (pkg, pid, sendSig)
-- donkonit will shutdown when the timer is hit.
end
}
donkonitSPProvider(function (pkg, pid, sendSig)
targs[pid] = sendSig
local n = {
registerForShutdownEvent = function ()
targsSD[pid] = sendSig
end,
registerSavingThrow = function (st)
neo.ensureType(st, "function")
targsST[pid] = st
end
}
return setmetatable(n, {
__index = mBase,
__metatable = 0
})
end)
donkonitRDProvider(function (pkg, pid, sendSig)
@ -250,6 +257,11 @@ pcall(saveSettings)
glacierDCProvider(function (pkg, pid, sendSig)
targsDC[pid] = sendSig
local function sWrap(f)
return function (s, ...)
return f("pub." .. s, ...)
end
end
return {
getKnownMonitors = function ()
local tbl = {}
@ -288,25 +300,9 @@ glacierDCProvider(function (pkg, pid, sendSig)
end,
forceRescan = rescanDevs,
-- NOTE: "pub." prefixed version of functions in sys.manage
getSetting = function (name)
neo.ensureType(name, "string")
return settings["pub." .. name]
end,
delSetting = function (name)
neo.ensureType(name, "string")
local val = nil
if name == "clipboard" then val = "" end
settings["pub." .. name] = val
sRattle("pub." .. name, val)
pcall(saveSettings)
end,
setSetting = function (name, val)
neo.ensureType(name, "string")
neo.ensureType(val, "string")
settings["pub." .. name] = val
sRattle("pub." .. name, val)
pcall(saveSettings)
end
getSetting = sWrap(mBase.getSetting),
delSetting = sWrap(mBase.delSetting),
setSetting = sWrap(mBase.setSetting)
}
end)

View File

@ -4,10 +4,9 @@
-- s-icecap : Responsible for x.neo.pub API, crash dialogs, and security policy that isn't "sys- has ALL access, anything else has none"
-- In general, this is what userspace will be interacting with in some way or another to get stuff done
local settings = neo.requireAccess("x.neo.sys.manage", "security sysconf access")
local fs = neo.requireAccess("c.filesystem", "file managers")
local donkonitDFProvider = neo.requireAccess("r.neo.pub.base", "creating basic NEO APIs")
local rootAccess = neo.requireAccess("k.root", "installing GUI integration")
local settings = neo.requireAccess("x.neo.sys.manage", "security sysconf access")
local donkonitDFProvider = neo.requireAccess("r.neo.pub.base", "creating basic NEO APIs")
local targsDH = {} -- data disposal
@ -98,8 +97,9 @@ end
donkonitDFProvider(function (pkg, pid, sendSig)
local prefixNS = "data/" .. pkg
local prefixWS = "data/" .. pkg .. "/"
fs.primary.makeDirectory(prefixNS)
local prefixWS = prefixNS .. "/"
local fs = rootAccess.primaryDisk
fs.makeDirectory(prefixNS)
local openHandles = {}
targsDH[pid] = function ()
for k, v in pairs(openHandles) do
@ -117,7 +117,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
neo.scheduleTimer(0)
table.insert(todo, function ()
-- sys-filedialog is yet another "library to control memory usage".
local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, fs, pkg, forWrite)
local closer = require("sys-filedialog")(event, nexus, function (res) openHandles[tag] = nil sendSig("filedialog", tag, res) end, neo.requireAccess("c.filesystem", "file managers"), pkg, forWrite)
openHandles[tag] = closer
end)
return tag
@ -144,14 +144,14 @@ donkonitDFProvider(function (pkg, pid, sendSig)
path = prefixNS .. path
neo.ensurePath(path, prefixWS)
if path:sub(#path, #path) ~= "/" then error("Expected / at end") end
return fs.primary.list(path:sub(1, #path - 1))
return fs.list(path:sub(1, #path - 1))
end,
makeDirectory = function (path)
neo.ensureType(path, "string")
path = prefixNS .. path
neo.ensurePath(path, prefixWS)
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
return fs.primary.makeDirectory(path)
return fs.makeDirectory(path)
end,
rename = function (path1, path2)
neo.ensureType(path1, "string")
@ -162,7 +162,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
neo.ensurePath(path2, prefixWS)
if path:sub(#path1, #path1) == "/" then error("Expected no / at end") end
if path:sub(#path2, #path2) == "/" then error("Expected no / at end") end
return fs.primary.rename(path1, path2)
return fs.rename(path1, path2)
end,
open = function (path, mode)
neo.ensureType(path, "string")
@ -170,7 +170,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
path = prefixNS .. path
neo.ensurePath(path, prefixWS)
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
local fw, closer = require("sys-filewrap").create(fs.primary, path, mode)
local fw, closer = require("sys-filewrap").create(fs, path, mode)
if not fw then return nil, closer end
local oc = fw.close
fw.close = function ()
@ -185,24 +185,24 @@ donkonitDFProvider(function (pkg, pid, sendSig)
path = prefixNS .. path
neo.ensurePath(path, prefixWS)
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
return fs.primary.remove(path)
return fs.remove(path)
end,
stat = function (path)
neo.ensureType(path, "string")
path = prefixNS .. path
neo.ensurePath(path, prefixWS)
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
if not fs.primary.exists(path) then return nil end
if not fs.exists(path) then return nil end
return {
fs.primary.isDirectory(path),
fs.primary.size(path),
fs.primary.lastModified(path)
fs.isDirectory(path),
fs.size(path),
fs.lastModified(path)
}
end,
-- getLabel/setLabel have nothing to do with this
spaceUsed = fs.primary.spaceUsed,
spaceTotal = fs.primary.spaceTotal,
isReadOnly = fs.primary.isReadOnly
spaceUsed = fs.spaceUsed,
spaceTotal = fs.spaceTotal,
isReadOnly = fs.isReadOnly
}
end)