2025-10-27 03:14:50 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"embed"
|
|
|
|
|
"io"
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"github.com/wailsapp/wails/v3/pkg/application"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// This file defines the public API contracts (interfaces) for the services
|
|
|
|
|
// in the Core framework. Services depend on these interfaces, not on
|
|
|
|
|
// concrete implementations.
|
|
|
|
|
|
|
|
|
|
type Contract struct {
|
|
|
|
|
DontPanic bool
|
|
|
|
|
DisableLogging bool
|
|
|
|
|
}
|
2025-11-02 03:03:54 +00:00
|
|
|
|
|
|
|
|
// Features provides a way to check if a feature is enabled.
|
|
|
|
|
type Features struct {
|
|
|
|
|
Flags []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsEnabled returns true if the given feature is enabled.
|
|
|
|
|
func (f *Features) IsEnabled(feature string) bool {
|
|
|
|
|
for _, flag := range f.Flags {
|
|
|
|
|
if flag == feature {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2025-10-27 03:14:50 +00:00
|
|
|
type Option func(*Core) error
|
|
|
|
|
type Message interface{}
|
|
|
|
|
type Core struct {
|
|
|
|
|
once sync.Once
|
|
|
|
|
initErr error
|
|
|
|
|
App *application.App
|
|
|
|
|
assets embed.FS
|
2025-11-02 03:03:54 +00:00
|
|
|
Features *Features
|
2025-10-27 03:14:50 +00:00
|
|
|
serviceLock bool
|
|
|
|
|
ipcMu sync.RWMutex
|
|
|
|
|
ipcHandlers []func(*Core, Message) error
|
|
|
|
|
serviceMu sync.RWMutex
|
|
|
|
|
services map[string]any
|
|
|
|
|
servicesLocked bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var instance *Core
|
|
|
|
|
|
|
|
|
|
// Config provides access to application configuration.
|
|
|
|
|
type Config interface {
|
|
|
|
|
Get(key string, out any) error
|
|
|
|
|
Set(key string, v any) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WindowConfig represents the configuration for a window.
|
|
|
|
|
type WindowConfig struct {
|
|
|
|
|
Name string
|
|
|
|
|
Title string
|
|
|
|
|
URL string
|
|
|
|
|
Width int
|
|
|
|
|
Height int // Add other common window options here as needed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WindowOption configures window creation.
|
|
|
|
|
type WindowOption interface {
|
2025-10-28 21:42:29 +00:00
|
|
|
Apply(*WindowConfig)
|
2025-10-27 03:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display manages windows and UI.
|
|
|
|
|
type Display interface {
|
|
|
|
|
OpenWindow(opts ...WindowOption) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Help manages the in-app documentation and help system.
|
|
|
|
|
type Help interface {
|
|
|
|
|
Show() error
|
|
|
|
|
ShowAt(anchor string) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Crypt provides cryptographic functions.
|
|
|
|
|
type Crypt interface {
|
|
|
|
|
EncryptPGP(writer io.Writer, recipientPath, data string, signerPath, signerPassphrase *string) (string, error)
|
|
|
|
|
DecryptPGP(recipientPath, message, passphrase string, signerPath *string) (string, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I18n provides internationalization and localization services.
|
|
|
|
|
type I18n interface {
|
|
|
|
|
// Translate returns the translated string for the given key.
|
|
|
|
|
Translate(key string) string
|
|
|
|
|
// SetLanguage changes the active language.
|
|
|
|
|
SetLanguage(lang string) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Workspace manages user workspaces.
|
|
|
|
|
type Workspace interface {
|
|
|
|
|
CreateWorkspace(identifier, password string) (string, error)
|
|
|
|
|
SwitchWorkspace(name string) error
|
|
|
|
|
WorkspaceFileGet(filename string) (string, error)
|
|
|
|
|
WorkspaceFileSet(filename, content string) error
|
|
|
|
|
}
|