Skip to content

Commit

Permalink
add entryType property to Webview
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Aug 16, 2024
1 parent 2c8f29f commit 9a68ead
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
9 changes: 3 additions & 6 deletions src/crowngui.nim
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@

import os, strutils, crowngui / [webview, net_utils]
import os, strutils, crowngui / [webview, net_utils, types]
import static_server, mimetypes, asyncdispatch
import finder

export webview

type
EntryType = enum
url, file, html, dir
Application* = object
entry: string
entryType: EntryType
Expand Down Expand Up @@ -50,7 +47,7 @@ proc newApplication*(entry: static[string]): ApplicationRef =
const url = entry
EntryType.file
else:
const url = dataUriHtmlHeader entry.strip
const url = entry.strip
EntryType.html
when defined(bundle):
const data = staticRead bundle
Expand All @@ -60,7 +57,7 @@ proc newApplication*(entry: static[string]): ApplicationRef =
when defined(bundle):
port = findAvailablePort()
let url = "http://localhost:" & $port
result.webview = newWebView(url)
result.webview = newWebView(url, entryType)
when defined(bundle):
result.webview.url = url

Expand Down
2 changes: 2 additions & 0 deletions src/crowngui/platforms/win/webview2/types.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import winim
import com
# import std/[atomics]
import ../../../types

type
WebView* = ptr WebViewObj
Expand All @@ -16,6 +17,7 @@ type
priv*: WebviewPrivObj
created*: bool
onOpenFile*: OnOpenFile
entryType*: EntryType
WebviewPrivObj* = object
windowHandle*: HWND
view*: ptr ICoreWebView2
Expand Down
3 changes: 3 additions & 0 deletions src/crowngui/types.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type
EntryType* = enum
url, file, html, dir
9 changes: 5 additions & 4 deletions src/crowngui/webview.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include js_utils
import tables, strutils, macros, logging, json, os, base64, strformat, std/exitprocs

import ./types
var logger = newRollingFileLogger(expandTilde("~/crowngui.log"))
addHandler(logger)

Expand Down Expand Up @@ -182,7 +182,7 @@ proc run*(w: Webview; quitProc: proc () {.noconv.}; controlCProc: proc () {.noco
system.setControlCHook(controlCProc)
w.run

proc webView(title = ""; url = ""; width: Positive = 1000; height: Positive = 700; resizable: static[bool] = true;
proc webView(title = ""; url = "";entryType:static[EntryType]; width: Positive = 1000; height: Positive = 700; resizable: static[bool] = true;
debug: static[bool] = not defined(release); callback: ExternalInvokeCb = nil): Webview {.inline.} =
result = create(WebviewObj)
result.title = title
Expand All @@ -191,11 +191,12 @@ proc webView(title = ""; url = ""; width: Positive = 1000; height: Positive = 70
result.height = height
result.resizable = resizable
result.debug = debug
result.entryType = entryType

Check failure on line 194 in src/crowngui/webview.nim

View workflow job for this annotation

GitHub Actions / build (macOS-12, devel)

undeclared field: 'entryType=' for type types.Webview [type declared in /Users/runner/work/crowngui/crowngui/src/crowngui/platforms/macos/types.nim(4, 3)]
result.invokeCb = generalExternalInvokeCallback
if callback != nil: result.externalInvokeCB = callback
if result.webview_init() != 0: return nil

proc newWebView*(path: static[string] = ""; title = ""; width: Positive = 1000; height: Positive = 700;
proc newWebView*(path: static[string] = ""; entryType:static[EntryType]; title = ""; width: Positive = 1000; height: Positive = 700;
resizable: static[bool] = true; debug: static[bool] = not defined(release); callback: ExternalInvokeCb = nil;
): Webview =
## Create a new Window with given attributes, all arguments are optional.
Expand All @@ -209,7 +210,7 @@ proc newWebView*(path: static[string] = ""; title = ""; width: Positive = 1000;
var entry = path
when path.endsWith".js" or path.endsWith".nim":
entry = dataUriHtmlHeader "<!DOCTYPE html><html><head><meta content='width=device-width,initial-scale=1' name=viewport></head><body id=body ><div id=ROOT ><div></body></html>" # Copied from Karax
var webview = webView(title, entry, width, height, resizable, debug, callback)
var webview = webView(title, entry, entryType, width, height, resizable, debug, callback)
when defined(macosx):
let MyAppDelegate = registerAppDelegate()
let WindowController = registerWindowController()
Expand Down

0 comments on commit 9a68ead

Please sign in to comment.