Coder Social home page Coder Social logo

bung87 / crowngui Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 3.0 694 KB

Web Technologies based Crossplatform GUI Framework, WebView in Nim

Home Page: https://bung87.github.io/crowngui/

License: MIT License

Nim 99.13% HTML 0.24% JavaScript 0.63%
webgui webview

crowngui's Introduction

crowngui

Web Technologies based Crossplatform GUI Framework

It uses Cocoa/WebKit on macOS, gtk-webkit2 on Linux and webview2 on Windows

crowngui contains managed code only, no native code.

crowngui provide CLI tool for bundling application easier.

CLI tool:
crowncli.

Architecture

how bindProcs works?

figure generated via asciiflow


┌─────────────┐         ┌──────────────────────────────┐       ┌─────────────────────────┐
│             │         │                              │       │                         │
│             │         │store hook function in `eps`  │       │when trigger js function │
│             │         │hook accept one string param  │       │internally it use browser│
│  bindProcs  ├────────►│and returns string that wraps ├──────►│`postMessage` api send   │
│             │         │nim proc call.                │       │json string with scope,  │
│             │         │And generate js function and  │       │name, argument.          │
│             │         │dispatch to main queue.       │       │                         │
└─────────────┘         └──────────────────────────────┘       └────────────┬────────────┘
                                                                            │
                                                                            ▼
                        ┌────────────────────────────────────────────────────┐
                        │browser add callback when received message          │
                        │it calls Webview's `invokeCb` which implements      │
                        │as `generalExternalInvokeCallback`                  │
                        │it parse argument as json retrieve scope,           │
                        │name, argument,then call the hook stored.           │
                        │                                                    │
                        └────────────────────────────────────────────────────┘

Usage

file: yourexecutable.nim

import crowngui

when isMainModule:
  const   
    cssDark = staticRead"assets/dark.css".strip.unindent.cstring
    cssLight = staticRead"assets/light.css".strip.unindent.cstring

  let app = newApplication( staticRead("assets/demo.html") )
  when not defined(bundle):
    let theme = if "--light-theme" in commandLineParams(): cssLight else: cssDark
    app.css(theme)
  app.run()
  app.exit()

Your project .nimble file

bin           = @["yourexecutable"]

crowncli will bundle your executable to exe on windows, .app on mac

Your project root can have "logo.png" which will generate as icon of application.

CLI usage

crowncli [build,run] --help

Usage:
  [build,run] [required&optional-params] [flags: string...]
Options:
  -h, --help                         print this cligen-erated help
  --help-syntax                      advanced: prepend,plurals,..
  -t=, --target=   string  REQUIRED  set target
  -w=, --wwwroot=  string  ""        set wwwroot
  -r, --release    bool    false     set release

Examples

crown_excel crowngui based excel viewer

Prerequires

rcedit for windows exe icon on non-windows platform requires wine

Development

run
crowncli run --target macos

build
crowncli build --target macos

Cross compilation for Windows

To cross compile for Windows from Linux or macOS using the MinGW-w64 toolchain:

nim c -d:mingw myproject.nim

Use --cpu:i386 or --cpu:amd64 to switch the CPU architecture.

The MinGW-w64 toolchain can be installed as follows:

Ubuntu: apt install mingw-w64
CentOS: yum install mingw32-gcc | mingw64-gcc - requires EPEL
OSX: brew install mingw-w64

References

Distribute your app and the WebView2 Runtime

WebView2 Win32 Reference

crowngui's People

Contributors

bung87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

crowngui's Issues

Using webview2.nim

I want to use the code in webview2.nim without the crowngui app to learn something about the internals of webview, it seems it should be possible because there is this code at line 250:

when isMainModule:
  SetCurrentProcessExplicitAppUserModelID("webview2 app")
  var v = newWebView()
  assert v.webview_init() == 0

  v.run

but there is no newWebView() proc which can be called.
How can I write a newWebView() that starts the app?
I tried to add this at line 252: import ../../webview.nim
and I can compile, but it fails to run with this error:
ERROR:window_impl.cc(121)] Failed to unregister class Chrome_WidgetWin_0. Error = 0

Error: undeclared identifier: 'ID' in stable and latest

Installing crowngui@#head
Building crowngui/crowngui.exe using c backend
C:\Users\dev1lroot\AppData\Local\Temp\nimble_9460\githubcom_bung87crowngui_#head\src\crownguipkg\webview.nim(22, 11) Error: undeclared identifier: 'ID'
Tip: 49 messages have been suppressed, use --verbose to show them.
Error: Build failed for package: crowngui
... Execution failed with exit code 1
... Command: I:\WindowsLibrary\Terminal\nim-1.4.6\bin\nim.exe c --colors:on --noNimblePath -d:release -d:NimblePkgVersion=0.2.7 --path:C:\Users\dev1lroot.nimble\pkgs\regex-0.19.0 --path:C:\Users\dev1lroot.nimble\pkgs\unicodedb-0.9.0 --path:C:\Users\dev1lroot.nimble\pkgs\xlsx-0.4.5 --path:C:\Users\dev1lroot.nimble\pkgs\zip-0.3.1 --path:C:\Users\dev1lroot.nimble\pkgs\static_server-2.2.0 --path:C:\Users\dev1lroot.nimble\pkgs\finder-0.2.0 --path:C:\Users\dev1lroot.nimble\pkgs\zippy-0.5.6 --path:C:\Users\dev1lroot.nimble\pkgs\jsonschema-0.2.1 --path:C:\Users\dev1lroot.nimble\pkgs\ast_pattern_matching-1.0.0 --path:C:\Users\dev1lroot.nimble\pkgs\objc_runtime-0.1.0 --path:C:\Users\dev1lroot.nimble\pkgs\darwin-#master --path:C:\Users\dev1lroot.nimble\pkgs\darwin-#master --hints:off -o:C:\Users\dev1lroot\AppData\Local\Temp\nimble_9460\githubcom_bung87crowngui_#head\crowngui.exe C:\Users\dev1lroot\AppData\Local\Temp\nimble_9460\githubcom_bung87crowngui_#head\src\crowngui.nim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.