Closed mchampaneri closed 6 years ago
I think, this can be improved:
// win.DefaultCallBackHandler()
// win.OpenArchive(resources)
// usage:
win.SetResourceArchive(resources)
win.LoadFile("this://app//notepad.htm")
// win.SetTitle("Demo") - there is no point in this call if notepad.htm contains <title>
// in library
func (sc *Sciter) SetResourceArchive(data []byte) {
sc.OpenArchive(data)
sc.SetCallback(...)
}
Although I see your point with file://
(i.e. use archived items if available, fallback to files in filesystem otherwise - aka dev/production environment), but I am not sure about this, since Sciter itself does not use this approach.
Sciter uses a hard coded schema (this://app/
) that relies on changing URLs in your app:
// dev/test environment, use local URLs:
// assume that 'index.htm` is in the current directory (common situation)
dir, _ := os.Getwd()
win.LoadFile(dir + "/index.htm")
// production environment
// use archived resources
win.LoadFile("this://app//index.htm")
Also keep in mind that HTML itself uses relative paths anyway:
<style src="main.css" />
<script type="text/tiscript" src="main.tis"/>
<body></body>
If you call LoadFile("~/sciter/index.htm")
, main.css
will be loaded from ~/sciter/main.css
.
If you call LoadFile("this://app/index.htm")
, main.css
will be loaded from this://app/main.css
.
So you need to change only URL of the main file.
@pravic
So you need to change only URL of the main file.
Actully , Its not working for me. When i just loaded main.html, It was not able to find style.css file using relative path.
I have to load every file from archive on their url using sc.DataReady(url, file-bytes)
Again, to make it work you need to load the main html using an absolute url. Either via LoadHtml
or LoadFile
. Or show your code, I might miss something.
@pravic
I have uploaded zip file containing code.
It contains 4 resource files, 2 go files and packfolder.exe
During Callback function I have to load css file to their relative url using
win.GetArchiveItem(params.Uri()[7:])
win.DataReady(params.Uri()[7:], fileData)
Otherwise css files are not get found,
Callback function loads the files according to the html file I am loading from archive using GetArchiveItem
win.LoadHtml(string(htbytes), "")
As I said, this is the problem (the empty URL). Either write win.LoadHtml(string(htbytes), "this://app/abc.html")
or win.LoadFile("this://app/abc.html")
.
It works fine with CSS, check it.
25d8ed4 contains SetResourceArchive
and a usage example (examples/restest2
).
@pravic
I understood what was the problem after reviewing your commit.
Thanks
Okay than. Thanks for bringing this up.
There should be a defaultCallBackHandler function that resolves files from archive.
Function
Useage