Skip to content

Commit

Permalink
enh(weg): improve add/remove detection and windows previews
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Aug 29, 2024
1 parent 36b0942 commit 362465e
Show file tree
Hide file tree
Showing 18 changed files with 739 additions and 653 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
- new custom virtual desktop implementation.
- shortcut to toggle debug mode on hitboxes (Control + Win + Alt + H).

### enhancements
- remove black borders of windows previews on dock.
- improve uwp app manage on dock/taskbar.

### refactor
- add strategy pattern to virtual desktops.

### fix
- topbar hitbox rect on auto hide equals to on-overlap.
- bad matching fullscreen apps.
- suspended process (ex: Settings) been shown on dock.
- uwp icons not loading correctly.

## [1.9.11]
### features
Expand Down
142 changes: 71 additions & 71 deletions src/apps/seelenweg/modules/item/infra/UserApplicationPreview.tsx
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>
);
};
168 changes: 84 additions & 84 deletions src/apps/seelenweg/modules/shared/store/domain.ts
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;
}
6 changes: 0 additions & 6 deletions src/apps/seelenweg/modules/shared/store/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ export async function registerStoreEvents() {
store.dispatch(RootActions.updateOpenAppInfo(item));
});

await listenGlobal<AppFromBackground>('replace-open-app', async (event) => {
const item = (await cleanItems([event.payload]))[0]!;
store.dispatch(RootActions.addOpenApp(item));
store.dispatch(RootActions.removeOpenApp(item.process_hwnd));
});

await listenGlobal<HWND>('set-focused-handle', (event) => {
store.dispatch(RootActions.setFocusedHandle(event.payload));
});
Expand Down
Loading

0 comments on commit 362465e

Please sign in to comment.