mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Add BundledAssetFileServer for bundled /wails/runtime.js. Update examples.
This commit is contained in:
parent
75c0236a04
commit
bc0a9b2e52
40 changed files with 1214 additions and 1209 deletions
|
|
@ -46,7 +46,6 @@ func main() {
|
|||
generate.NewSubCommandFunction("constants", "Generate JS constants from Go", commands.GenerateConstants)
|
||||
generate.NewSubCommandFunction(".desktop", "Generate .desktop file", commands.GenerateDotDesktop)
|
||||
generate.NewSubCommandFunction("appimage", "Generate Linux AppImage", commands.GenerateAppImage)
|
||||
generate.NewSubCommandFunction("runtime", "Generate the latest compiled runtime", commands.GenerateRuntime)
|
||||
|
||||
plugin := app.NewSubCommand("plugin", "Plugin tools")
|
||||
//plugin.NewSubCommandFunction("list", "List plugins", commands.PluginList)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@
|
|||
<input autofocus autocomplete="off" class="input" id="name" type="text"/>
|
||||
<button class="btn" onclick="greet()">Greet</button>
|
||||
</div>
|
||||
<script src='runtime.js'></script>
|
||||
<script src='/wails/runtime.js'></script>
|
||||
<script src='bindings_main.js'></script>
|
||||
<script>
|
||||
let resultText = "";
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func main() {
|
|||
&GreetService{},
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<title>Title</title>
|
||||
<style>body{ text-align: center; color: white; background-color: #191919; }</style>
|
||||
<style>.region{ width: 100%; border: 3px solid #00a4db; }</style>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Context Menu Demo</h1>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -17,7 +17,7 @@ func main() {
|
|||
Name: "Context Menu Demo",
|
||||
Description: "A demo of the Context Menu API",
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
|
|
|
|||
|
|
@ -35,14 +35,6 @@ func main() {
|
|||
URL: "/",
|
||||
})
|
||||
|
||||
//app.On(events.Common.ThemeChanged, func(e *application.Event) {
|
||||
// if app.IsDarkMode() {
|
||||
// log.Println("Dark mode!")
|
||||
// } else {
|
||||
// log.Println("Light mode!")
|
||||
// }
|
||||
//})
|
||||
|
||||
err := app.Run()
|
||||
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<style>body{ text-align: center; color: white; background-color: #191919; user-select: none; -ms-user-select: none; -webkit-user-select: none; }</style>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Drag-n-drop Demo</h1>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func main() {
|
|||
Name: "Drag-n-drop Demo",
|
||||
Description: "A demo of the Drag-n-drop API",
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
<style>body{ text-align: center; color: white; background-color: #191919; user-select: none; -ms-user-select: none; -webkit-user-select: none; }</style>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -19,7 +19,7 @@ func main() {
|
|||
Name: "Events Demo",
|
||||
Description: "A demo of the Events API",
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -17,7 +17,7 @@ func main() {
|
|||
Name: "Frameless Demo",
|
||||
Description: "A demo of frameless windows",
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ func main() {
|
|||
Description: "A test of Hidden window and display it",
|
||||
Assets: application.AlphaAssets,
|
||||
Mac: application.MacOptions{
|
||||
// ActivationPolicy: application.ActivationPolicyAccessory,
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: false,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@
|
|||
text-align: -webkit-center;
|
||||
}
|
||||
</style>
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -26,7 +26,7 @@ func main() {
|
|||
WebviewBrowserPath: "",
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@
|
|||
font-size: large;
|
||||
}
|
||||
</style>
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body style="--webkit-app-region: drag;">
|
||||
<img class="logo"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ func main() {
|
|||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@
|
|||
font-size: large;
|
||||
}
|
||||
</style>
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<img class="logo"
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -20,7 +20,7 @@ func main() {
|
|||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
Handler: application.BundledAssetFileServer(assets),
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ require (
|
|||
github.com/Microsoft/go-winio v0.6.1 // indirect
|
||||
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
|
||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||
github.com/alexbrainman/ps v0.0.0-20171229230509-b3e1b4a15894 // indirect
|
||||
github.com/cloudflare/circl v1.3.7 // indirect
|
||||
github.com/containerd/console v1.0.3 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
|
||||
|
|
|
|||
1139
v3/internal/assetserver/assets/runtime.debug.js
Normal file
1139
v3/internal/assetserver/assets/runtime.debug.js
Normal file
File diff suppressed because one or more lines are too long
1
v3/internal/assetserver/assets/runtime.js
Normal file
1
v3/internal/assetserver/assets/runtime.js
Normal file
File diff suppressed because one or more lines are too long
33
v3/internal/assetserver/bundled_assetserver.go
Normal file
33
v3/internal/assetserver/bundled_assetserver.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package assetserver
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/internal/assetserver/bundledassets"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BundledAssetServer struct {
|
||||
handler http.Handler
|
||||
}
|
||||
|
||||
func NewBundledAssetFileServer(fs fs.FS) *BundledAssetServer {
|
||||
return &BundledAssetServer{
|
||||
handler: NewAssetFileServer(fs),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BundledAssetServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
if strings.HasPrefix(req.URL.Path, "/wails/") {
|
||||
// Strip the /wails prefix
|
||||
req.URL.Path = req.URL.Path[6:]
|
||||
switch req.URL.Path {
|
||||
case "/runtime.js":
|
||||
rw.Header().Set("Content-Type", "application/javascript")
|
||||
rw.Write([]byte(bundledassets.RuntimeJS))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
b.handler.ServeHTTP(rw, req)
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package runtime
|
||||
//go:build !production
|
||||
|
||||
package bundledassets
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed runtime.js
|
||||
var RuntimeJS []byte
|
||||
|
||||
//go:embed runtime.debug.js
|
||||
var RuntimeDebugJS []byte
|
||||
var RuntimeJS []byte
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
//go:build production
|
||||
|
||||
package bundledassets
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed runtime.js
|
||||
var RuntimeJS []byte
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -1,21 +0,0 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/internal/commands/build_assets/runtime"
|
||||
"os"
|
||||
)
|
||||
|
||||
type GenerateRuntimeOptions struct {
|
||||
}
|
||||
|
||||
func GenerateRuntime(options *GenerateRuntimeOptions) error {
|
||||
err := os.WriteFile("runtime.js", runtime.RuntimeJS, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.WriteFile("runtime.debug.js", runtime.RuntimeDebugJS, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -21,12 +21,12 @@ tasks:
|
|||
build:debug:
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild@latest desktop/compiled/main.js --bundle --tree-shaking=true --sourcemap=inline --outfile=../commands/build_assets/runtime/runtime.debug.js --define:DEBUG=true
|
||||
- npx esbuild@latest desktop/compiled/main.js --bundle --tree-shaking=true --sourcemap=inline --outfile=../assetserver/assets/runtime.debug.js --define:DEBUG=true
|
||||
|
||||
build:production:
|
||||
internal: true
|
||||
cmds:
|
||||
- npx esbuild@latest desktop/compiled/main.js --bundle --tree-shaking=true --minify --outfile=../commands/build_assets/runtime/runtime.js --define:DEBUG=false --drop:console
|
||||
- npx esbuild@latest desktop/compiled/main.js --bundle --tree-shaking=true --minify --outfile=../assetserver/assets/runtime.js --define:DEBUG=false --drop:console
|
||||
|
||||
build:all:
|
||||
internal: true
|
||||
|
|
@ -35,14 +35,6 @@ tasks:
|
|||
- build:production
|
||||
|
||||
cmds:
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/binding/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/frameless/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/window-api/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/contextmenus/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/wml/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../internal/commands/build_assets/runtime/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../examples/screen/assets/runtime.js
|
||||
- cmd: wails3 tool cp ../commands/build_assets/runtime/runtime.js ../../pkg/application/assets/alpha/runtime.js
|
||||
- cmd: echo "Build Complete."
|
||||
|
||||
build:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ var globalApplication *App
|
|||
|
||||
// AlphaAssets is the default assets for the alpha application
|
||||
var AlphaAssets = AssetOptions{
|
||||
Handler: AssetFileServerFS(alphaAssets),
|
||||
Handler: BundledAssetFileServer(alphaAssets),
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -115,6 +115,15 @@ func AssetFileServerFS(assets fs.FS) http.Handler {
|
|||
return assetserver.NewAssetFileServer(assets)
|
||||
}
|
||||
|
||||
// BundledAssetFileServer returns a http handler which serves the assets from the fs.FS.
|
||||
// If an external devserver has been provided 'FRONTEND_DEVSERVER_URL' the files are being served
|
||||
// from the external server, ignoring the `assets`.
|
||||
// It also serves the compiled runtime.js file at `/wails/runtime.js`.
|
||||
// It will provide the production runtime.js file from the embedded assets if the `production` tag is used.
|
||||
func BundledAssetFileServer(assets fs.FS) http.Handler {
|
||||
return assetserver.NewBundledAssetFileServer(assets)
|
||||
}
|
||||
|
||||
/******** Mac Options ********/
|
||||
|
||||
// ActivationPolicy is the activation policy for the application.
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@
|
|||
}
|
||||
</style>
|
||||
<!-- Load the runtime from our asset bundle -->
|
||||
<script src="runtime.js"></script>
|
||||
<script src="/wails/runtime.js"></script>
|
||||
</head>
|
||||
<body style="--webkit-app-region: drag;">
|
||||
<img class="logo"
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue