Add minimal prototype
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
7da0915465
commit
040bd20eee
@ -1,3 +1,4 @@
|
|||||||
|
"""
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Unloader - plugin for Falkon
|
# Unloader - plugin for Falkon
|
||||||
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||||
@ -15,17 +16,31 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
"""
|
||||||
import Falkon
|
import Falkon
|
||||||
from PySide2 import QtCore
|
from PySide2 import QtCore
|
||||||
|
from unloader.manager import UnloaderManager
|
||||||
|
|
||||||
|
|
||||||
class UnloaderPlugin(Falkon.PluginInterface, QtCore.QObject):
|
class UnloaderPlugin(Falkon.PluginInterface, QtCore.QObject):
|
||||||
|
manager = None
|
||||||
|
|
||||||
def init(self, state, settingsPath):
|
def init(self, state, settingsPath):
|
||||||
pass
|
self.manager = UnloaderManager(settingsPath)
|
||||||
|
|
||||||
|
plugins = Falkon.MainApplication.instance().plugins()
|
||||||
|
|
||||||
|
plugins.mainWindowCreated.connect(self.manager.onMainWindowCreated)
|
||||||
|
plugins.mainWindowDeleted.connect(self.manager.onMainWindowDeleted)
|
||||||
|
|
||||||
|
if state == Falkon.PluginInterface.LateInitState:
|
||||||
|
for window in Falkon.MainApplication.instance().windows():
|
||||||
|
self.manager.onMainWindowCreated(window)
|
||||||
|
|
||||||
def unload(self):
|
def unload(self):
|
||||||
pass
|
if self.manager:
|
||||||
|
del self.manager
|
||||||
|
self.manager = None
|
||||||
|
|
||||||
def testPlugin(self):
|
def testPlugin(self):
|
||||||
return True
|
return True
|
||||||
|
96
unloader/manager.py
Normal file
96
unloader/manager.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
"""
|
||||||
|
# ============================================================
|
||||||
|
# Unloader - plugin for Falkon
|
||||||
|
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
# ============================================================
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Falkon
|
||||||
|
from PySide2 import QtCore
|
||||||
|
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
|
class UnloaderManager(QtCore.QObject):
|
||||||
|
tabs = None
|
||||||
|
timer = None
|
||||||
|
threshold = None
|
||||||
|
|
||||||
|
def __init__(self, settingsPath, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.tabs = {}
|
||||||
|
self.threshold = 15
|
||||||
|
|
||||||
|
self.timer = QtCore.QTimer(self)
|
||||||
|
self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer)
|
||||||
|
self.timer.setInterval(5000)
|
||||||
|
|
||||||
|
self.timer.timeout.connect(self.onTimeout)
|
||||||
|
|
||||||
|
self.timer.start()
|
||||||
|
|
||||||
|
def onMainWindowCreated(self, window):
|
||||||
|
tabs = window.tabWidget().allTabs()
|
||||||
|
|
||||||
|
for tab in tabs:
|
||||||
|
self.tabs[tab] = 0
|
||||||
|
|
||||||
|
def onCurrentTabChanged(index):
|
||||||
|
tab = window.tabWidget().webTab(index)
|
||||||
|
self.tabs[tab] = 0
|
||||||
|
|
||||||
|
window.tabWidget().currentChanged.connect(onCurrentTabChanged)
|
||||||
|
window.tabWidget().tabInserted.connect(onCurrentTabChanged)
|
||||||
|
window.tabWidget().tabRemoved.connect(self.onTabRemoved)
|
||||||
|
|
||||||
|
def onMainWindowDeleted(self, window):
|
||||||
|
tabs = window.tabWidget().allTabs()
|
||||||
|
|
||||||
|
for tab in tabs:
|
||||||
|
if tab in self.tabs:
|
||||||
|
del self.tabs[tab]
|
||||||
|
|
||||||
|
def onTabRemoved(self, index):
|
||||||
|
self.refreshTabList()
|
||||||
|
|
||||||
|
def onTimeout(self):
|
||||||
|
if not self.tabs:
|
||||||
|
return
|
||||||
|
|
||||||
|
for tab, time in self.tabs.items():
|
||||||
|
if tab.isCurrentTab():
|
||||||
|
continue
|
||||||
|
if not tab.isRestored():
|
||||||
|
self.tabs[tab] = 0
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.tabs[tab] = time + int(self.timer.interval() / 1000)
|
||||||
|
|
||||||
|
if self.threshold:
|
||||||
|
if self.tabs[tab] > self.threshold and tab.isRestored():
|
||||||
|
self.tabs[tab] = 0
|
||||||
|
tab.unload()
|
||||||
|
|
||||||
|
def refreshTabList(self):
|
||||||
|
oldTabs = self.tabs.copy()
|
||||||
|
self.tabs.clear()
|
||||||
|
|
||||||
|
for window in Falkon.MainApplication.instance().windows():
|
||||||
|
winTabs = window.tabWidget().allTabs()
|
||||||
|
|
||||||
|
for tab in winTabs:
|
||||||
|
self.tabs[tab] = oldTabs.get(tab, 0)
|
Loading…
Reference in New Issue
Block a user