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