forked from toeverything/AFFiNE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(electron): move electron-api to framework (toeverything#8601)
fix AF-1394
- Loading branch information
Showing
81 changed files
with
779 additions
and
558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { DesktopApiService } from '@affine/core/modules/desktop-api/service'; | ||
import { useService } from '@toeverything/infra'; | ||
import { useTheme } from 'next-themes'; | ||
import { useRef } from 'react'; | ||
|
||
export const DesktopThemeSync = () => { | ||
const { theme } = useTheme(); | ||
const lastThemeRef = useRef(theme); | ||
const onceRef = useRef(false); | ||
|
||
const handler = useService(DesktopApiService).api.handler; | ||
|
||
if (lastThemeRef.current !== theme || !onceRef.current) { | ||
if (BUILD_CONFIG.isElectron && theme) { | ||
handler.ui | ||
.handleThemeChange(theme as 'dark' | 'light' | 'system') | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
lastThemeRef.current = theme; | ||
onceRef.current = true; | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,3 +94,5 @@ export const sharedStorage = { | |
globalState, | ||
globalCache, | ||
}; | ||
|
||
export type SharedStorage = typeof sharedStorage; |
23 changes: 1 addition & 22 deletions
23
packages/frontend/component/src/components/theme-provider/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,12 @@ | ||
import { apis } from '@affine/electron-api'; | ||
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes'; | ||
import { ThemeProvider as NextThemeProvider } from 'next-themes'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { memo, useRef } from 'react'; | ||
|
||
const themes = ['dark', 'light']; | ||
|
||
const DesktopThemeSync = memo(function DesktopThemeSync() { | ||
const { theme } = useTheme(); | ||
const lastThemeRef = useRef(theme); | ||
const onceRef = useRef(false); | ||
if (lastThemeRef.current !== theme || !onceRef.current) { | ||
if (BUILD_CONFIG.isElectron && theme) { | ||
apis?.ui | ||
.handleThemeChange(theme as 'dark' | 'light' | 'system') | ||
.catch(err => { | ||
console.error(err); | ||
}); | ||
} | ||
lastThemeRef.current = theme; | ||
onceRef.current = true; | ||
} | ||
return null; | ||
}); | ||
|
||
export const ThemeProvider = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<NextThemeProvider themes={themes} enableSystem={true}> | ||
{children} | ||
<DesktopThemeSync /> | ||
</NextThemeProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.