mirror of
https://github.com/20kdc/OC-KittenOS.git
synced 2024-11-27 12:58:05 +11:00
More memory improvements
This commit is contained in:
parent
51c417b55c
commit
1338185eea
@ -111,69 +111,76 @@ local function getMonitorSettings(a)
|
|||||||
return w, h, d, t
|
return w, h, d, t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
table.insert(s, k)
|
||||||
|
end
|
||||||
|
return s
|
||||||
|
end,
|
||||||
|
delSetting = function ()
|
||||||
|
neo.ensureType(name, "string")
|
||||||
|
local val = nil
|
||||||
|
if name == "password" or name == "pub.clipboard" then val = "" end
|
||||||
|
settings[name] = val
|
||||||
|
sRattle(name, val)
|
||||||
|
pcall(saveSettings)
|
||||||
|
end,
|
||||||
|
setSetting = function (name, val)
|
||||||
|
neo.ensureType(name, "string")
|
||||||
|
neo.ensureType(val, "string")
|
||||||
|
settings[name] = val
|
||||||
|
-- NOTE: Either a monitor is under application control,
|
||||||
|
-- or it's not under any control.
|
||||||
|
-- Monitor settings are applied on the transition to control.
|
||||||
|
sRattle(name, val)
|
||||||
|
pcall(saveSettings)
|
||||||
|
end,
|
||||||
|
shutdown = function (reboot)
|
||||||
|
neo.ensureType(reboot, "boolean")
|
||||||
|
if shuttingDown then return end
|
||||||
|
shuttingDown = true
|
||||||
|
shutdownMode = reboot
|
||||||
|
local counter = 0
|
||||||
|
neo.scheduleTimer(os.uptime() + 5) -- in case the upcoming code fails in some way
|
||||||
|
for f, v in pairs(targsSD) do
|
||||||
|
counter = counter + 1
|
||||||
|
v("shutdown", reboot, function ()
|
||||||
|
counter = counter - 1
|
||||||
|
if counter == 0 then
|
||||||
|
shutdownFin(shutdownMode)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
if counter == 0 then
|
||||||
|
shutdownFin(shutdownMode)
|
||||||
|
end
|
||||||
|
-- donkonit will shutdown when the timer is hit.
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
donkonitSPProvider(function (pkg, pid, sendSig)
|
donkonitSPProvider(function (pkg, pid, sendSig)
|
||||||
targs[pid] = sendSig
|
targs[pid] = sendSig
|
||||||
return {
|
local n = {
|
||||||
listSettings = function ()
|
|
||||||
local s = {}
|
|
||||||
for k, v in pairs(settings) do
|
|
||||||
table.insert(s, k)
|
|
||||||
end
|
|
||||||
return s
|
|
||||||
end,
|
|
||||||
-- NOTE: REPLICATED IN GB
|
|
||||||
getSetting = function (name)
|
|
||||||
neo.ensureType(name, "string")
|
|
||||||
return settings[name]
|
|
||||||
end,
|
|
||||||
delSetting = function (name)
|
|
||||||
neo.ensureType(name, "string")
|
|
||||||
local val = nil
|
|
||||||
if name == "password" or name == "pub.clipboard" then val = "" end
|
|
||||||
settings[name] = val
|
|
||||||
sRattle(name, val)
|
|
||||||
pcall(saveSettings)
|
|
||||||
end,
|
|
||||||
setSetting = function (name, val)
|
|
||||||
neo.ensureType(name, "string")
|
|
||||||
neo.ensureType(val, "string")
|
|
||||||
settings[name] = val
|
|
||||||
-- NOTE: Either a monitor is under application control,
|
|
||||||
-- or it's not under any control.
|
|
||||||
-- Monitor settings are applied on the transition to control.
|
|
||||||
sRattle(name, val)
|
|
||||||
pcall(saveSettings)
|
|
||||||
end,
|
|
||||||
--
|
|
||||||
registerForShutdownEvent = function ()
|
registerForShutdownEvent = function ()
|
||||||
targsSD[pid] = sendSig
|
targsSD[pid] = sendSig
|
||||||
end,
|
end,
|
||||||
registerSavingThrow = function (st)
|
registerSavingThrow = function (st)
|
||||||
neo.ensureType(st, "function")
|
neo.ensureType(st, "function")
|
||||||
targsST[pid] = st
|
targsST[pid] = st
|
||||||
end,
|
|
||||||
shutdown = function (reboot)
|
|
||||||
neo.ensureType(reboot, "boolean")
|
|
||||||
if shuttingDown then return end
|
|
||||||
shuttingDown = true
|
|
||||||
shutdownMode = reboot
|
|
||||||
local counter = 0
|
|
||||||
neo.scheduleTimer(os.uptime() + 5) -- in case the upcoming code fails in some way
|
|
||||||
for f, v in pairs(targsSD) do
|
|
||||||
counter = counter + 1
|
|
||||||
v("shutdown", reboot, function ()
|
|
||||||
counter = counter - 1
|
|
||||||
if counter == 0 then
|
|
||||||
shutdownFin(shutdownMode)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
if counter == 0 then
|
|
||||||
shutdownFin(shutdownMode)
|
|
||||||
end
|
|
||||||
-- donkonit will shutdown when the timer is hit.
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
return setmetatable(n, {
|
||||||
|
__index = mBase,
|
||||||
|
__metatable = 0
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
donkonitRDProvider(function (pkg, pid, sendSig)
|
donkonitRDProvider(function (pkg, pid, sendSig)
|
||||||
@ -250,6 +257,11 @@ pcall(saveSettings)
|
|||||||
|
|
||||||
glacierDCProvider(function (pkg, pid, sendSig)
|
glacierDCProvider(function (pkg, pid, sendSig)
|
||||||
targsDC[pid] = sendSig
|
targsDC[pid] = sendSig
|
||||||
|
local function sWrap(f)
|
||||||
|
return function (s, ...)
|
||||||
|
return f("pub." .. s, ...)
|
||||||
|
end
|
||||||
|
end
|
||||||
return {
|
return {
|
||||||
getKnownMonitors = function ()
|
getKnownMonitors = function ()
|
||||||
local tbl = {}
|
local tbl = {}
|
||||||
@ -288,25 +300,9 @@ glacierDCProvider(function (pkg, pid, sendSig)
|
|||||||
end,
|
end,
|
||||||
forceRescan = rescanDevs,
|
forceRescan = rescanDevs,
|
||||||
-- NOTE: "pub." prefixed version of functions in sys.manage
|
-- NOTE: "pub." prefixed version of functions in sys.manage
|
||||||
getSetting = function (name)
|
getSetting = sWrap(mBase.getSetting),
|
||||||
neo.ensureType(name, "string")
|
delSetting = sWrap(mBase.delSetting),
|
||||||
return settings["pub." .. name]
|
setSetting = sWrap(mBase.setSetting)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -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"
|
-- 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
|
-- 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 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
|
local targsDH = {} -- data disposal
|
||||||
|
|
||||||
@ -98,8 +97,9 @@ end
|
|||||||
|
|
||||||
donkonitDFProvider(function (pkg, pid, sendSig)
|
donkonitDFProvider(function (pkg, pid, sendSig)
|
||||||
local prefixNS = "data/" .. pkg
|
local prefixNS = "data/" .. pkg
|
||||||
local prefixWS = "data/" .. pkg .. "/"
|
local prefixWS = prefixNS .. "/"
|
||||||
fs.primary.makeDirectory(prefixNS)
|
local fs = rootAccess.primaryDisk
|
||||||
|
fs.makeDirectory(prefixNS)
|
||||||
local openHandles = {}
|
local openHandles = {}
|
||||||
targsDH[pid] = function ()
|
targsDH[pid] = function ()
|
||||||
for k, v in pairs(openHandles) do
|
for k, v in pairs(openHandles) do
|
||||||
@ -117,7 +117,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
|
|||||||
neo.scheduleTimer(0)
|
neo.scheduleTimer(0)
|
||||||
table.insert(todo, function ()
|
table.insert(todo, function ()
|
||||||
-- sys-filedialog is yet another "library to control memory usage".
|
-- 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
|
openHandles[tag] = closer
|
||||||
end)
|
end)
|
||||||
return tag
|
return tag
|
||||||
@ -144,14 +144,14 @@ donkonitDFProvider(function (pkg, pid, sendSig)
|
|||||||
path = prefixNS .. path
|
path = prefixNS .. path
|
||||||
neo.ensurePath(path, prefixWS)
|
neo.ensurePath(path, prefixWS)
|
||||||
if path:sub(#path, #path) ~= "/" then error("Expected / at end") end
|
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,
|
end,
|
||||||
makeDirectory = function (path)
|
makeDirectory = function (path)
|
||||||
neo.ensureType(path, "string")
|
neo.ensureType(path, "string")
|
||||||
path = prefixNS .. path
|
path = prefixNS .. path
|
||||||
neo.ensurePath(path, prefixWS)
|
neo.ensurePath(path, prefixWS)
|
||||||
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
||||||
return fs.primary.makeDirectory(path)
|
return fs.makeDirectory(path)
|
||||||
end,
|
end,
|
||||||
rename = function (path1, path2)
|
rename = function (path1, path2)
|
||||||
neo.ensureType(path1, "string")
|
neo.ensureType(path1, "string")
|
||||||
@ -162,7 +162,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
|
|||||||
neo.ensurePath(path2, prefixWS)
|
neo.ensurePath(path2, prefixWS)
|
||||||
if path:sub(#path1, #path1) == "/" then error("Expected no / at end") end
|
if path:sub(#path1, #path1) == "/" then error("Expected no / at end") end
|
||||||
if path:sub(#path2, #path2) == "/" 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,
|
end,
|
||||||
open = function (path, mode)
|
open = function (path, mode)
|
||||||
neo.ensureType(path, "string")
|
neo.ensureType(path, "string")
|
||||||
@ -170,7 +170,7 @@ donkonitDFProvider(function (pkg, pid, sendSig)
|
|||||||
path = prefixNS .. path
|
path = prefixNS .. path
|
||||||
neo.ensurePath(path, prefixWS)
|
neo.ensurePath(path, prefixWS)
|
||||||
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
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
|
if not fw then return nil, closer end
|
||||||
local oc = fw.close
|
local oc = fw.close
|
||||||
fw.close = function ()
|
fw.close = function ()
|
||||||
@ -185,24 +185,24 @@ donkonitDFProvider(function (pkg, pid, sendSig)
|
|||||||
path = prefixNS .. path
|
path = prefixNS .. path
|
||||||
neo.ensurePath(path, prefixWS)
|
neo.ensurePath(path, prefixWS)
|
||||||
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
||||||
return fs.primary.remove(path)
|
return fs.remove(path)
|
||||||
end,
|
end,
|
||||||
stat = function (path)
|
stat = function (path)
|
||||||
neo.ensureType(path, "string")
|
neo.ensureType(path, "string")
|
||||||
path = prefixNS .. path
|
path = prefixNS .. path
|
||||||
neo.ensurePath(path, prefixWS)
|
neo.ensurePath(path, prefixWS)
|
||||||
if path:sub(#path, #path) == "/" then error("Expected no / at end") end
|
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 {
|
return {
|
||||||
fs.primary.isDirectory(path),
|
fs.isDirectory(path),
|
||||||
fs.primary.size(path),
|
fs.size(path),
|
||||||
fs.primary.lastModified(path)
|
fs.lastModified(path)
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
-- getLabel/setLabel have nothing to do with this
|
-- getLabel/setLabel have nothing to do with this
|
||||||
spaceUsed = fs.primary.spaceUsed,
|
spaceUsed = fs.spaceUsed,
|
||||||
spaceTotal = fs.primary.spaceTotal,
|
spaceTotal = fs.spaceTotal,
|
||||||
isReadOnly = fs.primary.isReadOnly
|
isReadOnly = fs.isReadOnly
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user