mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 10:02:55 +08:00
Initial support for firebug (#543)
* Initial support for firebug * Remove windows message
This commit is contained in:
parent
b7a59daee1
commit
5b33ed28fd
6
app.go
6
app.go
@ -2,7 +2,6 @@ package wails
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
"github.com/syossan27/tebata"
|
||||
@ -117,11 +116,6 @@ func (a *App) start() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Enable console for Windows debug builds
|
||||
if runtime.GOOS == "windows" && BuildMode == cmd.BuildModeDebug {
|
||||
a.renderer.EnableConsole()
|
||||
}
|
||||
|
||||
// Start signal handler
|
||||
t := tebata.New(os.Interrupt, os.Kill, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL)
|
||||
t.Reserve(func() {
|
||||
|
File diff suppressed because one or more lines are too long
@ -574,6 +574,10 @@ func ldFlags(po *ProjectOptions, buildMode string) string {
|
||||
ldflags += "-H windowsgui "
|
||||
}
|
||||
|
||||
if po.UseFirebug {
|
||||
ldflags += "-X github.com/wailsapp/wails/lib/renderer.UseFirebug=true "
|
||||
}
|
||||
|
||||
ldflags += "-X github.com/wailsapp/wails.BuildMode=" + buildMode
|
||||
|
||||
// Add additional ldflags passed in via the `ldflags` cli flag
|
||||
|
@ -165,6 +165,7 @@ type ProjectOptions struct {
|
||||
Architecture string
|
||||
LdFlags string
|
||||
GoPath string
|
||||
UseFirebug bool
|
||||
|
||||
// Supported platforms
|
||||
Platforms []string `json:"platforms,omitempty"`
|
||||
|
@ -26,6 +26,7 @@ func init() {
|
||||
var packageApp = false
|
||||
var forceRebuild = false
|
||||
var debugMode = false
|
||||
var usefirebug = false
|
||||
var gopath = ""
|
||||
var typescriptFilename = ""
|
||||
var verbose = false
|
||||
@ -42,6 +43,7 @@ func init() {
|
||||
BoolFlag("p", "Package application on successful build", &packageApp).
|
||||
BoolFlag("f", "Force rebuild of application components", &forceRebuild).
|
||||
BoolFlag("d", "Build in Debug mode", &debugMode).
|
||||
BoolFlag("firebug", "Enable firebug console for debug builds", &usefirebug).
|
||||
BoolFlag("verbose", "Verbose output", &verbose).
|
||||
StringFlag("t", "Generate Typescript definitions to given file (at runtime)", &typescriptFilename).
|
||||
StringFlag("ldflags", "Extra options for -ldflags", &ldflags).
|
||||
@ -71,6 +73,7 @@ func init() {
|
||||
// Project options
|
||||
projectOptions := &cmd.ProjectOptions{}
|
||||
projectOptions.Verbose = verbose
|
||||
projectOptions.UseFirebug = usefirebug
|
||||
|
||||
// Check we are in project directory
|
||||
// Check project.json loads correctly
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
type Renderer interface {
|
||||
Initialise(AppConfig, IPCManager, EventManager) error
|
||||
Run() error
|
||||
EnableConsole()
|
||||
|
||||
// Binding
|
||||
NewBinding(bindingName string) error
|
||||
|
@ -56,10 +56,6 @@ func (h *Bridge) Initialise(appConfig interfaces.AppConfig, ipcManager interface
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableConsole not needed for bridge!
|
||||
func (h *Bridge) EnableConsole() {
|
||||
}
|
||||
|
||||
func (h *Bridge) wsBridgeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := websocket.Upgrade(w, r, w.Header(), 1024, 1024)
|
||||
if err != nil {
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -18,14 +18,17 @@ import (
|
||||
|
||||
// WebView defines the main webview application window
|
||||
// Default values in []
|
||||
|
||||
// UseFirebug indicates whether to inject the firebug console
|
||||
var UseFirebug = ""
|
||||
|
||||
type WebView struct {
|
||||
window wv.WebView // The webview object
|
||||
ipc interfaces.IPCManager
|
||||
log *logger.CustomLogger
|
||||
config interfaces.AppConfig
|
||||
eventManager interfaces.EventManager
|
||||
bindingCache []string
|
||||
enableConsole bool
|
||||
window wv.WebView // The webview object
|
||||
ipc interfaces.IPCManager
|
||||
log *logger.CustomLogger
|
||||
config interfaces.AppConfig
|
||||
eventManager interfaces.EventManager
|
||||
bindingCache []string
|
||||
}
|
||||
|
||||
// NewWebView returns a new WebView struct
|
||||
@ -104,11 +107,6 @@ func (w *WebView) evalJS(js string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnableConsole enables the console!
|
||||
func (w *WebView) EnableConsole() {
|
||||
w.enableConsole = true
|
||||
}
|
||||
|
||||
// Escape the Javascripts!
|
||||
func escapeJS(js string) (string, error) {
|
||||
result := strings.Replace(js, "\\", "\\\\", -1)
|
||||
@ -179,10 +177,9 @@ func (w *WebView) Run() error {
|
||||
w.log.Info("Running...")
|
||||
|
||||
// Inject firebug in debug mode on Windows
|
||||
if w.enableConsole {
|
||||
w.log.Debug("Enabling Wails console")
|
||||
console := mewn.String("../../runtime/assets/console.js")
|
||||
w.evalJS(console)
|
||||
if UseFirebug != "" {
|
||||
w.log.Debug("Injecting Firebug")
|
||||
w.evalJS(`window.usefirebug=true;`)
|
||||
}
|
||||
|
||||
// Runtime assets
|
||||
|
File diff suppressed because one or more lines are too long
@ -13,7 +13,7 @@ import * as Browser from './browser';
|
||||
import { On, OnMultiple, Emit, Notify, Heartbeat, Acknowledge } from './events';
|
||||
import { NewBinding } from './bindings';
|
||||
import { Callback } from './calls';
|
||||
import { AddScript, InjectCSS } from './utils';
|
||||
import { AddScript, InjectCSS, InjectFirebug } from './utils';
|
||||
import { AddIPCListener } from './ipc';
|
||||
import * as Store from './store';
|
||||
|
||||
@ -60,6 +60,11 @@ window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||
window.wails.Log.Error('error: ' + error);
|
||||
};
|
||||
|
||||
// Use firebug?
|
||||
if( window.usefirebug ) {
|
||||
InjectFirebug();
|
||||
}
|
||||
|
||||
// Emit loaded event
|
||||
Emit('wails:loaded');
|
||||
|
||||
|
@ -20,6 +20,18 @@ export function AddScript(js, callbackID) {
|
||||
}
|
||||
}
|
||||
|
||||
export function InjectFirebug() {
|
||||
// set the debug attribute on HTML
|
||||
var html = document.getElementsByTagName('html')[0];
|
||||
html.setAttribute('debug', 'true');
|
||||
var firebugURL = 'https://wails.app/assets/js/firebug-lite.js#startOpened=true,disableWhenFirebugActive=false';
|
||||
var script = document.createElement('script');
|
||||
script.src = firebugURL;
|
||||
script.type = 'application/javascript';
|
||||
document.head.appendChild(script);
|
||||
window.wails.Log.Info('Injected firebug');
|
||||
}
|
||||
|
||||
// Adapted from webview - thanks zserge!
|
||||
export function InjectCSS(css) {
|
||||
var elem = document.createElement('style');
|
||||
|
Loading…
Reference in New Issue
Block a user