plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

[feat] OS info as constants and not async functions

Open wscourge opened this issue 1 year ago • 2 comments

Describe the problem

Given a scarce support for the top-level await, I'd like to have, at the very least, the osType exposed as a constant in the JS API (and not an async function, as it is now).

Describe the solution you'd like

Add this

import { OS_TYPE } from '@tauri-apps/api/os';

and don't make me call this anymore:

import { type } from '@tauri-apps/api/os';
const osType = await type();

Alternatives considered

For other people struggling with it at the moment: use the following ugly, bad, breaking, etc hack on the client side: window.navigator.userAgent.includes("Macintosh;").

Additional context

Electron does it.

It can easily come as a non-breaking change (supplementary to the current async type, arch and such). No need to deprecate the other stuff for a long time, too.

wscourge avatar May 19 '24 15:05 wscourge

We explicitly removed all variables from the API in v2 and stopped adding them to v1, because we got many many reports about issues with ssr-first frameworks (nextjs, nuxt, sveltekit, etc) because of variables (because they need access to the navigator or window variable).

I'm not ruling it out, just warning you that this is pretty unlikely as of now. As an idea for exploration, instead of using the typical ipc, using eval/init_scripts may work (with the caveats it has).

FabianLars avatar May 19 '24 18:05 FabianLars

We can't break the API in v1 so I will just consider v2 for this issue and transfer the issue to plugins-workspace.

we can't make them constants, as Fabian said, will need to access window or navigator variables and will make issues in SSR frameworks, but we can make these functions not async at least, you will also be able to directly access them using window.__TAURI_OS_PLUGIN_INTERNALS__.eol if you prefer but I wouldn't rely on these internals.

amrbashir avatar May 20 '24 16:05 amrbashir