mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-27 15:44:12 +08:00
dark
This commit is contained in:
parent
7fec150cca
commit
fa22e9e0a3
@ -9,7 +9,6 @@ from gui.usefulwidget import (
|
||||
D_getspinbox,
|
||||
D_getcolorbutton,
|
||||
getcolorbutton,
|
||||
D_getsimpleswitch,
|
||||
selectcolor,
|
||||
)
|
||||
|
||||
@ -316,9 +315,9 @@ def uisetting(self):
|
||||
("明暗", 4),
|
||||
(
|
||||
D_getsimplecombobox(
|
||||
_TRL(["明亮", "黑暗", "跟随系统"]),
|
||||
_TRL(["跟随系统", "明亮", "黑暗"]),
|
||||
globalconfig,
|
||||
"darklight",
|
||||
"darklight2",
|
||||
lambda _: gobject.baseobject.setcommonstylesheet(),
|
||||
),
|
||||
5,
|
||||
|
@ -683,6 +683,11 @@ class WebivewWidget(abstractwebview):
|
||||
self.__token,
|
||||
)
|
||||
|
||||
def get_controller(self):
|
||||
return self.webview.get_native_handle(
|
||||
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER
|
||||
)
|
||||
|
||||
def __init__(self, parent=None, debug=False) -> None:
|
||||
super().__init__(parent)
|
||||
declare_library_path(
|
||||
@ -700,25 +705,31 @@ class WebivewWidget(abstractwebview):
|
||||
self.on_ZoomFactorChanged.emit
|
||||
)
|
||||
self.__token = winsharedutils.add_ZoomFactorChanged(
|
||||
self.webview.get_native_handle(
|
||||
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER
|
||||
),
|
||||
zoomfunc,
|
||||
self.get_controller(), zoomfunc
|
||||
)
|
||||
self.keepref = [zoomfunc]
|
||||
self.webview.bind("__on_load", self._on_load)
|
||||
self.webview.init("""window.__on_load(window.location.href)""")
|
||||
|
||||
self.__darkstate = None
|
||||
t = QTimer(self)
|
||||
t.setInterval(100)
|
||||
t.timeout.connect(self.__darkstatechecker)
|
||||
t.timeout.emit()
|
||||
t.start()
|
||||
|
||||
def __darkstatechecker(self):
|
||||
dl = globalconfig["darklight2"]
|
||||
if dl == self.__darkstate:
|
||||
return
|
||||
self.__darkstate = dl
|
||||
winsharedutils.put_PreferredColorScheme(self.get_controller(), dl)
|
||||
|
||||
def set_zoom(self, zoom):
|
||||
self.put_ZoomFactor(zoom)
|
||||
|
||||
def put_ZoomFactor(self, zoom):
|
||||
winsharedutils.put_ZoomFactor(
|
||||
self.webview.get_native_handle(
|
||||
webview_native_handle_kind_t.WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER
|
||||
),
|
||||
zoom,
|
||||
)
|
||||
winsharedutils.put_ZoomFactor(self.get_controller(), zoom)
|
||||
|
||||
def _on_load(self, href):
|
||||
self.on_load.emit(href)
|
||||
|
@ -84,12 +84,12 @@ def simplehtmlparser(text, tag, sign):
|
||||
|
||||
|
||||
def nowisdark():
|
||||
dl = globalconfig["darklight"]
|
||||
if dl == 0:
|
||||
dl = globalconfig["darklight2"]
|
||||
if dl == 1:
|
||||
dark = False
|
||||
elif dl == 1:
|
||||
dark = True
|
||||
elif dl == 2:
|
||||
dark = True
|
||||
elif dl == 0:
|
||||
dark = winsharedutils.isDark()
|
||||
return dark
|
||||
|
||||
|
@ -20,6 +20,7 @@ from ctypes import (
|
||||
c_double,
|
||||
c_char,
|
||||
CFUNCTYPE,
|
||||
c_long,
|
||||
)
|
||||
from ctypes.wintypes import WORD, HANDLE, HWND, LONG, DWORD, RECT, BYTE
|
||||
from windows import WINDOWPLACEMENT
|
||||
@ -409,6 +410,9 @@ get_ZoomFactor.argtypes = (c_void_p,)
|
||||
get_ZoomFactor.restype = c_double
|
||||
put_ZoomFactor = utilsdll.put_ZoomFactor
|
||||
put_ZoomFactor.argtypes = c_void_p, c_double
|
||||
put_PreferredColorScheme = utilsdll.put_PreferredColorScheme
|
||||
put_PreferredColorScheme.argtypes = c_void_p, c_int
|
||||
put_PreferredColorScheme.restype = c_long
|
||||
|
||||
clipboard_callback = utilsdll.clipboard_callback
|
||||
clipboard_callback.argtypes = (c_void_p,)
|
||||
|
@ -1192,7 +1192,7 @@
|
||||
"type": "offline"
|
||||
}
|
||||
},
|
||||
"darklight": 0,
|
||||
"darklight2": 0,
|
||||
"darktheme": 0,
|
||||
"lighttheme": 0,
|
||||
"usesearchword": false,
|
||||
|
@ -11,7 +11,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/wil/include)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/miniaudio)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/tinymp3)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/webview2/Microsoft.Web.WebView2.1.0.1150.38/build/native/include)
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR}/webview2/Microsoft.Web.WebView2.1.0.2478.35/build/native/include)
|
||||
|
||||
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
|
||||
set(LTLPlatform "Win32")
|
||||
|
@ -1,4 +1,4 @@
|
||||
mswebview2_version = "1.0.1150.38"
|
||||
mswebview2_version = "1.0.2478.35"
|
||||
|
||||
import os, subprocess
|
||||
|
||||
|
@ -7,10 +7,27 @@
|
||||
#include <wrl/implements.h>
|
||||
using namespace Microsoft::WRL;
|
||||
#include <WebView2.h>
|
||||
#define CHECK_FAILURE(x) \
|
||||
if (FAILED((x))) \
|
||||
return x;
|
||||
|
||||
DECLARE void *add_ZoomFactorChanged(void *m_host, void (*signal)(double))
|
||||
DECLARE HRESULT put_PreferredColorScheme(void *m_host, COREWEBVIEW2_PREFERRED_COLOR_SCHEME scheme)
|
||||
{
|
||||
|
||||
wil::com_ptr<ICoreWebView2Controller> m_controller(reinterpret_cast<ICoreWebView2Controller *>(m_host));
|
||||
wil::com_ptr<ICoreWebView2> coreWebView2;
|
||||
CHECK_FAILURE(m_controller->get_CoreWebView2(&coreWebView2));
|
||||
auto webView2_13 = coreWebView2.try_query<ICoreWebView2_13>();
|
||||
if (webView2_13)
|
||||
{
|
||||
wil::com_ptr<ICoreWebView2Profile> profile;
|
||||
CHECK_FAILURE(webView2_13->get_Profile(&profile));
|
||||
CHECK_FAILURE(profile->put_PreferredColorScheme(scheme));
|
||||
}
|
||||
return S_FALSE;
|
||||
}
|
||||
DECLARE void *add_ZoomFactorChanged(void *m_host, void (*signal)(double))
|
||||
{
|
||||
EventRegistrationToken *m_zoomFactorChangedToken = new EventRegistrationToken;
|
||||
// Register a handler for the ZoomFactorChanged event.
|
||||
// This handler just announces the new level of zoom on the window's title bar.
|
||||
|
Loading…
x
Reference in New Issue
Block a user