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

Electron provides a new-window event in the main thread, but TAURI does not. #10124

Open
ryusei-48 opened this issue Jun 26, 2024 · 0 comments
Open

Comments

@ryusei-48
Copy link

Describe the problem

The following are window-wide event handlers available in Electron that are triggered when a URL is opened in a new window.

 const electron = require("electron");
 const shell = electron.shell;
 const app = electron.app;
 const BrowserWindow = electron.BrowserWindow;
 
 app.on('ready', function() {
   const mainWindow = new BrowserWindow({width: 1600, height: 600});
   mainWindow.loadURL('file://' + __dirname + '/index.html');
 
   // New window event intercepted and opened in default browser (currently not concerned with page transitions)
   mainWindow.webContents.on('new-window', function(e,url){
     e.preventDefault();
     shell.openExternal(url);
   });
 });

However, these events have not yet been implemented in TAURI as far as I can tell.

This event is required when external HTML containing an a tag is loaded and displayed, for example, or when a URL is opened in an iframe (e.g., YouTube embedding) tag.
I am currently working on a project for such a situation.
It is inefficient to change the a tag in JavaScript and add the target="_blank" attribute each time.

Describe the solution you'd like

So I would like to add a new-window event in the listen function in the TAURI API.

import { listen, type Event } from '@tauri-apps/api/event';
import { Open } from '@tauri-apps/api/shell;

const winPosUnlisten = await listen("tauri://new-window", async (e: Event<{ url: string }>) => {
    e.preventDefault();
    await Open( url );
});

Alternatives considered

No response

Additional context

Please let me know if there are other existing methods that would be better.
Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant