Skip to content

Commit

Permalink
Merge pull request tangly1024#2273 from tangly1024/fix/notion-config-…
Browse files Browse the repository at this point in the history
…live2d

修复 Live2D宠物读取配置失败的问题
  • Loading branch information
tangly1024 committed Apr 9, 2024
2 parents 214b40f + 1595992 commit 9fff892
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions components/Live2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export default function Live2D() {
const { theme, switchTheme } = useGlobal()
const showPet = JSON.parse(siteConfig('WIDGET_PET'))
const petLink = siteConfig('WIDGET_PET_LINK')
const petSwitchTheme = siteConfig('WIDGET_PET_SWITCH_THEME')

useEffect(() => {
if (showPet && !isMobile()) {
Promise.all([
loadExternalResource('https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/live2d.min.js', 'js')
]).then((e) => {
loadExternalResource(
'https://cdn.jsdelivr.net/gh/stevenjoezhang/live2d-widget@latest/live2d.min.js',
'js'
)
]).then(e => {
if (typeof window?.loadlive2d !== 'undefined') {
// https://github.com/xiazeyu/live2d-widget-models
try {
Expand All @@ -31,7 +35,7 @@ export default function Live2D() {
}, [theme])

function handleClick() {
if (JSON.parse(siteConfig('WIDGET_PET_SWITCH_THEME'))) {
if (petSwitchTheme) {
switchTheme()
}
}
Expand All @@ -40,9 +44,15 @@ export default function Live2D() {
return <></>
}

return <canvas id="live2d" width="280" height="250" onClick={handleClick}
className="cursor-grab"
onMouseDown={(e) => e.target.classList.add('cursor-grabbing')}
onMouseUp={(e) => e.target.classList.remove('cursor-grabbing')}
return (
<canvas
id='live2d'
width='280'
height='250'
onClick={handleClick}
className='cursor-grab'
onMouseDown={e => e.target.classList.add('cursor-grabbing')}
onMouseUp={e => e.target.classList.remove('cursor-grabbing')}
/>
)
}

0 comments on commit 9fff892

Please sign in to comment.