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

New window created on each trigger of sidecar #4823

Closed
siegerts opened this issue Aug 1, 2022 · 12 comments · Fixed by #4814
Closed

New window created on each trigger of sidecar #4823

siegerts opened this issue Aug 1, 2022 · 12 comments · Fixed by #4814
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@siegerts
Copy link

siegerts commented Aug 1, 2022

Describe the bug

Every time I trigger the sidecar via JS a new window is opened.

Very similar to #3564

Reproduction

  1. create sidecar executable in go
package main

import "fmt"

func something() {
	fmt.Println("my msg here")
}

func main() {
	something()
}
  1. configure sidecar in app
  2. call sidecar from frontend Vue app
<script setup>
...


async function testSidecar() {
 
  let cmd = Command.sidecar('bin/sc')
  let out = await cmd.execute()
  console.log(out)
}
</script>
  1. new app window opens

Expected behavior

No response

Platform and versions

> tauri "info"


Environment
  › OS: Mac OS 12.4.0 X64
  › Node.js: 16.13.0
  › npm: 8.1.0
  › pnpm: 7.3.0
  › yarn: 1.22.17
  › rustup: 1.24.3
  › rustc: 1.61.0
  › cargo: 1.61.0
  › Rust toolchain: stable-x86_64-apple-darwin

Packages
  › @tauri-apps/cli [NPM]: 1.0.5
  › @tauri-apps/api [NPM]: 1.0.2
  › tauri [RUST]: 1.0.5,
  › tauri-build [RUST]: 1.0.4,
  › tao [RUST]: 0.12.2,
  › wry [RUST]: 0.19.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: Vue.js

App directory structure
  ├─ dist
  ├─ node_modules
  ├─ public
  ├─ src-tauri
  ├─ .vscode
  └─ src

Stack trace

No response

Additional context

No response

@siegerts siegerts added status: needs triage This issue needs to triage, applied to new issues type: bug labels Aug 1, 2022
@lucasfernog
Copy link
Member

I thought this was on Windows lol can you share a sample sidecar or go app that we can use? Just to check if it isn't something specific to Go.

@siegerts
Copy link
Author

siegerts commented Aug 1, 2022

The program is just the Go snippet above, just to get it working.

@lucasfernog
Copy link
Member

Also an entire repo showcasing this issue might be useful since it could be related to the project configuration.

@lucasfernog
Copy link
Member

Ok I'll see if I can reproduce with this data thanks @siegerts

@siegerts
Copy link
Author

siegerts commented Aug 1, 2022

{
  "$schema": "../node_modules/@tauri-apps/cli/schema.json",
  "build": {
    "beforeBuildCommand": "yarn build",
    "beforeDevCommand": "yarn dev",
    "devPath": "http://localhost:5173",
    "distDir": "../dist"
  },
  "package": {
    "productName": "sc",
    "version": "0.1.0"
  },
  "tauri": {
    "allowlist": {
      "all": true,
      "shell": {
        "sidecar": true,
        "scope": [
          { "name": "bin/sc", "sidecar": true }
        ]
      }
    },
    "bundle": {
      "active": true,
      "category": "DeveloperTool",
      "copyright": "",
      "deb": {
        "depends": []
      },
      "externalBin": [  "bin/sc" ],
      "icon": [
        "icons/32x32.png",
        "icons/128x128.png",
        "icons/128x128@2x.png",
        "icons/icon.icns",
        "icons/icon.ico"
      ],
      "identifier": "com.siegerts.dev",
      "longDescription": "",
      "macOS": {
        "entitlements": null,
        "exceptionDomain": "",
        "frameworks": [],
        "providerShortName": null,
        "signingIdentity": null
      },
      "resources": [],
      "shortDescription": "",
      "targets": "all",
      "windows": {
        "certificateThumbprint": null,
        "digestAlgorithm": "sha256",
        "timestampUrl": ""
      }
    },
    "security": {
      "csp": null
    },
    "updater": {
      "active": false
    },
    "windows": [
      {
        "fullscreen": false,
        "height": 600,
        "resizable": true,
        "title": "sc",
        "width": 800
      }
    ]
  }
}

@siegerts
Copy link
Author

siegerts commented Aug 1, 2022

Also, for the sidecar above:

  1. go build sc.go
  2. and then rename to sc-x86_64-apple-darwin

@lucasfernog
Copy link
Member

@siegerts I couldn't reproduce it :( can you try creating a repo that I can use to reproduce it?

@siegerts
Copy link
Author

siegerts commented Aug 1, 2022

I'll try again from scratch but the example I'm using is only the above + the vite/Vue setup from the CLI prompts.

@siegerts
Copy link
Author

siegerts commented Aug 2, 2022

@lucasfernog do you mind sharing your set up, either here or on discord so I can see if I've diverged somehow. Thanks for the help.

@lucasfernog
Copy link
Member

I just used the sidecar example here in this repo and used your go code instead of the Nodejs app as sidecar.

@siegerts
Copy link
Author

siegerts commented Aug 2, 2022

@lucasfernog Got it to work :) . So my app name was the same as my sidecar name. Also, I didn't have the Rust portion in main.rs. The interpreted the docs as Running on JavaScript or Running on Rust. Thank you very much for your help and time. I appreciate it.

For reference -

use tauri::{
  api::process::{Command, CommandEvent},
  Manager,
};

fn main() {
  tauri::Builder::default()
    .setup(|app| {
      let window = app.get_window("main").unwrap();
      let (mut rx, mut child) = Command::new_sidecar("sc")
        .expect("failed to create `mem` binary command")
        .spawn()
        .expect("Failed to spawn sidecar");

      Ok(())
    })
    // .invoke_handler(tauri::generate_handler![my_custom_command])
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

@lucasfernog
Copy link
Member

The main.rs code is only needed if you need to run the sidecar from the Rust code. It should still work without it. Anyway I've added some validation in #4814 so this won't happen again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants