Revert "chore: define ELECTRON macro to tree shake code (#142)"

This reverts commit 74959ca54d.

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-07-20 00:17:42 +08:00
parent 9333f780ee
commit da2fcbb1cb
18 changed files with 30 additions and 32 deletions
+3 -3
View File
@@ -27,7 +27,7 @@ function App() {
useLayoutEffect(() => {
// Electron app register in app scope, but web app should register in window scope
if (ELECTRON) return
if (window.electron) return
const handleOpenSettings = (e) => {
if (e.key === "," && (e.metaKey || e.ctrlKey)) {
window.router.showSettings()
@@ -41,10 +41,10 @@ function App() {
}
}, [])
const windowsElectron = ELECTRON && getOS() === "Windows"
const windowsElectron = window.electron && getOS() === "Windows"
return (
<>
{ELECTRON && !windowsElectron && (
{window.electron && !windowsElectron && (
<div
className="drag-region absolute inset-x-0 top-0 h-12 shrink-0"
aria-hidden
@@ -6,8 +6,8 @@ export const Vibrancy: Component<
> = ({ className, children, ...rest }) => {
const opaqueSidebar = useUISettingKey("opaqueSidebar")
const canVibrancy =
ELECTRON &&
window.electron?.process.platform === "darwin" &&
window.electron &&
window.electron.process.platform === "darwin" &&
!opaqueSidebar
return (
@@ -34,7 +34,7 @@ const Wrapper: Component<{
className="absolute bottom-4 right-4 flex gap-3"
onClick={stopPropagation}
>
{ELECTRON && (
{!!window.electron && (
<ActionButton
tooltip="Download"
onClick={() => {
@@ -64,7 +64,7 @@ export const PreviewImageContent: FC<{
const handleContextMenu = useCallback(
(image: string, e: React.MouseEvent<HTMLImageElement>) => {
if (!ELECTRON) return
if (!window.electron) return
showNativeMenu(
[
+4 -2
View File
@@ -47,7 +47,9 @@ export const LoginButton: FC<LoginProps> = (props) => {
title: "Login",
id: "login",
content: () => (
<LoginModalContent runtime={ELECTRON ? "app" : "browser"} />
<LoginModalContent
runtime={window.electron ? "app" : "browser"}
/>
),
clickOutsideToDismiss: true,
})
@@ -124,7 +126,7 @@ export const ProfileButton: FC<LoginProps> = memo((props) => {
Preferences
</DropdownMenuItem>
<DropdownMenuSeparator />
{!ELECTRON && (
{!window.electron && (
<>
<DropdownMenuItem
onClick={() => {
+3 -3
View File
@@ -8,7 +8,7 @@ import { useMediaQuery } from "usehooks-ts"
const useDarkQuery = () => useMediaQuery("(prefers-color-scheme: dark)")
type ColorMode = "light" | "dark" | "system"
const darkAtom = !ELECTRON ?
const darkAtom = !window.electron ?
atomWithStorage(
getStorageNS("color-mode"),
"system" as ColorMode,
@@ -26,7 +26,7 @@ function useDarkWebApp() {
const mode = useAtomValue(darkAtom)
return mode === "dark" || (mode === "system" && systemIsDark)
}
export const useDark = ELECTRON ? useDarkElectron : useDarkWebApp
export const useDark = window.electron ? useDarkElectron : useDarkWebApp
const useSyncDarkElectron = () => {
const appIsDark = useDarkQuery()
@@ -50,7 +50,7 @@ const useSyncDarkWebApp = () => {
}, [colorMode, systemIsDark])
}
export const useSyncDark = ELECTRON ?
export const useSyncDark = window.electron ?
useSyncDarkElectron :
useSyncDarkWebApp
+1 -1
View File
@@ -1,6 +1,6 @@
import { useEffect, useRef } from "react"
const titleTemplate = ELECTRON ? `%s` : `%s | ${APP_NAME}`
const titleTemplate = window.electron ? `%s` : `%s | ${APP_NAME}`
export const useTitle = (title?: Nullable<string >) => {
const currentTitleRef = useRef(document.title)
+1 -1
View File
@@ -4,7 +4,7 @@ import { WEB_URL } from "@shared/constants"
export const LOGIN_CALLBACK_URL = `${WEB_URL}/redirect?app=follow`
export type LoginRuntime = "browser" | "app"
export const loginHandler = (provider: string, runtime: LoginRuntime = "app") => {
if (ELECTRON) {
if (window.electron) {
window.open(
`${WEB_URL}/login?provider=${provider}`,
)
+2 -2
View File
@@ -1,8 +1,8 @@
import { createClient } from "@egoist/tipc/renderer"
import type { Router } from "@main/tipc"
export const tipcClient = ELECTRON ?
window.electron && createClient<Router>({
export const tipcClient = window.electron ?
createClient<Router>({
ipcInvoke: window.electron.ipcRenderer.invoke,
}) :
null
+1 -1
View File
@@ -20,7 +20,7 @@ export const showNativeMenu = async (
el.dataset.contextMenuOpen = "true"
}
if (!ELECTRON) {
if (!window.electron) {
document.dispatchEvent(
new CustomEvent(CONTEXT_MENU_SHOW_EVENT_KEY, {
detail: {
+1 -1
View File
@@ -16,7 +16,7 @@ await initializeApp().finally(() => {
const $container = document.querySelector("#root") as HTMLElement
if (ELECTRON && getOS() === "Windows") {
if (window.electron && getOS() === "Windows") {
$container.style.borderRadius = "12px"
$container.style.overflow = "hidden"
$container.style.paddingTop = "24px"
@@ -214,7 +214,7 @@ const ListHeader: FC<{
const headerTitle = useFeedHeaderTitle()
const os = getOS()
const titleAtBottom = ELECTRON && os === "macOS"
const titleAtBottom = window.electron && os === "macOS"
const isInCollectionList = feedId === FEED_COLLECTION_LIST
const titleInfo = !!headerTitle && (
@@ -13,7 +13,7 @@ import { useMemo, useRef, useState } from "react"
import { ReactVirtuosoItemPlaceholder } from "../../components/ui/placeholder"
import type { UniversalItemProps } from "./types"
const ViewTag = ELECTRON ? "webview" : "iframe"
const ViewTag = window.electron ? "webview" : "iframe"
export function VideoItem({ entryId, entryPreview, translation }: UniversalItemProps) {
const entry = useEntry(entryId) || entryPreview
@@ -139,7 +139,7 @@ export function FeedColumn({ children }: PropsWithChildren) {
)
const normalStyle =
!ELECTRON || window.electron?.process.platform !== "darwin"
!window.electron || window.electron.process.platform !== "darwin"
const unreadByView = useUnreadByView()
@@ -43,7 +43,7 @@ export const SettingAppearance = () => {
label="Dark Mode"
checked={isDark}
onCheckedChange={(e) => {
if (ELECTRON) {
if (window.electron) {
tipcClient?.setAppearance(e ? "dark" : "light")
} else {
setDarkInWebApp(e ? "dark" : "light")
@@ -66,7 +66,7 @@ export const SettingAppearance = () => {
},
{
disabled:
!ELECTRON || !["macOS", "Linux"].includes(getOS()),
!window.electron || !["macOS", "Linux"].includes(getOS()),
label: "Dock Badge",
key: "showDockBadge",
onChange: (value) => setUISetting("showDockBadge", value),
@@ -81,7 +81,7 @@ export const SettingAppearance = () => {
type: "title",
value: "Content",
},
!!ELECTRON && Fonts,
!!window.electron && Fonts,
ShikiTheme,
{
@@ -114,7 +114,7 @@ export const SettingGeneral = () => {
]}
/>
{/* {ELECTRON&& (
{/* {window.electron && (
<SettingSwitch
label="Launch Follow at Login"
checked={loginSetting}
+1 -4
View File
@@ -55,10 +55,7 @@ export function Component() {
canClose={false}
clickOutsideToDismiss={false}
>
<LoginModalContent
canClose={false}
runtime={ELECTRON ? "app" : "browser"}
/>
<LoginModalContent canClose={false} runtime={window.electron ? "app" : "browser"} />
</DeclarativeModal>
</RootPortal>
)}
@@ -48,6 +48,6 @@ export const RootProviders: FC<PropsWithChildren> = ({ children }) => (
const Devtools = () => (
<>
{!ELECTRON && <ReactQueryDevtools buttonPosition="bottom-left" client={queryClient} />}
{!window.electron && <ReactQueryDevtools buttonPosition="bottom-left" client={queryClient} />}
</>
)
+1 -2
View File
@@ -1,8 +1,7 @@
import { createEventHandlers } from "@egoist/tipc/renderer"
import type { RendererHandlers } from "@main/renderer-handlers"
export const handlers = ELECTRON ?
window.electron &&
export const handlers = window.electron ?
createEventHandlers<RendererHandlers>({
on: (channel, callback) => {
if (!window.electron) return () => {}