gears.cache didn't work this, make the cache manually to stop it from leaking
This commit is contained in:
parent
12b94b52a3
commit
216094d0d5
|
@ -3,7 +3,6 @@ local awful = require("awful")
|
|||
local gobject = require("gears.object")
|
||||
local gtable = require("gears.table")
|
||||
local gtimer = require("gears.timer")
|
||||
local gcache = require("gears.cache")
|
||||
local wibox = require("wibox")
|
||||
local beautiful = require("beautiful")
|
||||
local prompt_widget = require(... .. ".prompt")
|
||||
|
@ -91,7 +90,11 @@ local function scroll(self, dir, page_dir)
|
|||
end
|
||||
end
|
||||
|
||||
local app_widget = gcache.new(function(self, app)
|
||||
local function app_widget(self, app)
|
||||
if self._private.apps_widgets_cache[app.name] then
|
||||
return self._private.apps_widgets_cache[app.name]
|
||||
end
|
||||
|
||||
local widget = nil
|
||||
|
||||
if self.app_template == nil then
|
||||
|
@ -249,8 +252,10 @@ local app_widget = gcache.new(function(self, app)
|
|||
function app:unselect() widget:unselect() end
|
||||
function app:is_selected() widget:is_selected() end
|
||||
|
||||
self._private.apps_widgets_cache[app.name] = widget
|
||||
|
||||
return widget
|
||||
end)
|
||||
end
|
||||
|
||||
local function generate_apps(self)
|
||||
self._private.all_apps = {}
|
||||
|
@ -468,7 +473,7 @@ function app_launcher:refresh()
|
|||
for index, app in ipairs(self._private.matched_apps) do
|
||||
-- Only add widgets that are between this range (part of the current page)
|
||||
if index > min_app_index_to_include and index <= max_app_index_to_include then
|
||||
self:get_grid():add(app_widget:get(self, app))
|
||||
self:get_grid():add(app_widget(self, app))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -486,7 +491,7 @@ function app_launcher:search()
|
|||
self._private.matched_apps = self._private.all_apps
|
||||
for _, matched_app in ipairs(self._private.matched_apps) do
|
||||
if #self:get_grid().children + 1 <= self._private.max_apps_per_page then
|
||||
self:get_grid():add(app_widget:get(self, matched_app))
|
||||
self:get_grid():add(app_widget(self, matched_app))
|
||||
else
|
||||
break
|
||||
end
|
||||
|
@ -500,7 +505,7 @@ function app_launcher:search()
|
|||
table.insert(self._private.matched_apps, app)
|
||||
-- Only add the widgets for apps that are part of the first page
|
||||
if #self:get_grid().children + 1 <= self._private.max_apps_per_page then
|
||||
self:get_grid():add(app_widget:get(self, app))
|
||||
self:get_grid():add(app_widget(self, app))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -581,7 +586,7 @@ function app_launcher:page_forward(dir)
|
|||
for index, app in ipairs(self._private.matched_apps) do
|
||||
-- Only add widgets that are between this range (part of the current page)
|
||||
if index > min_app_index_to_include and index <= max_app_index_to_include then
|
||||
self:get_grid():add(app_widget:get(self, app))
|
||||
self:get_grid():add(app_widget(self, app))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -628,7 +633,7 @@ function app_launcher:page_backward(dir)
|
|||
for index, app in ipairs(self._private.matched_apps) do
|
||||
-- Only add widgets that are between this range (part of the current page)
|
||||
if index > min_app_index_to_include and index <= max_app_index_to_include then
|
||||
self:get_grid():add(app_widget:get(self, app))
|
||||
self:get_grid():add(app_widget(self, app))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -691,7 +696,7 @@ function app_launcher:reset()
|
|||
for index, app in ipairs(self._private.all_apps) do
|
||||
-- Only add the apps that are part of the first page
|
||||
if index <= self._private.apps_per_page then
|
||||
self:get_grid():add(app_widget:get(self, app))
|
||||
self:get_grid():add(app_widget(self, app))
|
||||
else
|
||||
break
|
||||
end
|
||||
|
@ -793,6 +798,7 @@ local function new(args)
|
|||
ret._private.text = ""
|
||||
ret._private.pages_count = 0
|
||||
ret._private.current_page = 1
|
||||
ret._private.apps_widgets_cache = {}
|
||||
ret._private.search_timer = gtimer {
|
||||
timeout = 0.05,
|
||||
call_now = false,
|
||||
|
|
Loading…
Reference in New Issue