mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 19:50:15 +08:00
[v3] Improved plugin shutdown
This commit is contained in:
parent
767b7d6026
commit
7ecbc846b4
@ -76,7 +76,7 @@ func New(appOptions Options) *App {
|
||||
result.plugins = NewPluginManager(appOptions.Plugins, srv)
|
||||
err = result.plugins.Init()
|
||||
if err != nil {
|
||||
println("Fatal error in application initialisation: ", err.Error())
|
||||
result.Quit()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,9 @@ type Plugin interface {
|
||||
}
|
||||
|
||||
type PluginManager struct {
|
||||
plugins map[string]Plugin
|
||||
assetServer *assetserver.AssetServer
|
||||
plugins map[string]Plugin
|
||||
assetServer *assetserver.AssetServer
|
||||
initialisedPlugins []Plugin
|
||||
}
|
||||
|
||||
func NewPluginManager(plugins map[string]Plugin, assetServer *assetserver.AssetServer) *PluginManager {
|
||||
@ -27,8 +28,11 @@ func (p *PluginManager) Init() error {
|
||||
for _, plugin := range p.plugins {
|
||||
err := plugin.Init(globalApplication)
|
||||
if err != nil {
|
||||
globalApplication.error("Plugin '%s' failed to initialise: %s", plugin.Name(), err.Error())
|
||||
p.Shutdown()
|
||||
return err
|
||||
}
|
||||
p.initialisedPlugins = append(p.initialisedPlugins, plugin)
|
||||
injectJS := plugin.InjectJS()
|
||||
if injectJS != "" {
|
||||
p.assetServer.AddPluginScript(plugin.Name(), injectJS)
|
||||
@ -39,7 +43,7 @@ func (p *PluginManager) Init() error {
|
||||
}
|
||||
|
||||
func (p *PluginManager) Shutdown() {
|
||||
for _, plugin := range p.plugins {
|
||||
for _, plugin := range p.initialisedPlugins {
|
||||
plugin.Shutdown()
|
||||
globalApplication.info("Plugin '%s' shutdown", plugin.Name())
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package single_instance
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -71,7 +72,7 @@ func (p *Plugin) Init(app *application.App) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
return fmt.Errorf("another instance of this application is already running")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user