5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

Disable F5 key on windows

This commit is contained in:
Lea Anthony 2020-05-09 05:46:40 +10:00
parent cc99dcce80
commit f1d16a03ec

View File

@ -139,7 +139,7 @@ struct webview_priv
#define DEFAULT_URL \ #define DEFAULT_URL \
"data:text/" \ "data:text/" \
"html,%3C%21DOCTYPE%20html%3E%0A%3Chtml%20lang=%22en%22%3E%0A%3Chead%3E%" \ "html,%3C%21DOCTYPE%20html%3E%0A%3Chtml%20lang=%22en%22%3E%0A%3Chead%3E%" \
"3Cmeta%20charset=%22utf-8%22%3E%3Cmeta%20http-equiv=%22IE=edge%22%" \ "3Cmeta%20charset=%22utf-8%22%3E%3Cmeta%20http-equiv=%22IE=edge%22%" \
"20content=%22IE=edge%22%3E%3C%2Fhead%3E%0A%3Cbody%3E%3Cdiv%20id=%22app%22%" \ "20content=%22IE=edge%22%3E%3C%2Fhead%3E%0A%3Cbody%3E%3Cdiv%20id=%22app%22%" \
"3E%3C%2Fdiv%3E%3Cscript%20type=%22text%2Fjavascript%22%3E%3C%2Fscript%3E%" \ "3E%3C%2Fdiv%3E%3Cscript%20type=%22text%2Fjavascript%22%3E%3C%2Fscript%3E%" \
"3C%2Fbody%3E%0A%3C%2Fhtml%3E" "3C%2Fbody%3E%0A%3C%2Fhtml%3E"
@ -1227,7 +1227,7 @@ struct webview_priv
} }
VariantInit(&myURL); VariantInit(&myURL);
myURL.vt = VT_BSTR; myURL.vt = VT_BSTR;
// #ifndef UNICODE // #ifndef UNICODE
{ {
wchar_t *buffer = webview_to_utf16(webPageName); wchar_t *buffer = webview_to_utf16(webPageName);
if (buffer == NULL) if (buffer == NULL)
@ -1237,9 +1237,9 @@ struct webview_priv
myURL.bstrVal = SysAllocString(buffer); myURL.bstrVal = SysAllocString(buffer);
GlobalFree(buffer); GlobalFree(buffer);
} }
// #else // #else
// myURL.bstrVal = SysAllocString(webPageName); // myURL.bstrVal = SysAllocString(webPageName);
// #endif // #endif
if (!myURL.bstrVal) if (!myURL.bstrVal)
{ {
badalloc: badalloc:
@ -1277,7 +1277,7 @@ struct webview_priv
if (!SafeArrayAccessData(sfArray, (void **)&pVar)) if (!SafeArrayAccessData(sfArray, (void **)&pVar))
{ {
pVar->vt = VT_BSTR; pVar->vt = VT_BSTR;
// #ifndef UNICODE // #ifndef UNICODE
{ {
wchar_t *buffer = webview_to_utf16(url); wchar_t *buffer = webview_to_utf16(url);
if (buffer == NULL) if (buffer == NULL)
@ -1287,9 +1287,9 @@ struct webview_priv
bstr = SysAllocString(buffer); bstr = SysAllocString(buffer);
GlobalFree(buffer); GlobalFree(buffer);
} }
// #else // #else
// bstr = SysAllocString(url); // bstr = SysAllocString(url);
// #endif // #endif
if ((pVar->bstrVal = bstr)) if ((pVar->bstrVal = bstr))
{ {
htmlDoc2->lpVtbl->write(htmlDoc2, sfArray); htmlDoc2->lpVtbl->write(htmlDoc2, sfArray);
@ -1444,12 +1444,12 @@ struct webview_priv
rect.right - rect.left, rect.bottom - rect.top, rect.right - rect.left, rect.bottom - rect.top,
HWND_DESKTOP, NULL, hInstance, (void *)w); HWND_DESKTOP, NULL, hInstance, (void *)w);
#else #else
w->priv.hwnd = w->priv.hwnd =
CreateWindowEx(0, classname, w->title, style, rect.left, rect.top, CreateWindowEx(0, classname, w->title, style, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top, rect.right - rect.left, rect.bottom - rect.top,
HWND_DESKTOP, NULL, hInstance, (void *)w); HWND_DESKTOP, NULL, hInstance, (void *)w);
#endif #endif
if (w->priv.hwnd == 0) if (w->priv.hwnd == 0)
{ {
OleUninitialize(); OleUninitialize();
@ -1466,8 +1466,7 @@ struct webview_priv
#else #else
SetWindowText(w->priv.hwnd, w->title); SetWindowText(w->priv.hwnd, w->title);
#endif #endif
ShowWindow(w->priv.hwnd, SW_SHOWDEFAULT); ShowWindow(w->priv.hwnd, SW_SHOWDEFAULT);
UpdateWindow(w->priv.hwnd); UpdateWindow(w->priv.hwnd);
SetFocus(w->priv.hwnd); SetFocus(w->priv.hwnd);
@ -1494,6 +1493,11 @@ struct webview_priv
case WM_KEYDOWN: case WM_KEYDOWN:
case WM_KEYUP: case WM_KEYUP:
{ {
// Disable refresh when pressing F5 on windows
if (msg.wParam == VK_F5)
{
break;
}
HRESULT r = S_OK; HRESULT r = S_OK;
IWebBrowser2 *webBrowser2; IWebBrowser2 *webBrowser2;
IOleObject *browser = *w->priv.browser; IOleObject *browser = *w->priv.browser;
@ -1603,7 +1607,7 @@ struct webview_priv
WEBVIEW_API void webview_set_title(struct webview *w, const char *title) WEBVIEW_API void webview_set_title(struct webview *w, const char *title)
{ {
#ifdef UNICODE #ifdef UNICODE
wchar_t *u16title = webview_to_utf16(title); wchar_t *u16title = webview_to_utf16(title);
if (u16title == NULL) if (u16title == NULL)
{ {
@ -1611,12 +1615,11 @@ struct webview_priv
} }
SetWindowText(w->priv.hwnd, u16title); SetWindowText(w->priv.hwnd, u16title);
GlobalFree(u16title); GlobalFree(u16title);
#else #else
SetWindowText(w->priv.hwnd, title); SetWindowText(w->priv.hwnd, title);
#endif #endif
} }
WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen) WEBVIEW_API void webview_set_fullscreen(struct webview *w, int fullscreen)
{ {
if (w->priv.is_fullscreen == !!fullscreen) if (w->priv.is_fullscreen == !!fullscreen)
@ -1927,22 +1930,25 @@ struct webview_priv
[script setValue:self forKey:@"external"]; [script setValue:self forKey:@"external"];
} }
static void webview_run_input_open_panel(id self, SEL cmd, id webview, static void webview_run_input_open_panel(id self, SEL cmd, id webview,
id listener, BOOL allowMultiple) { id listener, BOOL allowMultiple)
{
char filename[256] = ""; char filename[256] = "";
struct webview *w = struct webview *w =
(struct webview *)objc_getAssociatedObject(self, "webview"); (struct webview *)objc_getAssociatedObject(self, "webview");
webview_dialog(w, WEBVIEW_DIALOG_TYPE_OPEN, WEBVIEW_DIALOG_FLAG_FILE, "", "", webview_dialog(w, WEBVIEW_DIALOG_TYPE_OPEN, WEBVIEW_DIALOG_FLAG_FILE, "", "",
filename, 255); filename, 255);
if (strlen(filename)) { if (strlen(filename))
{
[listener chooseFilename:[NSString stringWithUTF8String:filename]]; [listener chooseFilename:[NSString stringWithUTF8String:filename]];
} else { }
else
{
[listener cancel]; [listener cancel];
} }
} }
static void webview_external_invoke(id self, SEL cmd, id arg) static void webview_external_invoke(id self, SEL cmd, id arg)
{ {
struct webview *w = struct webview *w =
@ -1955,7 +1961,7 @@ static void webview_run_input_open_panel(id self, SEL cmd, id webview,
{ {
return; return;
} }
w->external_invoke_cb(w, [(NSString *)(arg)UTF8String]); w->external_invoke_cb(w, [(NSString *)(arg) UTF8String]);
} }
WEBVIEW_API int webview_init(struct webview *w) WEBVIEW_API int webview_init(struct webview *w)