sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 268 forks source link

@jinxmcg Thanks! However your code uses Go.Rice directly (via `.FindBox`, `.String`) while it can be used [completely transparent](https://github.com/sciter-sdk/go-sciter/blob/master/rice/rice.go). #347

Closed X-Unlimited closed 1 year ago

X-Unlimited commented 1 year ago
          @jinxmcg Thanks! However your code uses Go.Rice directly (via `.FindBox`, `.String`) while it can be used [completely transparent](https://github.com/sciter-sdk/go-sciter/blob/master/rice/rice.go).

Essentially, rice.HandleDataLoad reduces your example to the following three calls:

    rice.HandleDataLoad(w.Sciter)
    tool.FindBox("res")
    w.LoadFile("rice://res/simple.html")

Here is a full source code (also in examples/restest:

package main

import (
    "log"
    tool "github.com/GeertJohan/go.rice"
    sciter "github.com/sciter-sdk/go-sciter"
    rice "github.com/sciter-sdk/go-sciter/rice"
    window "github.com/sciter-sdk/go-sciter/window"
)

func main() {
    // As usual, create a sciter window.
    w, err := window.New(sciter.SW_TITLEBAR|sciter.SW_RESIZEABLE|sciter.SW_CONTROLS|sciter.SW_MAIN, nil)
    if err != nil {
        log.Fatal(err)
    }

    // 1. Handle resources via sciter.rice loader.
    // It handles URLS like `file://box/` and `rice://box/`.
    rice.HandleDataLoad(w.Sciter)

    // 2. A dummy call to allow `go.rice` to package and register that folder.
    _, err = tool.FindBox("res")
    if err != nil {
        log.Fatal(err)
    }

    // 3. Load a packaged resource.
    err = w.LoadFile("rice://res/simple.html")
    if err != nil {
        log.Fatal(err)
    }
    w.SetTitle("Example")
    w.Show()
    w.Run()
}

How to make it work:

~Although only the rice append is supported. I think it's worth to allow and rice embed as well.~

rice append and rice embed-go work both.

Originally posted by @pravic in https://github.com/sciter-sdk/go-sciter/issues/124#issuecomment-377526649