mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 23:37:15 +08:00
fix: using width atom for syncing app headers position (#7666)
may use global state to replace these sidebar state atoms fix AF-1109
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import 'setimmediate';
|
||||
import '@affine/component/theme/global.css';
|
||||
import '@affine/component/theme/theme.css';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
|
||||
import { ThemeProvider } from '@affine/component/theme-provider';
|
||||
import { appConfigProxy } from '@affine/core/hooks/use-app-config-storage';
|
||||
import { configureAppTabsHeaderModule } from '@affine/core/modules/app-tabs-header';
|
||||
import { configureElectronStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { performanceLogger } from '@affine/core/shared';
|
||||
import { apis, events } from '@affine/electron-api';
|
||||
import {
|
||||
configureGlobalStorageModule,
|
||||
Framework,
|
||||
@@ -26,9 +27,17 @@ const frameworkProvider = framework.provider();
|
||||
const logger = performanceLogger.namespace('shell');
|
||||
|
||||
function main() {
|
||||
appConfigProxy
|
||||
.getSync()
|
||||
.catch(() => console.error('failed to load app config'));
|
||||
const handleMaximized = (maximized: boolean | undefined) => {
|
||||
document.documentElement.dataset.maximized = String(maximized);
|
||||
};
|
||||
const handleFullscreen = (fullscreen: boolean | undefined) => {
|
||||
document.documentElement.dataset.fullscreen = String(fullscreen);
|
||||
};
|
||||
|
||||
apis?.ui.isMaximized().then(handleMaximized).catch(console.error);
|
||||
apis?.ui.isFullScreen().then(handleFullscreen).catch(console.error);
|
||||
events?.ui.onMaximized(handleMaximized);
|
||||
events?.ui.onFullScreen(handleFullscreen);
|
||||
}
|
||||
|
||||
function mountApp() {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { cssVar } from '@toeverything/theme';
|
||||
import { globalStyle, style } from '@vanilla-extract/css';
|
||||
import { createVar, globalStyle, style } from '@vanilla-extract/css';
|
||||
|
||||
export const sidebarOffsetVar = createVar();
|
||||
|
||||
export const root = style({
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
opacity: 1,
|
||||
display: 'flex',
|
||||
transition: 'opacity 0.1s',
|
||||
background: cssVar('backgroundPrimaryColor'),
|
||||
selectors: {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useAppSettingHelper } from '@affine/core/hooks/affine/use-app-setting-helper';
|
||||
import { AppTabsHeader } from '@affine/core/modules/app-tabs-header';
|
||||
import { apis, events } from '@affine/electron-api';
|
||||
import { events } from '@affine/electron-api';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import * as styles from './shell.css';
|
||||
|
||||
const useIsShellActive = () => {
|
||||
const [active, setActive] = useState(true);
|
||||
const [active, setActive] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const unsub = events?.ui.onTabShellViewActiveChange(active => {
|
||||
@@ -20,48 +20,9 @@ const useIsShellActive = () => {
|
||||
return active;
|
||||
};
|
||||
|
||||
const useTabsBoundingRect = () => {
|
||||
const [rect, setRect] = useState<{
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}>({
|
||||
x: environment.isDesktop && environment.isMacOs ? 80 : 0,
|
||||
y: 0,
|
||||
width: window.innerWidth,
|
||||
height: 52,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
let unsub: (() => void) | undefined;
|
||||
apis?.ui
|
||||
.getTabsBoundingRect()
|
||||
.then(rect => {
|
||||
if (rect) {
|
||||
setRect(rect);
|
||||
}
|
||||
unsub = events?.ui.onTabsBoundingRectChanged(rect => {
|
||||
if (rect) {
|
||||
setRect(rect);
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
return () => {
|
||||
unsub?.();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return rect;
|
||||
};
|
||||
|
||||
export function ShellRoot() {
|
||||
const active = useIsShellActive();
|
||||
const { appSettings } = useAppSettingHelper();
|
||||
const rect = useTabsBoundingRect();
|
||||
const translucent =
|
||||
environment.isDesktop &&
|
||||
environment.isMacOs &&
|
||||
@@ -72,15 +33,7 @@ export function ShellRoot() {
|
||||
data-translucent={translucent}
|
||||
data-active={active}
|
||||
>
|
||||
<AppTabsHeader
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: rect.y,
|
||||
left: rect.x,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
}}
|
||||
/>
|
||||
<AppTabsHeader mode="shell" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import type { MainEventRegister } from '../type';
|
||||
import {
|
||||
onActiveTabChanged,
|
||||
onTabAction,
|
||||
onTabsBoundingRectChanged,
|
||||
onTabShellViewActiveChange,
|
||||
onTabsStatusChange,
|
||||
onTabViewsMetaChanged,
|
||||
@@ -36,5 +35,4 @@ export const uiEvents = {
|
||||
onTabsStatusChange,
|
||||
onActiveTabChanged,
|
||||
onTabShellViewActiveChange,
|
||||
onTabsBoundingRectChanged,
|
||||
} satisfies Record<string, MainEventRegister>;
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
closeTab,
|
||||
getMainWindow,
|
||||
getOnboardingWindow,
|
||||
getTabsBoundingRect,
|
||||
getTabsStatus,
|
||||
getTabViewsMeta,
|
||||
getWorkbenchMeta,
|
||||
@@ -19,10 +18,10 @@ import {
|
||||
initAndShowMainWindow,
|
||||
isActiveTab,
|
||||
launchStage,
|
||||
pingAppLayoutReady,
|
||||
showDevTools,
|
||||
showTab,
|
||||
showTabContextMenu,
|
||||
updateTabsBoundingRect,
|
||||
updateWorkbenchMeta,
|
||||
} from '../windows-manager';
|
||||
import { getChallengeResponse } from './challenge';
|
||||
@@ -193,14 +192,8 @@ export const uiHandlers = {
|
||||
uiSubjects.onToggleRightSidebar$.next(tabId);
|
||||
}
|
||||
},
|
||||
getTabsBoundingRect: async () => {
|
||||
return getTabsBoundingRect();
|
||||
},
|
||||
updateTabsBoundingRect: async (
|
||||
e,
|
||||
rect: { x: number; y: number; width: number; height: number }
|
||||
) => {
|
||||
return updateTabsBoundingRect(e.sender, rect);
|
||||
pingAppLayoutReady: async e => {
|
||||
pingAppLayoutReady(e.sender);
|
||||
},
|
||||
showDevTools: async (_, ...args: Parameters<typeof showDevTools>) => {
|
||||
return showDevTools(...args);
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
type CookiesSetDetails,
|
||||
globalShortcut,
|
||||
Menu,
|
||||
type Rectangle,
|
||||
type View,
|
||||
type WebContents,
|
||||
WebContentsView,
|
||||
@@ -130,7 +129,6 @@ export class WebContentViewsManager {
|
||||
}
|
||||
|
||||
readonly tabViewsMeta$ = TabViewsMetaState.$;
|
||||
readonly tabsBoundingRect$ = new BehaviorSubject<Rectangle | null>(null);
|
||||
readonly appTabsUIReady$ = new BehaviorSubject(new Set<string>());
|
||||
|
||||
// all web views
|
||||
@@ -202,14 +200,6 @@ export class WebContentViewsManager {
|
||||
TabViewsMetaState.patch(patch);
|
||||
};
|
||||
|
||||
get tabsBoundingRect() {
|
||||
return this.tabsBoundingRect$.value;
|
||||
}
|
||||
|
||||
set tabsBoundingRect(rect: Rectangle | null) {
|
||||
this.tabsBoundingRect$.next(rect);
|
||||
}
|
||||
|
||||
get shellView() {
|
||||
return this.webViewsMap$.value.get('shell');
|
||||
}
|
||||
@@ -584,14 +574,6 @@ export class WebContentViewsManager {
|
||||
})
|
||||
);
|
||||
|
||||
disposables.push(
|
||||
this.tabsBoundingRect$.subscribe(rect => {
|
||||
if (rect) {
|
||||
this.reorderViews();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
app.on('ready', () => {
|
||||
// bind CMD/CTRL+1~8 to switch tabs
|
||||
// bind CMD/CTRL+9 to switch to the last tab
|
||||
@@ -745,6 +727,11 @@ export class WebContentViewsManager {
|
||||
});
|
||||
|
||||
this.resizeView(view);
|
||||
|
||||
view.webContents.on('did-finish-load', () => {
|
||||
this.resizeView(view);
|
||||
});
|
||||
|
||||
// reorder will add to main window when loaded
|
||||
this.reorderViews();
|
||||
|
||||
@@ -887,32 +874,12 @@ export const showDevTools = (id?: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const onTabsBoundingRectChanged = (
|
||||
fn: (rect: Rectangle | null) => void
|
||||
) => {
|
||||
const sub = WebContentViewsManager.instance.tabsBoundingRect$.subscribe(fn);
|
||||
return () => {
|
||||
sub.unsubscribe();
|
||||
};
|
||||
};
|
||||
|
||||
export const getTabsBoundingRect = () => {
|
||||
return WebContentViewsManager.instance.tabsBoundingRect;
|
||||
};
|
||||
|
||||
export const updateTabsBoundingRect = (wc: WebContents, rect: Rectangle) => {
|
||||
try {
|
||||
if (isActiveTab(wc)) {
|
||||
WebContentViewsManager.instance.tabsBoundingRect = rect;
|
||||
}
|
||||
const viewId = WebContentViewsManager.instance.getViewIdFromWebContentsId(
|
||||
wc.id
|
||||
);
|
||||
if (viewId) {
|
||||
WebContentViewsManager.instance.setTabUIReady(viewId);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
export const pingAppLayoutReady = (wc: WebContents) => {
|
||||
const viewId = WebContentViewsManager.instance.getViewIdFromWebContentsId(
|
||||
wc.id
|
||||
);
|
||||
if (viewId) {
|
||||
WebContentViewsManager.instance.setTabUIReady(viewId);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user