mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
Implement unique application instance checks
This commit is contained in:
parent
ef64ca609e
commit
05e32593ec
@ -411,7 +411,16 @@ def relpath(target, base=os.curdir):
|
|||||||
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
|
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
|
||||||
return os.path.join(*rel_list)
|
return os.path.join(*rel_list)
|
||||||
|
|
||||||
_lock_file = None
|
def _clean_lock_file(file):
|
||||||
|
try:
|
||||||
|
file.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
os.remove(file.name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
def singleinstance(name):
|
def singleinstance(name):
|
||||||
'''
|
'''
|
||||||
Return True if no other instance of the application identified by name is running,
|
Return True if no other instance of the application identified by name is running,
|
||||||
@ -435,7 +444,7 @@ def singleinstance(name):
|
|||||||
try:
|
try:
|
||||||
f = open(path, 'w')
|
f = open(path, 'w')
|
||||||
fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
fcntl.lockf(f.fileno(), fcntl.LOCK_EX|fcntl.LOCK_NB)
|
||||||
_lock_file = f
|
atexit.register(_clean_lock_file, f)
|
||||||
return True
|
return True
|
||||||
except IOError:
|
except IOError:
|
||||||
return False
|
return False
|
||||||
|
@ -1016,7 +1016,7 @@ def main(args=sys.argv):
|
|||||||
app = QApplication(args)
|
app = QApplication(args)
|
||||||
QCoreApplication.setOrganizationName(ORG_NAME)
|
QCoreApplication.setOrganizationName(ORG_NAME)
|
||||||
QCoreApplication.setApplicationName(APP_UID)
|
QCoreApplication.setApplicationName(APP_UID)
|
||||||
if not singleinstance('main GUI'):
|
if not singleinstance('mainGUI'):
|
||||||
QMessageBox.critical(None, 'Cannot Start '+__appname__,
|
QMessageBox.critical(None, 'Cannot Start '+__appname__,
|
||||||
'<p>%s is already running.</p>'%__appname__)
|
'<p>%s is already running.</p>'%__appname__)
|
||||||
return 1
|
return 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user