Files
Firelink/src/utils/platform.ts
T
NimBold 6e85c0842f fix(startup): enforce keychain consent before credential access
Keep credential-store operations behind a per-process consent gate, prevent duplicate native grant requests, and defer legacy token migration until explicit consent. Harden the RTL/sidebar, custom window controls, bidi copy, and queue editor fixes.

Refs #17
2026-07-19 07:07:29 +03:30

57 lines
1.5 KiB
TypeScript

import { useEffect, useState } from 'react';
import type { PlatformInfo } from '../bindings/PlatformInfo';
import { invokeCommand as invoke } from '../ipc';
const fallback: PlatformInfo = {
os: 'unknown',
arch: 'unknown',
targetTriple: 'unknown',
portable: false
};
export const shouldUseCustomWindowControls = (os: string, userAgent: string): boolean => {
if (os === 'windows' || os === 'linux' || os === 'macos') return true;
if (os !== 'unknown') return false;
// Keep the custom titlebar visible while the native platform query is
// resolving. Mobile user agents are the only unknown targets that must not
// receive desktop window controls.
return !/Android|iPhone|iPad|iPod|Mobile/i.test(userAgent);
};
let cached: PlatformInfo | null = null;
let pending: Promise<PlatformInfo> | null = null;
export const getPlatformInfo = (): Promise<PlatformInfo> => {
if (cached) return Promise.resolve(cached);
if (!pending) {
pending = invoke('get_platform_info')
.then(info => {
cached = info;
return info;
})
.finally(() => {
pending = null;
});
}
return pending;
};
export const usePlatformInfo = () => {
const [platform, setPlatform] = useState<PlatformInfo>(cached ?? fallback);
useEffect(() => {
let active = true;
void getPlatformInfo()
.then(info => {
if (active) setPlatform(info);
})
.catch(() => undefined);
return () => {
active = false;
};
}, []);
return platform;
};