mirror of
https://github.com/onyx-and-iris/nvda-voicemeeter.git
synced 2026-03-21 02:09:11 +00:00
add ServerState enum to give is_running return values meaning.
fail faster if nvda isn't running
This commit is contained in:
parent
aae62fa136
commit
2a86c05bea
@ -1,7 +1,14 @@
|
||||
from enum import IntEnum
|
||||
|
||||
from .cdll import libc
|
||||
from .errors import NVDAVMCAPIError
|
||||
|
||||
|
||||
class ServerState(IntEnum):
|
||||
RUNNING = 0
|
||||
UNAVAILABLE = 1722
|
||||
|
||||
|
||||
class CBindings:
|
||||
bind_test_if_running = libc.nvdaController_testIfRunning
|
||||
bind_speak_text = libc.nvdaController_speakText
|
||||
@ -18,7 +25,10 @@ class CBindings:
|
||||
class Nvda(CBindings):
|
||||
@property
|
||||
def is_running(self):
|
||||
return self.call(self.bind_test_if_running) == 0
|
||||
return (
|
||||
self.call(self.bind_test_if_running, ok=(ServerState.RUNNING, ServerState.UNAVAILABLE))
|
||||
== ServerState.RUNNING
|
||||
)
|
||||
|
||||
def speak(self, text):
|
||||
self.call(self.bind_speak_text, text)
|
||||
|
||||
@ -6,6 +6,7 @@ import FreeSimpleGUI as psg
|
||||
|
||||
from . import configuration, models, util
|
||||
from .builder import Builder
|
||||
from .errors import NVDAVMError
|
||||
from .nvda import Nvda
|
||||
from .parser import Parser
|
||||
from .popup import Popup
|
||||
@ -25,6 +26,10 @@ class NVDAVMWindow(psg.Window):
|
||||
self.kind = self.vm.kind
|
||||
self.logger = logger.getChild(type(self).__name__)
|
||||
self.logger.debug(f'loaded with theme: {psg.theme()}')
|
||||
self.nvda = Nvda()
|
||||
if not self.nvda.is_running:
|
||||
self.logger.error('NVDA is not running. Exiting...')
|
||||
raise NVDAVMError('NVDA is not running')
|
||||
self.cache = {
|
||||
'hw_ins': models._make_hardware_ins_cache(self.vm),
|
||||
'hw_outs': models._make_hardware_outs_cache(self.vm),
|
||||
@ -34,7 +39,6 @@ class NVDAVMWindow(psg.Window):
|
||||
'asio': models._make_patch_asio_cache(self.vm),
|
||||
'insert': models._make_patch_insert_cache(self.vm),
|
||||
}
|
||||
self.nvda = Nvda()
|
||||
self.parser = Parser()
|
||||
self.popup = Popup(self)
|
||||
self.builder = Builder(self)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user