Refactor platform detection to use import.meta.env.MODE instead of isPlatformNative()
This commit is contained in:
parent
4360359d60
commit
55463fe0aa
|
|
@ -28,7 +28,6 @@
|
|||
colorEquals,
|
||||
gradientFirstColor,
|
||||
} from "/src/utility-functions/colors";
|
||||
import { isPlatformNative } 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";
|
||||
|
|
@ -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
|
||||
function eyedropperSupported(): boolean {
|
||||
// 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
import type { SubscriptionsRouter } from "/src/subscriptions-router";
|
||||
import { pasteFile } from "/src/utility-functions/files";
|
||||
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";
|
||||
|
||||
const subscriptions = getContext<SubscriptionsRouter>("subscriptions");
|
||||
|
|
@ -50,7 +49,7 @@
|
|||
</LayoutCol>
|
||||
<LayoutCol class="bottom-message">
|
||||
<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.
|
||||
{/if}
|
||||
</TextLabel>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
import FieldInput from "/src/components/widgets/inputs/FieldInput.svelte";
|
||||
import { PRESS_REPEAT_DELAY_MS, PRESS_REPEAT_INTERVAL_MS } from "/src/managers/input";
|
||||
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";
|
||||
|
||||
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,
|
||||
// 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 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
|
||||
// (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
|
||||
if (usePointerLock) target.requestPointerLock();
|
||||
if (isPlatformNative()) {
|
||||
if (import.meta.env.MODE === "native") {
|
||||
editor.appWindowPointerLock();
|
||||
}
|
||||
initialValueBeforeDragging = value;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
import type { AppWindowStore } from "/src/stores/app-window";
|
||||
import type { DialogStore } from "/src/stores/dialog";
|
||||
import type { TooltipStore } from "/src/stores/tooltip";
|
||||
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
|
||||
const dialog = getContext<DialogStore>("dialog");
|
||||
const tooltip = getContext<TooltipStore>("tooltip");
|
||||
|
|
@ -29,7 +28,7 @@
|
|||
{#if $tooltip.visible}
|
||||
<Tooltip />
|
||||
{/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">
|
||||
<TextLabel>
|
||||
<p>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
import type { SubscriptionsRouter } from "/src/subscriptions-router";
|
||||
import { patchLayout } from "/src/utility-functions/widgets";
|
||||
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;
|
||||
|
||||
|
|
@ -22,8 +21,8 @@
|
|||
|
||||
let menuBarLayout: Layout = [];
|
||||
|
||||
$: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen || (isPlatformNative() && $appWindow.fullscreen);
|
||||
$: isFullscreen = isPlatformNative() ? $appWindow.fullscreen : $fullscreen.windowFullscreen;
|
||||
$: showFullscreenButton = $appWindow.platform === "Web" || $fullscreen.windowFullscreen || (import.meta.env.MODE === "native" && $appWindow.fullscreen);
|
||||
$: 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
|
||||
$: height = $appWindow.platform === "Mac" ? 28 * (1 / $appWindow.uiScale) : 28;
|
||||
|
||||
|
|
@ -59,7 +58,7 @@
|
|||
: undefined}
|
||||
tooltipShortcut={$tooltip.fullscreenShortcut}
|
||||
on:click={() => {
|
||||
if (isPlatformNative()) editor.appWindowFullscreen();
|
||||
if (import.meta.env.MODE === "native") editor.appWindowFullscreen();
|
||||
else ($fullscreen.windowFullscreen ? exitFullscreen : enterFullscreen)();
|
||||
}}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import { pasteFile } from "/src/utility-functions/files";
|
|||
import { makeKeyboardModifiersBitfield, textInputCleanup, getLocalizedScanCode } from "/src/utility-functions/keyboard-entry";
|
||||
import { operatingSystem } from "/src/utility-functions/platform";
|
||||
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
import { isPlatformNative } from "/wrapper/pkg/graphite_wasm_wrapper";
|
||||
|
||||
const BUTTON_LEFT = 0;
|
||||
const BUTTON_MIDDLE = 1;
|
||||
|
|
@ -36,9 +35,9 @@ export async function shouldRedirectKeyboardEventToBackend(e: KeyboardEvent, dia
|
|||
const accelKey = operatingSystem() === "Mac" ? e.metaKey : e.ctrlKey;
|
||||
|
||||
// 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
|
||||
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
|
||||
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;
|
||||
|
||||
// Web-only keyboard shortcuts
|
||||
if (!isPlatformNative()) {
|
||||
if (import.meta.env.MODE !== "native") {
|
||||
// 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) {
|
||||
e.preventDefault();
|
||||
|
|
|
|||
|
|
@ -909,18 +909,6 @@ impl EditorWrapper {
|
|||
// 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)]
|
||||
pub fn evaluate_math_expression(expression: &str) -> Option<f64> {
|
||||
let value = math_parser::evaluate(expression)
|
||||
|
|
|
|||
Loading…
Reference in New Issue