mirror of
https://github.com/borgbase/vorta
synced 2025-01-03 13:45:49 +00:00
Ensure only one app instance is running. Fixes #27
This commit is contained in:
parent
3f7249fb44
commit
55ff2b0352
3 changed files with 22 additions and 3 deletions
|
@ -20,7 +20,7 @@ def main():
|
||||||
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
|
sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'))
|
||||||
vorta.models.init_db(sqlite_db)
|
vorta.models.init_db(sqlite_db)
|
||||||
|
|
||||||
app = VortaApp(sys.argv)
|
app = VortaApp(sys.argv, single_app=True)
|
||||||
app.updater = vorta.updater.get_updater()
|
app.updater = vorta.updater.get_updater()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import fcntl
|
||||||
|
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtWidgets import QApplication
|
from PyQt5.QtWidgets import QApplication
|
||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
|
@ -8,6 +12,7 @@
|
||||||
from .borg.create import BorgCreateThread
|
from .borg.create import BorgCreateThread
|
||||||
from .views.main_window import MainWindow
|
from .views.main_window import MainWindow
|
||||||
from .utils import get_asset
|
from .utils import get_asset
|
||||||
|
from vorta.config import SETTINGS_DIR
|
||||||
|
|
||||||
|
|
||||||
class VortaApp(QApplication):
|
class VortaApp(QApplication):
|
||||||
|
@ -23,7 +28,21 @@ class VortaApp(QApplication):
|
||||||
backup_cancelled_event = QtCore.pyqtSignal()
|
backup_cancelled_event = QtCore.pyqtSignal()
|
||||||
backup_log_event = QtCore.pyqtSignal(str)
|
backup_log_event = QtCore.pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args, single_app=False):
|
||||||
|
|
||||||
|
# Ensure only one app instance is running.
|
||||||
|
# From https://stackoverflow.com/questions/220525/
|
||||||
|
# ensure-a-single-instance-of-an-application-in-linux#221159
|
||||||
|
if single_app:
|
||||||
|
pid_file = os.path.join(SETTINGS_DIR, 'vorta.pid')
|
||||||
|
lockfile = open(pid_file, 'w+')
|
||||||
|
try:
|
||||||
|
fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
|
self.lockfile = lockfile
|
||||||
|
except OSError:
|
||||||
|
print('An instance of Vorta is already running.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
super().__init__(args)
|
super().__init__(args)
|
||||||
self.setQuitOnLastWindowClosed(False)
|
self.setQuitOnLastWindowClosed(False)
|
||||||
self.scheduler = VortaScheduler(self)
|
self.scheduler = VortaScheduler(self)
|
||||||
|
|
|
@ -51,7 +51,7 @@ def test_create(app_with_repo, borg_json_output, mocker, qtbot):
|
||||||
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
|
mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result)
|
||||||
|
|
||||||
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
qtbot.mouseClick(main.createStartBtn, QtCore.Qt.LeftButton)
|
||||||
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('INFO: Remote'))
|
qtbot.waitUntil(lambda: main.createProgressText.text().startswith('Backup finished.'))
|
||||||
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled())
|
qtbot.waitUntil(lambda: main.createStartBtn.isEnabled())
|
||||||
assert EventLogModel.select().count() == 1
|
assert EventLogModel.select().count() == 1
|
||||||
assert SnapshotModel.select().count() == 1
|
assert SnapshotModel.select().count() == 1
|
||||||
|
|
Loading…
Reference in a new issue