Refactor platform detection to use import.meta.env.MODE instead of isPlatformNative()

This commit is contained in:
Keavon Chambers 2026-04-03 21:26:27 -07:00
parent 4360359d60
commit 55463fe0aa
7 changed files with 12 additions and 29 deletions

View File

@ -28,7 +28,6 @@
colorEquals, colorEquals,
gradientFirstColor, gradientFirstColor,
} from "/src/utility-functions/colors"; } from "/src/utility-functions/colors";
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
import type { FillChoice, MenuDirection, Color } from "/wrapper/pkg/graphite_wasm_wrapper"; import type { FillChoice, MenuDirection, Color } from "/wrapper/pkg/graphite_wasm_wrapper";
type PresetColors = "None" | "Black" | "White" | "Red" | "Yellow" | "Green" | "Cyan" | "Blue" | "Magenta"; type PresetColors = "None" | "Black" | "White" | "Red" | "Yellow" | "Green" | "Cyan" | "Blue" | "Magenta";
@ -404,7 +403,7 @@
// TODO: Replace this temporary usage of the browser eyedropper API, that only works in Chromium-based browsers, with the custom color sampler system used by the Eyedropper tool // TODO: Replace this temporary usage of the browser eyedropper API, that only works in Chromium-based browsers, with the custom color sampler system used by the Eyedropper tool
function eyedropperSupported(): boolean { function eyedropperSupported(): boolean {
// TODO: Implement support in the desktop app for OS-level color picking // TODO: Implement support in the desktop app for OS-level color picking
if (isPlatformNative()) return false; if (import.meta.env.MODE === "native") return false;
return window.EyeDropper !== undefined; return window.EyeDropper !== undefined;
} }

View File

@ -8,7 +8,6 @@
import type { SubscriptionsRouter } from "/src/subscriptions-router"; import type { SubscriptionsRouter } from "/src/subscriptions-router";
import { pasteFile } from "/src/utility-functions/files"; import { pasteFile } from "/src/utility-functions/files";
import { patchLayout } from "/src/utility-functions/widgets"; import { patchLayout } from "/src/utility-functions/widgets";
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
import type { EditorWrapper, Layout } from "/wrapper/pkg/graphite_wasm_wrapper"; import type { EditorWrapper, Layout } from "/wrapper/pkg/graphite_wasm_wrapper";
const subscriptions = getContext<SubscriptionsRouter>("subscriptions"); const subscriptions = getContext<SubscriptionsRouter>("subscriptions");
@ -50,7 +49,7 @@
</LayoutCol> </LayoutCol>
<LayoutCol class="bottom-message"> <LayoutCol class="bottom-message">
<TextLabel italic={true} disabled={true}> <TextLabel italic={true} disabled={true}>
{#if isPlatformNative()} {#if import.meta.env.MODE === "native"}
You are testing Release Candidate 4 of the 1.0 desktop release. Please regularly check Discord for the next testing build and report issues you encounter. You are testing Release Candidate 4 of the 1.0 desktop release. Please regularly check Discord for the next testing build and report issues you encounter.
{/if} {/if}
</TextLabel> </TextLabel>

View File

@ -4,7 +4,7 @@
import FieldInput from "/src/components/widgets/inputs/FieldInput.svelte"; import FieldInput from "/src/components/widgets/inputs/FieldInput.svelte";
import { PRESS_REPEAT_DELAY_MS, PRESS_REPEAT_INTERVAL_MS } from "/src/managers/input"; import { PRESS_REPEAT_DELAY_MS, PRESS_REPEAT_INTERVAL_MS } from "/src/managers/input";
import { browserVersion } from "/src/utility-functions/platform"; import { browserVersion } from "/src/utility-functions/platform";
import { evaluateMathExpression, isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper"; import { evaluateMathExpression } from "/wrapper/pkg/graphite_wasm_wrapper";
import type { ActionShortcut, EditorWrapper, NumberInputIncrementBehavior, NumberInputMode } from "/wrapper/pkg/graphite_wasm_wrapper"; import type { ActionShortcut, EditorWrapper, NumberInputIncrementBehavior, NumberInputMode } from "/wrapper/pkg/graphite_wasm_wrapper";
const BUTTONS_LEFT = 0b0000_0001; const BUTTONS_LEFT = 0b0000_0001;
@ -391,7 +391,7 @@
// Because "mousemove" (and similarly, the "pointermove" event we use) is defined as not being a user-initiated "engagement gesture" event, // Because "mousemove" (and similarly, the "pointermove" event we use) is defined as not being a user-initiated "engagement gesture" event,
// Safari never lets us to enter pointer lock while the mouse button is held down and we are awaiting movement to begin dragging the slider. // Safari never lets us to enter pointer lock while the mouse button is held down and we are awaiting movement to begin dragging the slider.
const isSafari = browserVersion().toLowerCase().includes("safari"); const isSafari = browserVersion().toLowerCase().includes("safari");
const usePointerLock = !isSafari && !isPlatformNative(); const usePointerLock = !isSafari && import.meta.env.MODE !== "native";
// On Safari, we use a workaround involving an alternative strategy where we hide the cursor while it's within the web page // On Safari, we use a workaround involving an alternative strategy where we hide the cursor while it's within the web page
// (but we can't hide it when it ventures outside the page), taking advantage of a separate (helpful) Safari bug where it // (but we can't hide it when it ventures outside the page), taking advantage of a separate (helpful) Safari bug where it
@ -404,7 +404,7 @@
// Enter dragging state // Enter dragging state
if (usePointerLock) target.requestPointerLock(); if (usePointerLock) target.requestPointerLock();
if (isPlatformNative()) { if (import.meta.env.MODE === "native") {
editor.appWindowPointerLock(); editor.appWindowPointerLock();
} }
initialValueBeforeDragging = value; initialValueBeforeDragging = value;

View File

@ -10,7 +10,6 @@
import type { AppWindowStore } from "/src/stores/app-window"; import type { AppWindowStore } from "/src/stores/app-window";
import type { DialogStore } from "/src/stores/dialog"; import type { DialogStore } from "/src/stores/dialog";
import type { TooltipStore } from "/src/stores/tooltip"; import type { TooltipStore } from "/src/stores/tooltip";
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
const dialog = getContext<DialogStore>("dialog"); const dialog = getContext<DialogStore>("dialog");
const tooltip = getContext<TooltipStore>("tooltip"); const tooltip = getContext<TooltipStore>("tooltip");
@ -29,7 +28,7 @@
{#if $tooltip.visible} {#if $tooltip.visible}
<Tooltip /> <Tooltip />
{/if} {/if}
{#if isPlatformNative() && new Date() > new Date("2026-04-30")} {#if import.meta.env.MODE === "native" && new Date() > new Date("2026-04-30")}
<LayoutCol class="release-candidate-expiry"> <LayoutCol class="release-candidate-expiry">
<TextLabel> <TextLabel>
<p> <p>

View File

@ -10,7 +10,6 @@
import type { SubscriptionsRouter } from "/src/subscriptions-router"; import type { SubscriptionsRouter } from "/src/subscriptions-router";
import { patchLayout } from "/src/utility-functions/widgets"; import { patchLayout } from "/src/utility-functions/widgets";
import type { EditorWrapper, Layout } from "/wrapper/pkg/graphite_wasm_wrapper"; import type { EditorWrapper, Layout } from "/wrapper/pkg/graphite_wasm_wrapper";
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
const keyboardLockApiSupported = navigator.keyboard !== undefined && "lock" in navigator.keyboard; const keyboardLockApiSupported = navigator.keyboard !== undefined && "lock" in navigator.keyboard;
@ -22,8 +21,8 @@
let menuBarLayout: Layout = []; let menuBarLayout: Layout = [];
$: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen || (isPlatformNative() && $appWindow.fullscreen); $: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen || (import.meta.env.MODE === "native" && $appWindow.fullscreen);
$: isFullscreen = isPlatformNative() ? $appWindow.fullscreen : $fullscreen.windowFullscreen; $: isFullscreen = import.meta.env.MODE === "native" ? $appWindow.fullscreen : $fullscreen.windowFullscreen;
// On Mac, the menu bar height needs to be scaled by the inverse of the UI scale to fit its native window buttons // On Mac, the menu bar height needs to be scaled by the inverse of the UI scale to fit its native window buttons
$: height = $appWindow.platform === "Mac" ? 28 * (1 / $appWindow.uiScale) : 28; $: height = $appWindow.platform === "Mac" ? 28 * (1 / $appWindow.uiScale) : 28;
@ -59,7 +58,7 @@
: undefined} : undefined}
tooltipShortcut={$tooltip.fullscreenShortcut} tooltipShortcut={$tooltip.fullscreenShortcut}
on:click={() => { on:click={() => {
if (isPlatformNative()) editor.appWindowFullscreen(); if (import.meta.env.MODE === "native") editor.appWindowFullscreen();
else ($fullscreen.windowFullscreen ? exitFullscreen : enterFullscreen)(); else ($fullscreen.windowFullscreen ? exitFullscreen : enterFullscreen)();
}} }}
> >

View File

@ -7,7 +7,6 @@ import { pasteFile } from "/src/utility-functions/files";
import { makeKeyboardModifiersBitfield, textInputCleanup, getLocalizedScanCode } from "/src/utility-functions/keyboard-entry"; import { makeKeyboardModifiersBitfield, textInputCleanup, getLocalizedScanCode } from "/src/utility-functions/keyboard-entry";
import { operatingSystem } from "/src/utility-functions/platform"; import { operatingSystem } from "/src/utility-functions/platform";
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper"; import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
const BUTTON_LEFT = 0; const BUTTON_LEFT = 0;
const BUTTON_MIDDLE = 1; const BUTTON_MIDDLE = 1;
@ -36,9 +35,9 @@ export async function shouldRedirectKeyboardEventToBackend(e: KeyboardEvent, dia
const accelKey = operatingSystem() === "Mac" ? e.metaKey : e.ctrlKey; const accelKey = operatingSystem() === "Mac" ? e.metaKey : e.ctrlKey;
// Cut, copy, and paste is handled in the backend on desktop // Cut, copy, and paste is handled in the backend on desktop
if (isPlatformNative() && accelKey && ["KeyX", "KeyC", "KeyV"].includes(key)) return true; if (import.meta.env.MODE === "native" && accelKey && ["KeyX", "KeyC", "KeyV"].includes(key)) return true;
// But on web, we want to not redirect paste // But on web, we want to not redirect paste
if (!isPlatformNative() && key === "KeyV" && accelKey) return false; if (import.meta.env.MODE !== "native" && key === "KeyV" && accelKey) return false;
// Don't redirect user input from text entry into HTML elements // Don't redirect user input from text entry into HTML elements
if (targetIsTextField(e.target || undefined) && key !== "Escape" && !(accelKey && ["Enter", "NumpadEnter"].includes(key))) return false; if (targetIsTextField(e.target || undefined) && key !== "Escape" && !(accelKey && ["Enter", "NumpadEnter"].includes(key))) return false;
@ -57,7 +56,7 @@ export async function shouldRedirectKeyboardEventToBackend(e: KeyboardEvent, dia
if (window.document.querySelector("[data-floating-menu-content]")) return false; if (window.document.querySelector("[data-floating-menu-content]")) return false;
// Web-only keyboard shortcuts // Web-only keyboard shortcuts
if (!isPlatformNative()) { if (import.meta.env.MODE !== "native") {
// Don't redirect a fullscreen request, but process it immediately instead // Don't redirect a fullscreen request, but process it immediately instead
if (((operatingSystem() !== "Mac" && key === "F11") || (operatingSystem() === "Mac" && e.ctrlKey && e.metaKey && key === "KeyF")) && e.type === "keydown" && !e.repeat) { if (((operatingSystem() !== "Mac" && key === "F11") || (operatingSystem() === "Mac" && e.ctrlKey && e.metaKey && key === "KeyF")) && e.type === "keydown" && !e.repeat) {
e.preventDefault(); e.preventDefault();

View File

@ -909,18 +909,6 @@ impl EditorWrapper {
// Static functions callable from JavaScript without an Editor instance // Static functions callable from JavaScript without an Editor instance
// ==================================================================== // ====================================================================
#[wasm_bindgen(js_name = isPlatformNative)]
pub fn is_platform_native() -> bool {
#[cfg(feature = "native")]
{
true
}
#[cfg(not(feature = "native"))]
{
false
}
}
#[wasm_bindgen(js_name = evaluateMathExpression)] #[wasm_bindgen(js_name = evaluateMathExpression)]
pub fn evaluate_math_expression(expression: &str) -> Option<f64> { pub fn evaluate_math_expression(expression: &str) -> Option<f64> {
let value = math_parser::evaluate(expression) let value = math_parser::evaluate(expression)