Merge branch 'reload-mime-types' of https://github.com/page-down/kitty

This commit is contained in:
Kovid Goyal 2023-02-14 09:55:22 +05:30
commit 5219044519
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 11 additions and 2 deletions

View File

@ -52,6 +52,8 @@ Detailed list of changes
- macOS: Fix the window buttons not being hidden after exiting the traditional full screen (:iss:`6009`) - macOS: Fix the window buttons not being hidden after exiting the traditional full screen (:iss:`6009`)
- When reloading configuration, also reload custom MIME types from :file:`mime.types` config file (:pull:`6012`)
0.27.1 [2023-02-07] 0.27.1 [2023-02-07]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -5,10 +5,10 @@ import os
import secrets import secrets
from contextlib import contextmanager from contextlib import contextmanager
from datetime import timedelta from datetime import timedelta
from mimetypes import guess_type
from typing import Generator, Union from typing import Generator, Union
from kitty.fast_data_types import truncate_point_for_length, wcswidth from kitty.fast_data_types import truncate_point_for_length, wcswidth
from kitty.guess_mime_type import guess_type
from ..tui.operations import styled from ..tui.operations import styled
from ..tui.progress import render_progress_bar from ..tui.progress import render_progress_bar
@ -121,7 +121,7 @@ def should_be_compressed(path: str) -> bool:
ext = path.rpartition(os.extsep)[-1].lower() ext = path.rpartition(os.extsep)[-1].lower()
if ext in ('zip', 'odt', 'odp', 'pptx', 'docx', 'gz', 'bz2', 'xz', 'svgz'): if ext in ('zip', 'odt', 'odp', 'pptx', 'docx', 'gz', 'bz2', 'xz', 'svgz'):
return False return False
mt = guess_type(path)[0] or '' mt = guess_type(path) or ''
if mt: if mt:
if mt.endswith('+zip'): if mt.endswith('+zip'):
return False return False

View File

@ -2385,6 +2385,8 @@ class Boss:
self.apply_new_options(opts) self.apply_new_options(opts)
from .open_actions import clear_caches from .open_actions import clear_caches
clear_caches() clear_caches()
from .guess_mime_type import clear_mime_cache
clear_mime_cache()
def safe_delete_temp_file(self, path: str) -> None: def safe_delete_temp_file(self, path: str) -> None:
if is_path_in_temp_dir(path): if is_path_in_temp_dir(path):

View File

@ -60,6 +60,11 @@ def initialize_mime_database() -> None:
init((local_defs,)) init((local_defs,))
def clear_mime_cache() -> None:
if hasattr(initialize_mime_database, 'inited'):
delattr(initialize_mime_database, 'inited')
def guess_type(path: str, allow_filesystem_access: bool = False) -> Optional[str]: def guess_type(path: str, allow_filesystem_access: bool = False) -> Optional[str]:
is_dir = is_exe = False is_dir = is_exe = False