优化获取磁盘大小的代码,只显示磁盘名为“Macintosh XX”的磁盘大小
This commit is contained in:
sugood 2022-01-14 23:36:07 +08:00
parent 36f5175b6f
commit b476f72140

View File

@ -177,14 +177,15 @@ end
function getRootVolumes() function getRootVolumes()
local vols = hs.fs.volume.allVolumes() local vols = hs.fs.volume.allVolumes()
local msg = ""
for key, vol in pairs(vols) do for key, vol in pairs(vols) do
local size = vol.NSURLVolumeTotalCapacityKey local size = vol.NSURLVolumeTotalCapacityKey
local free = vol.NSURLVolumeAvailableCapacityKey local free = vol.NSURLVolumeAvailableCapacityKey
local usedSSD = (1-free/size) * 100 local usedSSD = (1-free/size) * 100
-- msg = msg .. (1-free/size) * 100 if ( string.find(vol.NSURLVolumeNameKey,'Macintosh') ~= nil) then
return formatPercent(usedSSD) return formatPercent(usedSSD)
end end
end
return ' 0%'
end end
function formatPercent(percent) function formatPercent(percent)
@ -201,7 +202,6 @@ end
function resetSysInfoMeun() function resetSysInfoMeun()
if(config ~=nil and config[1].showSysInfo == 'on' and menuBarItem:isInMenuBar() == false) then if(config ~=nil and config[1].showSysInfo == 'on' and menuBarItem:isInMenuBar() == false) then
print("重置状态栏")
menuBarItem:delete() menuBarItem:delete()
menuBarItem= hs.menubar.new() menuBarItem= hs.menubar.new()
-- menuBarItem:setTitle("") -- menuBarItem:setTitle("")
@ -215,7 +215,7 @@ function resetSysInfoMeun()
obj.timer = nil obj.timer = nil
end end
-- 第三个参数表示当发生异常情况时,定时器是否继续执行下去 -- 第三个参数表示当发生异常情况时,定时器是否继续执行下去
obj.timer = hs.timer.doEvery(2, scan):start() obj.timer = hs.timer.doEvery(3, scan):start()
else else
menuBarItem:delete() menuBarItem:delete()
end end