mirror of https://gitlab.com/openlp/openlp.git
Merge branch 'issue-1200' into 'master'
Silence any errors from the LibreOffice shutdown on macOS Closes #1200 See merge request openlp/openlp!505
This commit is contained in:
commit
ef1e5685b2
|
@ -180,23 +180,24 @@ class LibreOfficeServer(object):
|
|||
if hasattr(self, '_docs'):
|
||||
while self._docs:
|
||||
self._docs[0].close_presentation()
|
||||
docs = self.desktop.getComponents()
|
||||
count = 0
|
||||
if docs.hasElements():
|
||||
list_elements = docs.createEnumeration()
|
||||
while list_elements.hasMoreElements():
|
||||
doc = list_elements.nextElement()
|
||||
if doc.getImplementationName() != 'com.sun.star.comp.framework.BackingComp':
|
||||
count += 1
|
||||
if count > 0:
|
||||
log.debug('LibreOffice not terminated as docs are still open')
|
||||
can_kill = False
|
||||
else:
|
||||
try:
|
||||
self.desktop.terminate()
|
||||
log.debug('LibreOffice killed')
|
||||
except Exception:
|
||||
log.exception('Failed to terminate LibreOffice')
|
||||
if self.desktop:
|
||||
docs = self.desktop.getComponents()
|
||||
count = 0
|
||||
if docs.hasElements():
|
||||
list_elements = docs.createEnumeration()
|
||||
while list_elements.hasMoreElements():
|
||||
doc = list_elements.nextElement()
|
||||
if doc.getImplementationName() != 'com.sun.star.comp.framework.BackingComp':
|
||||
count += 1
|
||||
if count > 0:
|
||||
log.debug('LibreOffice not terminated as docs are still open')
|
||||
can_kill = False
|
||||
else:
|
||||
try:
|
||||
self.desktop.terminate()
|
||||
log.debug('LibreOffice killed')
|
||||
except Exception:
|
||||
log.exception('Failed to terminate LibreOffice')
|
||||
if getattr(self, '_process') and can_kill:
|
||||
self._process.kill()
|
||||
|
||||
|
|
|
@ -114,7 +114,12 @@ class MacLOController(PresentationController, LogMixin):
|
|||
Called at system exit to clean up any running presentations.
|
||||
"""
|
||||
log.debug('Kill LibreOffice')
|
||||
self.client.shutdown()
|
||||
try:
|
||||
# Some people like to close LibreOffice themselves, let's just catch any errors so that OpenLP fails
|
||||
# silently
|
||||
self.client.shutdown()
|
||||
except Exception:
|
||||
pass
|
||||
self.server_process.kill()
|
||||
|
||||
|
||||
|
|
|
@ -159,6 +159,23 @@ class TestMacLOController(TestCase, TestMixin):
|
|||
controller._client.shutdown.assert_called_once_with()
|
||||
controller.server_process.kill.assert_called_once_with()
|
||||
|
||||
@patch('openlp.plugins.presentations.lib.maclocontroller.MacLOController._start_server')
|
||||
def test_kill_client_already_closed(self, mocked_start_server):
|
||||
"""
|
||||
Test the kill() method when the client is already closed
|
||||
"""
|
||||
# GIVEN: A controller and a client
|
||||
controller = MacLOController(plugin=self.mock_plugin)
|
||||
controller._client = MagicMock(**{'shutdown.side_effect': Exception})
|
||||
controller.server_process = MagicMock()
|
||||
|
||||
# WHEN: start_process() is called
|
||||
controller.kill()
|
||||
|
||||
# THEN: The client's start_process() should have been called
|
||||
controller._client.shutdown.assert_called_once_with()
|
||||
controller.server_process.kill.assert_called_once_with()
|
||||
|
||||
|
||||
class TestMacLODocument(TestCase):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue