mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 18:48:24 +00:00
Fallback to default open cmd
This commit is contained in:
parent
7307c80d33
commit
038b5a091a
3 changed files with 17 additions and 19 deletions
|
@ -46,9 +46,9 @@ else:
|
||||||
DEFAULT_OPEN = "open '{file_path}'"
|
DEFAULT_OPEN = "open '{file_path}'"
|
||||||
|
|
||||||
if _os_name == _linux:
|
if _os_name == _linux:
|
||||||
DEFAULT_COPY = "xclip -selection c"
|
COPY_CMD = "xclip -selection c"
|
||||||
else:
|
else:
|
||||||
DEFAULT_COPY = "pbcopy"
|
COPY_CMD = "pbcopy"
|
||||||
|
|
||||||
|
|
||||||
if os.path.isfile(DEFAULT_CONFIG):
|
if os.path.isfile(DEFAULT_CONFIG):
|
||||||
|
|
|
@ -46,7 +46,6 @@ class Controller:
|
||||||
self.model = model
|
self.model = model
|
||||||
self.view = view
|
self.view = view
|
||||||
self.render_lock = threading.Lock()
|
self.render_lock = threading.Lock()
|
||||||
self.render_msgs_lock = threading.Lock()
|
|
||||||
self.tg = tg
|
self.tg = tg
|
||||||
self.chat_size = 0.5
|
self.chat_size = 0.5
|
||||||
|
|
||||||
|
@ -431,18 +430,17 @@ class Controller:
|
||||||
self.view.status.draw()
|
self.view.status.draw()
|
||||||
|
|
||||||
def render_msgs(self) -> None:
|
def render_msgs(self) -> None:
|
||||||
with self.render_msgs_lock:
|
current_msg_idx = self.model.get_current_chat_msg_idx()
|
||||||
current_msg_idx = self.model.get_current_chat_msg_idx()
|
if current_msg_idx is None:
|
||||||
if current_msg_idx is None:
|
return
|
||||||
return
|
msgs = self.model.fetch_msgs(
|
||||||
msgs = self.model.fetch_msgs(
|
current_position=current_msg_idx,
|
||||||
current_position=current_msg_idx,
|
page_size=self.view.msgs.h,
|
||||||
page_size=self.view.msgs.h,
|
msgs_left_scroll_threshold=MSGS_LEFT_SCROLL_THRESHOLD,
|
||||||
msgs_left_scroll_threshold=MSGS_LEFT_SCROLL_THRESHOLD,
|
)
|
||||||
)
|
self.view.msgs.draw(
|
||||||
self.view.msgs.draw(
|
current_msg_idx, msgs, MSGS_LEFT_SCROLL_THRESHOLD
|
||||||
current_msg_idx, msgs, MSGS_LEFT_SCROLL_THRESHOLD
|
)
|
||||||
)
|
|
||||||
|
|
||||||
def _notify_for_message(self, chat_id: int, msg: MsgProxy):
|
def _notify_for_message(self, chat_id: int, msg: MsgProxy):
|
||||||
# do not notify, if muted
|
# do not notify, if muted
|
||||||
|
|
|
@ -32,14 +32,14 @@ emoji_pattern = re.compile(
|
||||||
units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12}
|
units = {"B": 1, "KB": 10 ** 3, "MB": 10 ** 6, "GB": 10 ** 9, "TB": 10 ** 12}
|
||||||
|
|
||||||
|
|
||||||
def get_file_handler(file_name, default=None):
|
def get_file_handler(file_path, default=None):
|
||||||
mtype, _ = mimetypes.guess_type(file_name)
|
mtype, _ = mimetypes.guess_type(file_path)
|
||||||
if not mtype:
|
if not mtype:
|
||||||
return default
|
return default
|
||||||
caps = mailcap.getcaps()
|
caps = mailcap.getcaps()
|
||||||
handler, view = mailcap.findmatch(caps, mtype, filename=file_name)
|
handler, view = mailcap.findmatch(caps, mtype, filename=file_path)
|
||||||
if not handler:
|
if not handler:
|
||||||
return None
|
return config.DEFAULT_OPEN.format(file_path=file_path)
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue