-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(weg): improve add/remove detection and windows previews
- Loading branch information
Showing
18 changed files
with
739 additions
and
653 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
142 changes: 71 additions & 71 deletions
142
src/apps/seelenweg/modules/item/infra/UserApplicationPreview.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,71 +1,71 @@ | ||
import { Icon } from '../../../../shared/components/Icon'; | ||
import { convertFileSrc, invoke } from '@tauri-apps/api/core'; | ||
import { listen } from '@tauri-apps/api/event'; | ||
import { Spin } from 'antd'; | ||
import { MouseEvent, useEffect, useReducer, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { LAZY_CONSTANTS } from '../../shared/utils/infra'; | ||
|
||
import { SelectOpenApp } from '../../shared/store/app'; | ||
|
||
import { HWND } from '../../shared/store/domain'; | ||
|
||
interface PreviewProps { | ||
hwnd: HWND; | ||
} | ||
|
||
export const UserApplicationPreview = ({ hwnd }: PreviewProps) => { | ||
const app = useSelector(SelectOpenApp(hwnd)); | ||
|
||
const imageUrl = convertFileSrc(`${LAZY_CONSTANTS.TEMP_FOLDER}${app?.process_hwnd || 0}.png`); | ||
|
||
const [imageSrc, setImageSrc] = useState<string | null>(imageUrl); | ||
const [_, forceUpdate] = useReducer((x) => x + 1, 0); | ||
|
||
useEffect(() => { | ||
const unlisten = listen(`weg-preview-update-${app?.process_hwnd || 0}`, () => { | ||
setImageSrc(imageUrl); | ||
forceUpdate(); | ||
}); | ||
return () => { | ||
unlisten.then((unlisten) => unlisten()).catch(console.error); | ||
}; | ||
}, []); | ||
|
||
const onClose = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
invoke('weg_close_app', { hwnd }); | ||
}; | ||
|
||
if (!app) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className="weg-item-preview" | ||
onClick={() => | ||
invoke('weg_toggle_window_state', { hwnd: app.hwnd || 0, exePath: app.execution_path }) | ||
} | ||
> | ||
<div className="weg-item-preview-topbar"> | ||
<div className="weg-item-preview-title">{app.title}</div> | ||
<div className="weg-item-preview-close" onClick={onClose}> | ||
<Icon iconName="IoClose" /> | ||
</div> | ||
</div> | ||
<div className="weg-item-preview-image-container"> | ||
{imageSrc ? ( | ||
<img | ||
className="weg-item-preview-image" | ||
src={imageSrc + `?${new Date().getTime()}`} | ||
onError={() => setImageSrc(null)} | ||
/> | ||
) : ( | ||
<Spin className="weg-item-preview-spin" /> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
import { Icon } from '../../../../shared/components/Icon'; | ||
import { convertFileSrc, invoke } from '@tauri-apps/api/core'; | ||
import { listen } from '@tauri-apps/api/event'; | ||
import { Spin } from 'antd'; | ||
import { MouseEvent, useEffect, useReducer, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { LAZY_CONSTANTS } from '../../shared/utils/infra'; | ||
|
||
import { SelectOpenApp } from '../../shared/store/app'; | ||
|
||
import { HWND } from '../../shared/store/domain'; | ||
|
||
interface PreviewProps { | ||
hwnd: HWND; | ||
} | ||
|
||
export const UserApplicationPreview = ({ hwnd }: PreviewProps) => { | ||
const app = useSelector(SelectOpenApp(hwnd)); | ||
|
||
const imageUrl = convertFileSrc(`${LAZY_CONSTANTS.TEMP_FOLDER}${app?.hwnd || 0}.png`); | ||
|
||
const [imageSrc, setImageSrc] = useState<string | null>(imageUrl); | ||
const [_, forceUpdate] = useReducer((x) => x + 1, 0); | ||
|
||
useEffect(() => { | ||
const unlisten = listen(`weg-preview-update-${app?.hwnd || 0}`, () => { | ||
setImageSrc(imageUrl); | ||
forceUpdate(); | ||
}); | ||
return () => { | ||
unlisten.then((unlisten) => unlisten()).catch(console.error); | ||
}; | ||
}, []); | ||
|
||
const onClose = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
invoke('weg_close_app', { hwnd }); | ||
}; | ||
|
||
if (!app) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className="weg-item-preview" | ||
onClick={() => | ||
invoke('weg_toggle_window_state', { hwnd: app.hwnd || 0, exePath: app.execution_path }) | ||
} | ||
> | ||
<div className="weg-item-preview-topbar"> | ||
<div className="weg-item-preview-title">{app.title}</div> | ||
<div className="weg-item-preview-close" onClick={onClose}> | ||
<Icon iconName="IoClose" /> | ||
</div> | ||
</div> | ||
<div className="weg-item-preview-image-container"> | ||
{imageSrc ? ( | ||
<img | ||
className="weg-item-preview-image" | ||
src={imageSrc + `?${new Date().getTime()}`} | ||
onError={() => setImageSrc(null)} | ||
/> | ||
) : ( | ||
<Spin className="weg-item-preview-spin" /> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; |
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,84 +1,84 @@ | ||
import { IRootState } from '../../../../../shared.interfaces'; | ||
import { Seelenweg } from '../../../../shared/schemas/Seelenweg'; | ||
import { | ||
SavedMediaItem, | ||
SavedPinnedApp, | ||
SavedSeparatorItem, | ||
StartMenuItem, | ||
SwItemType as SpecialItemType, | ||
} from '../../../../shared/schemas/SeelenWegItems'; | ||
import { modify } from 'readable-types'; | ||
|
||
export type HWND = number & {}; | ||
|
||
export { SpecialItemType }; | ||
|
||
export interface AppFromBackground { | ||
title: string; | ||
exe: string; | ||
execution_path: string; | ||
icon: string; | ||
icon_path: string; | ||
hwnd: HWND; | ||
process_hwnd: HWND; | ||
} | ||
|
||
export enum AppsSides { | ||
Left = 'left', | ||
Center = 'center', | ||
Right = 'right', | ||
Current = 'current', | ||
} | ||
|
||
export interface MediaSession { | ||
id: string; | ||
title: string; | ||
author: string; | ||
thumbnail: string | null; | ||
playing: boolean; | ||
default: boolean; | ||
} | ||
|
||
export type SwPinnedApp = modify< | ||
SavedPinnedApp, | ||
{ | ||
icon: string; | ||
title: string; | ||
opens: HWND[]; | ||
} | ||
>; | ||
|
||
export type SwTemporalApp = modify< | ||
SwPinnedApp, | ||
{ | ||
type: SpecialItemType.TemporalApp; | ||
} | ||
>; | ||
|
||
export type SwItem = SwPinnedApp | SwTemporalApp | SavedSeparatorItem | SavedMediaItem | StartMenuItem; | ||
|
||
export interface UIColors { | ||
background: string; | ||
foreground: string; | ||
accent_darkest: string; | ||
accent_darker: string; | ||
accent_dark: string; | ||
accent: string; | ||
accent_light: string; | ||
accent_lighter: string; | ||
accent_lightest: string; | ||
complement: string | null; | ||
} | ||
|
||
export interface RootState extends IRootState<Seelenweg> { | ||
itemsOnLeft: SwItem[]; | ||
itemsOnCenter: SwItem[]; | ||
itemsOnRight: SwItem[]; | ||
openApps: Record<HWND, AppFromBackground>; | ||
// ---------------------- | ||
focusedHandle: HWND; | ||
focusedExecutable: string; | ||
isOverlaped: boolean; | ||
mediaSessions: MediaSession[]; | ||
colors: UIColors; | ||
} | ||
import { IRootState } from '../../../../../shared.interfaces'; | ||
import { Seelenweg } from '../../../../shared/schemas/Seelenweg'; | ||
import { | ||
SavedMediaItem, | ||
SavedPinnedApp, | ||
SavedSeparatorItem, | ||
StartMenuItem, | ||
SwItemType as SpecialItemType, | ||
} from '../../../../shared/schemas/SeelenWegItems'; | ||
import { modify } from 'readable-types'; | ||
|
||
export type HWND = number & {}; | ||
|
||
export { SpecialItemType }; | ||
|
||
export interface AppFromBackground { | ||
title: string; | ||
exe: string; | ||
execution_path: string; | ||
icon: string; | ||
icon_path: string; | ||
hwnd: HWND; | ||
creator_hwnd: HWND; | ||
} | ||
|
||
export enum AppsSides { | ||
Left = 'left', | ||
Center = 'center', | ||
Right = 'right', | ||
Current = 'current', | ||
} | ||
|
||
export interface MediaSession { | ||
id: string; | ||
title: string; | ||
author: string; | ||
thumbnail: string | null; | ||
playing: boolean; | ||
default: boolean; | ||
} | ||
|
||
export type SwPinnedApp = modify< | ||
SavedPinnedApp, | ||
{ | ||
icon: string; | ||
title: string; | ||
opens: HWND[]; | ||
} | ||
>; | ||
|
||
export type SwTemporalApp = modify< | ||
SwPinnedApp, | ||
{ | ||
type: SpecialItemType.TemporalApp; | ||
} | ||
>; | ||
|
||
export type SwItem = SwPinnedApp | SwTemporalApp | SavedSeparatorItem | SavedMediaItem | StartMenuItem; | ||
|
||
export interface UIColors { | ||
background: string; | ||
foreground: string; | ||
accent_darkest: string; | ||
accent_darker: string; | ||
accent_dark: string; | ||
accent: string; | ||
accent_light: string; | ||
accent_lighter: string; | ||
accent_lightest: string; | ||
complement: string | null; | ||
} | ||
|
||
export interface RootState extends IRootState<Seelenweg> { | ||
itemsOnLeft: SwItem[]; | ||
itemsOnCenter: SwItem[]; | ||
itemsOnRight: SwItem[]; | ||
openApps: Record<HWND, AppFromBackground>; | ||
// ---------------------- | ||
focusedHandle: HWND; | ||
focusedExecutable: string; | ||
isOverlaped: boolean; | ||
mediaSessions: MediaSession[]; | ||
colors: UIColors; | ||
} |
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.