Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-clicking from a Windows desktop application fails #4652

Closed
deltaepsilon opened this issue Mar 28, 2024 · 1 comment
Closed

Double-clicking from a Windows desktop application fails #4652

deltaepsilon opened this issue Mar 28, 2024 · 1 comment

Comments

@deltaepsilon
Copy link

FOR POSTERITY

I've been wracking my brain, trying to figure out why my windows application won't launch from a double-click.

I'm using Pocketbase, and I isolated it to Pocketbase's Start command.

After digging in deep, I discovered that Pocketbase relies on Cobra, which has a "mousetrap" in place to prevent it from being used from a double-click... because it's a CLI tool and the authors don't want people to accidentally launch Cobra apps from a double-click.

Here's the repaired, working code. The relevant line is cobra.MousetrapHelpText = "". I imported "github.com/spf13/cobra" and set it on the imported module.

func StartPocketbase() *pocketbase.PocketBase {

	configDir, err := os.UserConfigDir()
	if err != nil {
		log.Fatal(err)
	}

	dataDir := filepath.Join(configDir, "QuiverPhotos", "__data")
	EnsurePathExists(dataDir)

	publicDir := filepath.Join(configDir, "QuiverPhotos", "__public")
	EnsurePathExists(publicDir)

	isDev := strings.Contains(os.Args[0], "-dev-")
	os.Args = []string{"pocketbase", "serve", "--dir=" + dataDir, "--publicDir=" + publicDir}

	app := pocketbase.New()

	if isDev {
		fmt.Println("🤖 Starting pocketbase in dev mode...")
	}

	migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
		Automigrate: isDev,
	})

	go func() {
		cobra.MousetrapHelpText = "" // Disable the mousetrap help text
		err := app.Start()
		log.Println("app.Start err:", err)
		if err != nil {
			log.Println("Failed to start pocketbase:", err)
		}
	}()

	return app
}
@ganigeorgiev
Copy link
Member

ganigeorgiev commented Mar 28, 2024

Double clicking will not work because we don't register a default command, aka. it is expected users to invoke the .\pocketbase serve command from the terminal.

Unless I'm misunderstand something there no plans for now to change this as I already have enough on my hands (see #4355).

edit: On second read I see that you are registering your own custom Start action. But in any case if you have other questions or just want to share something with the community, please consider using the Discussions instead.

@ganigeorgiev ganigeorgiev closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants