|
|
@@ -43,6 +43,19 @@ func init() {
|
|
|
func main() {
|
|
|
d := &dialogs{}
|
|
|
svc, host := app.NewService(d)
|
|
|
+ a := newApp(svc, host)
|
|
|
+ d.a = a
|
|
|
+ w := newWindow(a)
|
|
|
+ guardClose(a, w, host)
|
|
|
+ handleFileDrops(a, w, host)
|
|
|
+ if err := a.Run(); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// newApp creates the application. Only svc is bound; host serves the
|
|
|
+// sample previews.
|
|
|
+func newApp(svc *app.Service, host *app.Host) *application.App {
|
|
|
var a *application.App
|
|
|
a = application.New(application.Options{
|
|
|
Name: "MPCkit",
|
|
|
@@ -65,11 +78,12 @@ func main() {
|
|
|
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
|
|
},
|
|
|
})
|
|
|
+ return a
|
|
|
+}
|
|
|
|
|
|
- d.a = a
|
|
|
-
|
|
|
- // Start hidden and size the window once the screens are known, so it
|
|
|
- // fits the display instead of being clamped by it.
|
|
|
+// newWindow opens the main window. It starts hidden and is sized once the
|
|
|
+// screens are known, so it fits the display instead of being clamped by it.
|
|
|
+func newWindow(a *application.App) *application.WebviewWindow {
|
|
|
w := a.Window.NewWithOptions(application.WebviewWindowOptions{
|
|
|
Title: "MPCkit",
|
|
|
Width: maxWidth,
|
|
|
@@ -81,7 +95,6 @@ func main() {
|
|
|
BackgroundColour: application.NewRGB(0x15, 0x17, 0x1A),
|
|
|
URL: "/",
|
|
|
})
|
|
|
-
|
|
|
a.Event.OnApplicationEvent(events.Common.ApplicationStarted, func(*application.ApplicationEvent) {
|
|
|
if s := a.Screen.GetPrimary(); s != nil {
|
|
|
width, height := fitSize(s.WorkArea.Width, s.WorkArea.Height)
|
|
|
@@ -90,10 +103,13 @@ func main() {
|
|
|
w.Center()
|
|
|
w.Show()
|
|
|
})
|
|
|
+ return w
|
|
|
+}
|
|
|
|
|
|
- // Closing with unsaved changes: stop, and let the frontend ask. If the
|
|
|
- // user chooses to discard them, the frontend calls CloseWindow, which
|
|
|
- // closes for real.
|
|
|
+// guardClose handles closing with unsaved changes: stop, and let the
|
|
|
+// frontend ask. If the user chooses to discard them, the frontend calls
|
|
|
+// CloseWindow, which closes for real.
|
|
|
+func guardClose(a *application.App, w *application.WebviewWindow, host *app.Host) {
|
|
|
var closeConfirmed atomic.Bool
|
|
|
host.SetCloser(func() {
|
|
|
closeConfirmed.Store(true)
|
|
|
@@ -106,9 +122,11 @@ func main() {
|
|
|
e.Cancel()
|
|
|
a.Event.Emit(eventClose)
|
|
|
})
|
|
|
+}
|
|
|
|
|
|
- // A WAV dropped on a pad (an element with data-file-drop-target and
|
|
|
- // data-slot) is assigned to that pad.
|
|
|
+// handleFileDrops assigns a WAV dropped on a pad (an element with
|
|
|
+// data-file-drop-target and data-slot) to that pad.
|
|
|
+func handleFileDrops(a *application.App, w *application.WebviewWindow, host *app.Host) {
|
|
|
w.OnWindowEvent(events.Common.WindowFilesDropped, func(e *application.WindowEvent) {
|
|
|
ctx := e.Context()
|
|
|
target := ctx.DropTargetDetails()
|
|
|
@@ -131,10 +149,6 @@ func main() {
|
|
|
}
|
|
|
a.Event.Emit(eventError, "Only WAV files can be assigned to a pad.")
|
|
|
})
|
|
|
-
|
|
|
- if err := a.Run(); err != nil {
|
|
|
- log.Fatal(err)
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// fitSize returns a 16:9 window size that takes screenShare of the work
|