This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-11 18:12:17 -05:00
1 parent 5f3ef71fa5
commit 41cf2d3c7e
9 files changed
+595 -361

No files matched your search

@@ -50,7 +50,7 @@
let canGoForward = $state(false);
let chromeQuality = $state<'low' | 'balanced' | 'crisp' | null>(null);
let chromeDeviceMode = $state<DeviceMode>('auto');
let chromeMobileViewport = $state<MobileViewport>({ width: 390, height: 844 });
let chromeMobileViewport = $state<MobileViewport | undefined>();
let qualityMenuOpen = $state(false);
let qualityMenuAnchor = $state<HTMLElement>();
@@ -72,7 +72,17 @@
function setChromeMobileDimension(key: keyof MobileViewport, value: number) {
if (!Number.isFinite(value) || value <= 0) return;
chromeMobileViewport = { ...chromeMobileViewport, [key]: Math.round(value) };
chromeMobileViewport = {
...(chromeMobileViewport ?? { width: 390, height: 844 }),
[key]: Math.round(value)
};
chromeEl?.setMobileViewport(chromeMobileViewport);
}
function setChromeMobileViewport(enabled: boolean) {
chromeMobileViewport = enabled
? (chromeMobileViewport ?? { width: 390, height: 844 })
: undefined;
chromeEl?.setMobileViewport(chromeMobileViewport);
}
@@ -288,31 +298,43 @@
{/each}
</div>
{#if chromeDeviceMode === 'mobile'}
<div
class="mt-1.5 flex items-center gap-1 text-[0.625rem] text-gray-500 dark:text-gray-400"
<label
class="mt-1.5 flex items-center justify-between gap-2 px-1 text-[0.625rem] text-gray-500 dark:text-gray-400"
>
<span>{$t('browser.deviceFixedViewport')}</span>
<input
type="number"
min="1"
value={chromeMobileViewport.width}
aria-label={$t('browser.deviceWidth')}
use:tooltip={$t('browser.deviceWidthHint')}
onchange={(event) =>
setChromeMobileDimension('width', event.currentTarget.valueAsNumber)}
class="h-6 min-w-0 rounded-md border border-gray-200 bg-gray-100 px-1 text-center dark:border-white/8 dark:bg-white/6"
type="checkbox"
checked={Boolean(chromeMobileViewport)}
onchange={(event) => setChromeMobileViewport(event.currentTarget.checked)}
/>
<span>×</span>
<input
type="number"
min="1"
value={chromeMobileViewport.height}
aria-label={$t('browser.deviceHeight')}
use:tooltip={$t('browser.deviceHeightHint')}
onchange={(event) =>
setChromeMobileDimension('height', event.currentTarget.valueAsNumber)}
class="h-6 min-w-0 rounded-md border border-gray-200 bg-gray-100 px-1 text-center dark:border-white/8 dark:bg-white/6"
/>
</div>
</label>
{#if chromeMobileViewport}
<div
class="mt-1.5 flex items-center gap-1 text-[0.625rem] text-gray-500 dark:text-gray-400"
>
<input
type="number"
min="1"
value={chromeMobileViewport.width}
aria-label={$t('browser.deviceWidth')}
use:tooltip={$t('browser.deviceWidthHint')}
onchange={(event) =>
setChromeMobileDimension('width', event.currentTarget.valueAsNumber)}
class="h-6 min-w-0 rounded-md border border-gray-200 bg-gray-100 px-1 text-center dark:border-white/8 dark:bg-white/6"
/>
<span>×</span>
<input
type="number"
min="1"
value={chromeMobileViewport.height}
aria-label={$t('browser.deviceHeight')}
use:tooltip={$t('browser.deviceHeightHint')}
onchange={(event) =>
setChromeMobileDimension('height', event.currentTarget.valueAsNumber)}
class="h-6 min-w-0 rounded-md border border-gray-200 bg-gray-100 px-1 text-center dark:border-white/8 dark:bg-white/6"
/>
</div>
{/if}
{/if}
</div>
</DropdownMenu>
@@ -14,7 +14,7 @@
onstate: (state: BrowserState) => void;
onstatus: (status: string, message?: string, mode?: 'proxy') => void;
onquality: (quality: 'low' | 'balanced' | 'crisp' | null) => void;
ondevicemode: (mode: DeviceMode, viewport: MobileViewport) => void;
ondevicemode: (mode: DeviceMode, viewport?: MobileViewport) => void;
}
type DeviceMode = 'auto' | 'desktop' | 'mobile';
@@ -69,7 +69,7 @@
let mobile = $state(false);
let quality = $state<'low' | 'balanced' | 'crisp'>('balanced');
let deviceMode = $state<DeviceMode>('auto');
let mobileViewport = $state<MobileViewport>({ width: 390, height: 844 });
let mobileViewport = $state<MobileViewport | undefined>();
let deviceProfile: DeviceProfile | undefined;
let editableRegions = $state<EditableRegion[]>([]);
let lastViewport = '';
@@ -175,6 +175,7 @@
Number.isFinite(message.mobile_viewport?.height)
)
mobileViewport = message.mobile_viewport;
else mobileViewport = undefined;
onquality(managed ? quality : null);
ondevicemode(deviceMode, mobileViewport);
if (active) focusBrowser();
@@ -324,7 +325,7 @@
height
};
if (viewportTimer) clearTimeout(viewportTimer);
if (debounce || (mobile && document.activeElement === keyboardAntenna)) {
if (debounce || (isMobileInput() && document.activeElement === keyboardAntenna)) {
viewportTimer = setTimeout(() => void sendViewport(), 150);
} else {
void sendViewport();
@@ -342,7 +343,7 @@
quality,
device,
device_mode: deviceMode,
mobile_viewport: mobileViewport,
mobile_viewport: mobileViewport ?? null,
force
});
}
@@ -370,7 +371,7 @@
}
function focusAntenna() {
if (!managed || !mobile) return;
if (!isMobileInput()) return;
keepKeyboardFocus = true;
resetKeyboardAntenna();
keyboardAntenna?.focus({ preventScroll: true });
@@ -388,7 +389,7 @@
}
function isEditableTouch(event: PointerEvent) {
if (!managed || !mobile) return false;
if (!isMobileInput()) return false;
const point = coordinates(event);
return editableRegions.some(
(region) =>
@@ -438,7 +439,7 @@
}
function pointer(event: PointerEvent, type: 'move' | 'down' | 'up' | 'cancel') {
if (event.pointerType === 'touch') {
if (isMobileInput()) {
touch(event, type === 'down' ? 'start' : type === 'up' ? 'end' : type);
return;
}
@@ -529,7 +530,7 @@
}
function beforeInput(event: InputEvent) {
if (!managed || !mobile || composition) return;
if (!isMobileInput() || composition) return;
const text = event.data || '';
if (suppressText && text === suppressText) {
event.preventDefault();
@@ -598,13 +599,16 @@
ondevicemode(deviceMode, mobileViewport);
resize();
}
export function setMobileViewport(nextViewport: MobileViewport) {
if (nextViewport.width <= 0 || nextViewport.height <= 0) return;
export function setMobileViewport(nextViewport?: MobileViewport) {
if (nextViewport && (nextViewport.width <= 0 || nextViewport.height <= 0)) return;
mobileViewport = nextViewport;
lastViewport = '';
ondevicemode(deviceMode, mobileViewport);
resize();
}
function isMobileInput() {
return managed && (deviceMode === 'mobile' || (deviceMode === 'auto' && mobile));
}
function focusBrowser() {
if (!ready) return;
send({ type: 'focus' });
@@ -655,7 +659,7 @@
oncompositionend={(event) => {
composition = false;
const text = event.data || '';
if (managed && mobile && text) {
if (isMobileInput() && text) {
suppressText = text;
send({ type: 'text', text });
queueMicrotask(() => {
@@ -670,7 +674,7 @@
></textarea>
<canvas
bind:this={canvas}
tabindex={managed && mobile ? -1 : 0}
tabindex={isMobileInput() ? -1 : 0}
onfocus={canvasFocus}
onpointermove={(event) => pointer(event, 'move')}
onpointerdown={(event) => pointer(event, 'down')}
@@ -43,6 +43,10 @@
onHomeNewChat?: () => void;
onHomeNewTerminal?: () => void;
onHomeNewBrowser?: () => void;
onHomeSplit?: (direction: 'horizontal' | 'vertical') => void;
onHomeCloseGroup?: () => void;
homeSplitDirection?: 'horizontal' | 'vertical';
homeSplitActive?: boolean;
}
let {
@@ -55,7 +59,11 @@
onHomeClose,
onHomeNewChat,
onHomeNewTerminal,
onHomeNewBrowser
onHomeNewBrowser,
onHomeSplit,
onHomeCloseGroup,
homeSplitDirection = 'horizontal',
homeSplitActive = false
}: Props = $props();
let tabsEl: HTMLDivElement | undefined = $state();
@@ -119,6 +127,7 @@
function handleCloseGroup(e: Event) {
e.stopPropagation();
if (home) return onHomeCloseGroup?.();
closeGroup(group.id);
}
@@ -299,15 +308,20 @@
});
const splitMenuItems = $derived.by(() => {
const direction = $activeWorkspace?.splitDirection ?? 'horizontal';
const direction = home
? homeSplitDirection
: ($activeWorkspace?.splitDirection ?? 'horizontal');
return [
{
label: $t('bar.splitRight'),
icon: 'split-horizontal',
active: direction === 'horizontal',
onclick: () => {
setSplitDirection('horizontal');
splitCurrentTab('horizontal');
if (home) onHomeSplit?.('horizontal');
else {
setSplitDirection('horizontal');
splitCurrentTab('horizontal');
}
}
},
{
@@ -315,8 +329,11 @@
icon: 'split-vertical',
active: direction === 'vertical',
onclick: () => {
setSplitDirection('vertical');
splitCurrentTab('vertical');
if (home) onHomeSplit?.('vertical');
else {
setSplitDirection('vertical');
splitCurrentTab('vertical');
}
}
}
];
@@ -439,11 +456,11 @@
<!-- Right-side controls -->
<div class="flex items-center gap-0.5 shrink-0">
<!-- Split button (wide screens) -->
{#if isWideScreen && !home}
{#if isWideScreen}
<button
bind:this={splitBtnEl}
class="flex items-center justify-center w-7 h-7 rounded-lg transition-colors duration-100 shrink-0
{$splitActive
{(home ? homeSplitActive : $splitActive)
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
onclick={() => (showSplitMenu = !showSplitMenu)}
@@ -451,7 +468,7 @@
use:tooltip={$t('a11y.splitEditor')}
>
<Icon
name={$activeWorkspace?.splitDirection === 'vertical'
name={(home ? homeSplitDirection : $activeWorkspace?.splitDirection) === 'vertical'
? 'split-vertical'
: 'split-horizontal'}
size={14}
@@ -32,6 +32,7 @@
let expandedWorkspaces = $state<Set<string>>(new Set());
let wsChatsCache = $state<Map<string, ChatInfo[]>>(new Map());
let wsChatsHasMore = $state<Map<string, boolean>>(new Map());
let wsChatsLoading = $state<Set<string>>(new Set());
let currentPath = $derived($page.url.searchParams.get('workspace'));
@@ -46,14 +47,20 @@
expandedWorkspaces = next;
}
async function fetchWorkspaceChats(path: string) {
async function fetchWorkspaceChats(path: string, append = false) {
if (wsChatsLoading.has(path)) return;
wsChatsLoading = new Set([...wsChatsLoading, path]);
try {
const data = await getChats(path, 5, 0, 'updated_at', 'desc');
wsChatsCache = new Map([...wsChatsCache, [path, data.chats || []]]);
const existing = wsChatsCache.get(path) ?? [];
const data = await getChats(path, 5, append ? existing.length : 0, 'updated_at', 'desc');
wsChatsCache = new Map([
...wsChatsCache,
[path, append ? [...existing, ...(data.chats || [])] : data.chats || []]
]);
wsChatsHasMore = new Map([...wsChatsHasMore, [path, data.has_more]]);
} catch {
wsChatsCache = new Map([...wsChatsCache, [path, []]]);
wsChatsHasMore = new Map([...wsChatsHasMore, [path, false]]);
} finally {
const next = new Set(wsChatsLoading);
next.delete(path);
@@ -77,11 +84,6 @@
closeMobileSidebar();
}
function showMoreChats(wsPath: string) {
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
closeMobileSidebar();
}
function newChat(wsPath: string) {
goto(`/?workspace=${encodeURIComponent(wsPath)}&chatId`);
closeMobileSidebar();
@@ -166,6 +168,7 @@
if (!data.done && !data.title && !isNew) return;
wsChatsCache = new Map();
wsChatsHasMore = new Map();
for (const path of expandedWorkspaces) fetchWorkspaceChats(path);
}
@@ -216,6 +219,7 @@
{#each $workspaceList as ws (ws.path)}
{@const isExpanded = expandedWorkspaces.has(ws.path)}
{@const chats = wsChatsCache.get(ws.path)}
{@const hasMoreChats = wsChatsHasMore.get(ws.path)}
{@const isLoading = wsChatsLoading.has(ws.path)}
<div class="ws-item">
<div
@@ -295,9 +299,15 @@
onmenu={(e) => openChatMenu(e, chat.id, ws.path)}
/>
{/each}
<button class="ws-chat-show-more" onclick={() => showMoreChats(ws.path)}>
{$t('sidebar.showMore')}
</button>
{#if hasMoreChats}
<button
class="ws-chat-show-more"
disabled={isLoading}
onclick={() => fetchWorkspaceChats(ws.path, true)}
>
{$t('sidebar.showMore')}
</button>
{/if}
{/if}
</div>
{/if}
@@ -429,6 +429,7 @@
"browser.deviceAuto": "Auto",
"browser.deviceDesktop": "Desktop",
"browser.deviceMobile": "Mobile",
"browser.deviceFixedViewport": "Use fixed width × height",
"browser.deviceWidth": "Mobile viewport width",
"browser.deviceHeight": "Mobile viewport height",
"browser.deviceWidthHint": "Viewport width in CSS pixels.",
+138 -26
View File
@@ -102,6 +102,13 @@ export interface WorkspaceState {
fileBrowserCwd: string;
}
export interface HomeState {
groups: EditorGroup[];
activeGroupId: string;
layout: EditorLayout;
splitDirection: SplitDirection;
}
export type ToolApprovalMode = 'ask' | 'auto' | 'full';
export interface UserPreferences {
@@ -123,6 +130,7 @@ export interface UserPreferences {
widescreenMode?: boolean;
expandToolDetails?: boolean;
homeGroup?: EditorGroup;
homeState?: HomeState;
}
// ── ID generation ───────────────────────────────────────────────
@@ -264,10 +272,17 @@ function normalizeLayout(
/** The workspace currently displayed in THIS browser tab. Null = welcome page. */
export const currentWorkspace = writable<WorkspaceState | null>(null);
export const homeGroup = writable<EditorGroup>({
id: 'home',
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }],
activeTabId: 'home'
export const homeState = writable<HomeState>({
groups: [
{
id: 'home',
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }],
activeTabId: 'home'
}
],
activeGroupId: 'home',
layout: { type: 'group', groupId: 'home' },
splitDirection: 'horizontal'
});
/** List of all workspace summaries for the sidebar. */
@@ -426,7 +441,7 @@ function persistPreferences(): void {
textScale: get(textScale),
widescreenMode: get(widescreenMode),
expandToolDetails: get(expandToolDetails),
homeGroup: get(homeGroup)
homeState: get(homeState)
};
savePreferences(prefs as unknown as Record<string, unknown>).catch(() => {});
}, 300);
@@ -439,7 +454,7 @@ function subscribeForPersistence() {
currentWorkspace.subscribe(() => {
if (get(stateLoaded)) persistWorkspace();
});
homeGroup.subscribe(() => {
homeState.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
theme.subscribe(() => {
@@ -534,33 +549,71 @@ export async function loadPreferences(): Promise<void> {
if (prefs.expandToolDetails !== undefined)
expandToolDetails.set(prefs.expandToolDetails as boolean);
const savedHomeGroup = prefs.homeGroup as EditorGroup | undefined;
if (savedHomeGroup && Array.isArray(savedHomeGroup.tabs)) {
const savedHomeState =
(prefs.homeState as HomeState | undefined) ??
(savedHomeGroup
? {
groups: [savedHomeGroup],
activeGroupId: savedHomeGroup.id,
layout: { type: 'group' as const, groupId: savedHomeGroup.id },
splitDirection: 'horizontal' as const
}
: undefined);
if (savedHomeState && Array.isArray(savedHomeState.groups)) {
const [terminalIds, browserIds] = await Promise.all([
listSessions().catch(() => []),
listBrowserSessions().catch(() => [])
]);
const aliveTerminals = new Set(terminalIds);
const aliveBrowsers = new Set(browserIds);
const tabs = savedHomeGroup.tabs.filter(
(tab) =>
tab.type !== 'terminal' ||
(tab.sessionId !== undefined && aliveTerminals.has(tab.sessionId))
);
const liveTabs = tabs.filter(
(tab) =>
tab.type !== 'browser' ||
(tab.browserSessionId !== undefined && aliveBrowsers.has(tab.browserSessionId))
);
if (!liveTabs.some((tab) => tab.type === 'home')) {
liveTabs.unshift({ id: 'home', type: 'home', label: 'Home', permanent: true });
let groups = savedHomeState.groups
.map((group) => {
const tabs = group.tabs.filter(
(tab) =>
tab.type !== 'terminal' ||
(tab.sessionId !== undefined && aliveTerminals.has(tab.sessionId))
);
const liveTabs = tabs.filter(
(tab) =>
tab.type !== 'browser' ||
(tab.browserSessionId !== undefined && aliveBrowsers.has(tab.browserSessionId))
);
return {
...group,
tabs: liveTabs,
activeTabId: liveTabs.some((tab) => tab.id === group.activeTabId)
? group.activeTabId
: (liveTabs[0]?.id ?? '')
};
})
.filter((group) => group.tabs.length > 0);
if (!groups.length) {
groups = [
{
id: 'home',
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }],
activeTabId: 'home'
}
];
}
homeGroup.set({
...savedHomeGroup,
id: 'home',
tabs: liveTabs,
activeTabId: liveTabs.some((tab) => tab.id === savedHomeGroup.activeTabId)
? savedHomeGroup.activeTabId
: 'home'
if (!groups.some((group) => group.tabs.some((tab) => tab.type === 'home'))) {
groups[0] = {
...groups[0],
tabs: [{ id: 'home', type: 'home', label: 'Home', permanent: true }, ...groups[0].tabs]
};
}
homeState.set({
groups,
activeGroupId: groups.some((group) => group.id === savedHomeState.activeGroupId)
? savedHomeState.activeGroupId
: groups[0].id,
layout: normalizeLayout(
savedHomeState.layout,
groups,
savedHomeState.splitDirection ?? 'horizontal',
0.5
),
splitDirection: savedHomeState.splitDirection ?? 'horizontal'
});
}
const pwaPrefs = prefs.pwa;
@@ -1207,6 +1260,12 @@ export function setActiveGroup(groupId: string): void {
);
}
export function setHomeActiveGroup(groupId: string): void {
homeState.update((state) =>
state.activeGroupId === groupId ? state : { ...state, activeGroupId: groupId }
);
}
export function setFileBrowserCwd(cwd: string): void {
currentWorkspace.update((ws) => (ws ? { ...ws, fileBrowserCwd: cwd } : ws));
}
@@ -1321,6 +1380,24 @@ export function splitCurrentTab(direction?: SplitDirection): void {
});
}
export function splitHomeTab(direction?: SplitDirection): void {
homeState.update((state) => {
const group = state.groups.find((item) => item.id === state.activeGroupId);
const tab = group?.tabs.find((item) => item.id === group.activeTabId);
if (!group || !tab) return state;
const dir = direction ?? state.splitDirection;
const newTab: Tab = { ...tab, id: nextId(), permanent: false };
const newGroup: EditorGroup = { id: nextId(), tabs: [newTab], activeTabId: newTab.id };
return {
...state,
groups: [...state.groups, newGroup],
activeGroupId: newGroup.id,
layout: splitLayout(state.layout, group.id, newGroup.id, dir),
splitDirection: dir
};
});
}
/** Close an entire editor group */
export function closeGroup(groupId: string): void {
currentWorkspace.update((ws) => {
@@ -1358,6 +1435,34 @@ export function closeGroup(groupId: string): void {
});
}
export function closeHomeGroup(groupId: string): void {
homeState.update((state) => {
if (state.groups.length < 2) return state;
const closingGroup = state.groups.find((group) => group.id === groupId);
const remainingGroups = state.groups.filter((group) => group.id !== groupId);
const targetGroup =
remainingGroups.find((group) => group.id === state.activeGroupId) ?? remainingGroups[0];
if (!closingGroup || !targetGroup) return state;
const existingTabIds = new Set(targetGroup.tabs.map((tab) => tab.id));
const tabs = [
...targetGroup.tabs,
...closingGroup.tabs.filter((tab) => !existingTabIds.has(tab.id))
];
const activeTabId =
state.activeGroupId === groupId && tabs.some((tab) => tab.id === closingGroup.activeTabId)
? closingGroup.activeTabId
: targetGroup.activeTabId;
return {
...state,
groups: remainingGroups.map((group) =>
group.id === targetGroup.id ? { ...group, tabs, activeTabId } : group
),
activeGroupId: targetGroup.id,
layout: removeLayoutGroup(state.layout, groupId) ?? { type: 'group', groupId: targetGroup.id }
};
});
}
/** Move a tab from one group to another */
export function moveTabToGroup(tabId: string, fromGroupId: string, toGroupId: string): void {
currentWorkspace.update((ws) => {
@@ -1462,6 +1567,13 @@ export function setSplitRatio(splitId: string, ratio: number): void {
);
}
export function setHomeSplitRatio(splitId: string, ratio: number): void {
homeState.update((state) => ({
...state,
layout: updateSplitRatio(state.layout, splitId, ratio)
}));
}
function updateSplitRatio(layout: EditorLayout, splitId: string, ratio: number): EditorLayout {
if (layout.type === 'group') return layout;
if (layout.id === splitId) return { ...layout, ratio: Math.max(0.2, Math.min(0.8, ratio)) };
+332 -269
View File
@@ -18,7 +18,11 @@
showChangelog,
showSearch,
pwaPreferences,
homeGroup
homeState,
splitHomeTab,
closeHomeGroup,
setHomeActiveGroup,
setHomeSplitRatio
} from '$lib/stores';
import type { Tab, EditorGroup, EditorLayout, SplitDirection, WorkspaceState } from '$lib/stores';
import { chatEnabled } from '$lib/stores/chat';
@@ -63,17 +67,31 @@
});
const greetingVariant = $derived(new Date().getDate() % 3);
const greetingNameMarker = '\uE000';
const activeHomeGroup = $derived(
$homeState.groups.find((group) => group.id === $homeState.activeGroupId) ?? $homeState.groups[0]
);
const activeHomeTab = $derived(
$homeGroup.tabs.find((tab) => tab.id === $homeGroup.activeTabId) ?? $homeGroup.tabs[0]
activeHomeGroup?.tabs.find((tab) => tab.id === activeHomeGroup.activeTabId) ??
activeHomeGroup?.tabs[0]
);
function updateHomeTabs(update: (tabs: Tab[]) => { tabs: Tab[]; activeTabId: string }) {
const next = update($homeGroup.tabs);
homeGroup.set({ ...$homeGroup, ...next });
function updateHomeTabs(
groupId: string,
update: (tabs: Tab[]) => { tabs: Tab[]; activeTabId: string }
) {
homeState.update((state) => ({
...state,
activeGroupId: groupId,
groups: state.groups.map((group) =>
group.id === groupId ? { ...group, ...update(group.tabs) } : group
)
}));
}
function openHomeChat(chatId?: string) {
const existing = $homeGroup.tabs.find(
function openHomeChat(chatId?: string, groupId = $homeState.activeGroupId) {
const group = $homeState.groups.find((item) => item.id === groupId);
if (!group) return;
const existing = group.tabs.find(
(tab) =>
tab.type === 'chat' &&
(chatId
@@ -81,7 +99,7 @@
: tab.path?.startsWith('new-') || tab.path?.startsWith('pending-'))
);
if (existing) {
homeGroup.set({ ...$homeGroup, activeTabId: existing.id });
updateHomeTabs(groupId, (tabs) => ({ tabs, activeTabId: existing.id }));
return;
}
const tab: Tab = {
@@ -90,10 +108,10 @@
label: chatId ? 'Chat' : 'New Chat',
path: chatId || `new-${Date.now()}`
};
updateHomeTabs((tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
updateHomeTabs(groupId, (tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
}
async function openHomeTerminal() {
async function openHomeTerminal(groupId = $homeState.activeGroupId) {
try {
const session = await createSession();
const tab: Tab = {
@@ -102,13 +120,13 @@
label: 'Terminal',
sessionId: session.session_id
};
updateHomeTabs((tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
updateHomeTabs(groupId, (tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
} catch (error) {
console.error('Failed to create Home terminal:', error);
}
}
async function openHomeBrowser(url?: string) {
async function openHomeBrowser(url?: string, groupId = $homeState.activeGroupId) {
try {
const session = await createBrowserSession(url);
const tab: Tab = {
@@ -118,37 +136,47 @@
path: url,
browserSessionId: session.session_id
};
updateHomeTabs((tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
updateHomeTabs(groupId, (tabs) => ({ tabs: [...tabs, tab], activeTabId: tab.id }));
} catch (error) {
console.error('Failed to create Home browser:', error);
}
}
function closeHomeTab(tabId: string) {
const index = $homeGroup.tabs.findIndex((tab) => tab.id === tabId);
const tab = $homeGroup.tabs[index];
function closeHomeTab(tabId: string, groupId = $homeState.activeGroupId) {
const group = $homeState.groups.find((item) => item.id === groupId);
if (!group) return;
const index = group.tabs.findIndex((tab) => tab.id === tabId);
const tab = group.tabs[index];
if (!tab || tab.permanent) return;
if (tab.type === 'terminal' && tab.sessionId) deleteSession(tab.sessionId);
if (tab.type === 'browser' && tab.browserSessionId) deleteBrowserSession(tab.browserSessionId);
const tabs = $homeGroup.tabs.filter((item) => item.id !== tabId);
const tabs = group.tabs.filter((item) => item.id !== tabId);
const activeTabId =
$homeGroup.activeTabId === tabId
group.activeTabId === tabId
? (tabs[Math.max(0, index - 1)]?.id ?? 'home')
: $homeGroup.activeTabId;
homeGroup.set({ ...$homeGroup, tabs, activeTabId });
: group.activeTabId;
updateHomeTabs(groupId, () => ({ tabs, activeTabId }));
}
function updateHomeChatTab(tabId: string, chatId: string, label: string) {
updateHomeTabs((tabs) => ({
function updateHomeChatTab(
tabId: string,
chatId: string,
label: string,
groupId = $homeState.activeGroupId
) {
updateHomeTabs(groupId, (tabs) => ({
tabs: tabs.map((tab) => (tab.id === tabId ? { ...tab, path: chatId, label } : tab)),
activeTabId: $homeGroup.activeTabId
activeTabId:
groupId === $homeState.activeGroupId ? (activeHomeGroup?.activeTabId ?? tabId) : tabId
}));
}
function updateHomeBrowserTab(tabId: string, label: string) {
updateHomeTabs((tabs) => ({
function updateHomeBrowserTab(tabId: string, label: string, groupId = $homeState.activeGroupId) {
const group = $homeState.groups.find((item) => item.id === groupId);
if (!group) return;
updateHomeTabs(groupId, (tabs) => ({
tabs: tabs.map((tab) => (tab.id === tabId ? { ...tab, label } : tab)),
activeTabId: $homeGroup.activeTabId
activeTabId: group.activeTabId
}));
}
const INTENT_URL_KEYS = [
@@ -906,209 +934,244 @@
</script>
{#if !$currentWorkspace}
<div class="flex h-full flex-col">
<GroupTabBar
group={$homeGroup}
home
isPrimary
onHomeSelect={(tabId) => homeGroup.set({ ...$homeGroup, activeTabId: tabId })}
onHomeClose={closeHomeTab}
onHomeNewChat={openHomeChat}
onHomeNewTerminal={openHomeTerminal}
onHomeNewBrowser={openHomeBrowser}
/>
<div class="min-h-0 flex-1">
{#if activeHomeTab?.type === 'home'}
<div class="h-full overflow-y-auto px-6">
<div class="mx-auto flex min-h-full w-full max-w-md flex-col justify-center py-6">
<div class="mb-5">
<div class="flex items-baseline gap-2">
<h1 class="text-lg font-medium tracking-tight text-gray-900 dark:text-white">
{#if welcomeName}
{@const greeting = $t(`home.greeting.${greetingTime}.${greetingVariant}`, {
name: greetingNameMarker
})}
{@const [beforeName, afterName] = greeting.split(greetingNameMarker)}
{beforeName}<span class="capitalize">{welcomeName}</span>{afterName}
{:else}
Computer
{/if}
</h1>
</div>
<div
class="mt-0.5 flex items-baseline gap-2 font-mono text-xs text-gray-400 dark:text-gray-600"
>
{#if welcomeData?.hostname}
<span class="text-[0.6875rem]">{welcomeData.hostname}</span>
{/if}
{#if $appVersion}
<button
onclick={() => showChangelog.set(true)}
class="cursor-pointer text-[0.6875rem] hover:text-gray-500 hover:underline dark:hover:text-gray-400"
>
v{$appVersion}
</button>
{/if}
</div>
</div>
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">{$t('home.start')}</h2>
<button
class="text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => (showPicker = true)}
>
{$t('home.openWorkspace')}
</button>
{#if $chatEnabled}
<button
class="mt-1.5 block text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => openHomeChat()}
>
{$t('bar.newChat')}
</button>
{/if}
</div>
{#if continuation}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">{$t('home.continue')}</h2>
<button
class="group w-full min-w-0 py-1.5 text-left transition-colors duration-100"
onclick={() => quickOpen(continuation.path)}
>
<span class="flex min-w-0 items-baseline gap-2">
<span
class="truncate text-[0.8125rem] text-gray-800 group-hover:text-gray-950 dark:text-gray-200 dark:group-hover:text-white"
<div class="split-container" class:flex-col={$homeState.splitDirection === 'vertical'}>
{#each $homeState.groups as homePane (homePane.id)}
{@const homeTab =
homePane.tabs.find((tab) => tab.id === homePane.activeTabId) ?? homePane.tabs[0]}
<div class="split-branch-child">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="split-pane"
onpointerdown={() => setHomeActiveGroup(homePane.id)}
onfocusin={() => setHomeActiveGroup(homePane.id)}
>
<GroupTabBar
group={homePane}
home
isPrimary
canClose={$homeState.groups.length > 1}
homeSplitActive={$homeState.groups.length > 1}
homeSplitDirection={$homeState.splitDirection}
onHomeSelect={(tabId) =>
updateHomeTabs(homePane.id, (tabs) => ({ tabs, activeTabId: tabId }))}
onHomeClose={(tabId) => closeHomeTab(tabId, homePane.id)}
onHomeNewChat={() => openHomeChat(undefined, homePane.id)}
onHomeNewTerminal={() => openHomeTerminal(homePane.id)}
onHomeNewBrowser={() => openHomeBrowser(undefined, homePane.id)}
onHomeSplit={(direction) => {
setHomeActiveGroup(homePane.id);
splitHomeTab(direction);
}}
onHomeCloseGroup={() => closeHomeGroup(homePane.id)}
/>
<div class="pane-content">
{#if homeTab?.type === 'home'}
<div class="h-full overflow-y-auto px-6">
<div class="mx-auto flex min-h-full w-full max-w-md flex-col justify-center py-6">
<div class="mb-5">
<div class="flex items-baseline gap-2">
<h1 class="text-lg font-medium tracking-tight text-gray-900 dark:text-white">
{#if welcomeName}
{@const greeting = $t(
`home.greeting.${greetingTime}.${greetingVariant}`,
{
name: greetingNameMarker
}
)}
{@const [beforeName, afterName] = greeting.split(greetingNameMarker)}
{beforeName}<span class="capitalize">{welcomeName}</span>{afterName}
{:else}
Computer
{/if}
</h1>
</div>
<div
class="mt-0.5 flex items-baseline gap-2 font-mono text-xs text-gray-400 dark:text-gray-600"
>
{continuation.name}
</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(continuation.path)}
</span>
</span>
{#if continueSignals.length}
<span
class="mt-0.5 block truncate font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
>
{continueSignals.join(' ')}
</span>
{:else if continueResume?.activeLabels.length}
<span
class="mt-0.5 block truncate text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{continueResume.activeLabels.join(' · ')}
</span>
{/if}
</button>
</div>
{/if}
{#if recent.length}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">{$t('home.recent')}</h2>
<div class="flex flex-col">
{#each recent as item}
{@const resume = workspaceResumes.get(item.path)}
{@const signals = resumeSignals(resume)}
<button
class="group w-full min-w-0 py-1.5 text-left transition-colors duration-100"
onclick={() => quickOpen(item.path)}
>
<span class="flex min-w-0 items-baseline gap-2">
<span
class="truncate text-[0.8125rem] text-gray-700 group-hover:text-gray-900 dark:text-gray-300 dark:group-hover:text-white"
>
{item.name}
</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(item.path)}
</span>
</span>
{#if signals.length}
<span
class="mt-0.5 block truncate font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
>
{signals.join(' ')}
</span>
{:else if resume?.activeLabels.length}
<span
class="mt-0.5 block truncate text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{resume.activeLabels.join(' · ')}
</span>
{#if welcomeData?.hostname}
<span class="text-[0.6875rem]">{welcomeData.hostname}</span>
{/if}
</button>
{/each}
</div>
</div>
{:else if !continuation}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">{$t('home.recent')}</h2>
<button
class="text-[0.8125rem] text-gray-500 transition-colors duration-100 hover:text-gray-900 dark:text-gray-500 dark:hover:text-white"
onclick={() => (showPicker = true)}
>
{$t('home.noWorkspaces')}
</button>
</div>
{/if}
{#if $appVersion}
<button
onclick={() => showChangelog.set(true)}
class="cursor-pointer text-[0.6875rem] hover:text-gray-500 hover:underline dark:hover:text-gray-400"
>
v{$appVersion}
</button>
{/if}
</div>
</div>
{#if nearby.length && !welcomeData?.recent?.length}
<div>
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">{$t('home.folders')}</h2>
<div class="flex flex-col">
{#each nearby as item}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">
{$t('home.start')}
</h2>
<button
class="flex min-w-0 items-center gap-2 py-1.5 text-left text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => quickOpen(item.path)}
class="text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => (showPicker = true)}
>
<Icon
name="folder"
size={14}
strokeWidth={1.3}
class="shrink-0 text-gray-400 dark:text-gray-600"
/>
<span class="truncate">{item.name}</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(item.path)}
</span>
{$t('home.openWorkspace')}
</button>
{/each}
{#if $chatEnabled}
<button
class="mt-1.5 block text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => openHomeChat(undefined, homePane.id)}
>
{$t('bar.newChat')}
</button>
{/if}
</div>
{#if continuation}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">
{$t('home.continue')}
</h2>
<button
class="group w-full min-w-0 py-1.5 text-left transition-colors duration-100"
onclick={() => quickOpen(continuation.path)}
>
<span class="flex min-w-0 items-baseline gap-2">
<span
class="truncate text-[0.8125rem] text-gray-800 group-hover:text-gray-950 dark:text-gray-200 dark:group-hover:text-white"
>
{continuation.name}
</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(continuation.path)}
</span>
</span>
{#if continueSignals.length}
<span
class="mt-0.5 block truncate font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
>
{continueSignals.join(' ')}
</span>
{:else if continueResume?.activeLabels.length}
<span
class="mt-0.5 block truncate text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{continueResume.activeLabels.join(' · ')}
</span>
{/if}
</button>
</div>
{/if}
{#if recent.length}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">
{$t('home.recent')}
</h2>
<div class="flex flex-col">
{#each recent as item}
{@const resume = workspaceResumes.get(item.path)}
{@const signals = resumeSignals(resume)}
<button
class="group w-full min-w-0 py-1.5 text-left transition-colors duration-100"
onclick={() => quickOpen(item.path)}
>
<span class="flex min-w-0 items-baseline gap-2">
<span
class="truncate text-[0.8125rem] text-gray-700 group-hover:text-gray-900 dark:text-gray-300 dark:group-hover:text-white"
>
{item.name}
</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(item.path)}
</span>
</span>
{#if signals.length}
<span
class="mt-0.5 block truncate font-mono text-[0.625rem] text-gray-400 dark:text-gray-600"
>
{signals.join(' ')}
</span>
{:else if resume?.activeLabels.length}
<span
class="mt-0.5 block truncate text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{resume.activeLabels.join(' · ')}
</span>
{/if}
</button>
{/each}
</div>
</div>
{:else if !continuation}
<div class="mb-6">
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">
{$t('home.recent')}
</h2>
<button
class="text-[0.8125rem] text-gray-500 transition-colors duration-100 hover:text-gray-900 dark:text-gray-500 dark:hover:text-white"
onclick={() => (showPicker = true)}
>
{$t('home.noWorkspaces')}
</button>
</div>
{/if}
{#if nearby.length && !welcomeData?.recent?.length}
<div>
<h2 class="mb-2 text-xs text-gray-400 dark:text-gray-600">
{$t('home.folders')}
</h2>
<div class="flex flex-col">
{#each nearby as item}
<button
class="flex min-w-0 items-center gap-2 py-1.5 text-left text-[0.8125rem] text-gray-600 transition-colors duration-100 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
onclick={() => quickOpen(item.path)}
>
<Icon
name="folder"
size={14}
strokeWidth={1.3}
class="shrink-0 text-gray-400 dark:text-gray-600"
/>
<span class="truncate">{item.name}</span>
<span
class="truncate font-mono text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{shortenPath(item.path)}
</span>
</button>
{/each}
</div>
</div>
{/if}
</div>
</div>
{:else if homeTab?.type === 'chat'}
<ChatPanel
chatId={homeTab.path?.startsWith('new-') || homeTab.path?.startsWith('pending-')
? undefined
: homeTab.path}
tabId={homeTab.id}
ontabupdate={(tabId, chatId, label) =>
updateHomeChatTab(tabId, chatId, label, homePane.id)}
onopenchat={(chatId) => openHomeChat(chatId, homePane.id)}
/>
{:else if homeTab?.type === 'terminal' && homeTab.sessionId}
<Terminal sessionId={homeTab.sessionId} />
{:else if homeTab?.type === 'browser' && homeTab.browserSessionId}
<BrowserPreview
sessionId={homeTab.browserSessionId}
groupId={homePane.id}
tabId={homeTab.id}
initialUrl={homeTab.path}
onTabUpdate={(label) => updateHomeBrowserTab(homeTab.id, label, homePane.id)}
onOpenBrowser={(url) => openHomeBrowser(url, homePane.id)}
/>
{/if}
</div>
</div>
{:else if activeHomeTab?.type === 'chat'}
<ChatPanel
chatId={activeHomeTab.path?.startsWith('new-') ||
activeHomeTab.path?.startsWith('pending-')
? undefined
: activeHomeTab.path}
tabId={activeHomeTab.id}
ontabupdate={updateHomeChatTab}
onopenchat={openHomeChat}
/>
{:else if activeHomeTab?.type === 'terminal' && activeHomeTab.sessionId}
<Terminal sessionId={activeHomeTab.sessionId} />
{:else if activeHomeTab?.type === 'browser' && activeHomeTab.browserSessionId}
<BrowserPreview
sessionId={activeHomeTab.browserSessionId}
groupId="home"
tabId={activeHomeTab.id}
initialUrl={activeHomeTab.path}
onTabUpdate={(label) => updateHomeBrowserTab(activeHomeTab.id, label)}
onOpenBrowser={openHomeBrowser}
/>
{/if}
</div>
</div>
{/each}
</div>
{:else}
<!-- Editor groups layout -->
@@ -1172,58 +1235,58 @@
/>
<div class="pane-content">
{#each group.tabs.filter((tab) => tab.type === 'files') as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileBrowser />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'file' && tab.filePath) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileEditor
filePath={tab.filePath!}
tabId={tab.id}
edit={tab.edit === true}
searchTarget={tab.searchTarget}
/>
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'chat') as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<ChatPanel
workspace={$currentWorkspace!.path}
chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-')
? undefined
: tab.path}
tabId={tab.id}
/>
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'terminal' && tab.sessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<Terminal sessionId={tab.sessionId!} />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'browser' && tab.browserSessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<BrowserPreview
sessionId={tab.browserSessionId!}
groupId={group.id}
tabId={tab.id}
initialUrl={tab.path}
active={tab.id === group.activeTabId && group.id === activeGroup?.id}
/>
</div>
{/each}
{#if !groupTab}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileBrowser />
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
<div class="flex items-center justify-center h-full"><Spinner size={20} /></div>
{:else if groupTab.type === 'browser' && !groupTab.browserSessionId}
<div
class="flex h-full items-center justify-center gap-2 text-xs text-gray-500 dark:text-gray-400"
>
<Spinner size={16} />
<span>{$t('browser.starting')}</span>
</div>
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'file' && tab.filePath) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<FileEditor
filePath={tab.filePath!}
tabId={tab.id}
edit={tab.edit === true}
searchTarget={tab.searchTarget}
/>
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'chat') as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<ChatPanel
workspace={$currentWorkspace!.path}
chatId={tab.path?.startsWith('new-') || tab.path?.startsWith('pending-')
? undefined
: tab.path}
tabId={tab.id}
/>
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'terminal' && tab.sessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<Terminal sessionId={tab.sessionId!} />
</div>
{/each}
{#each group.tabs.filter((tab) => tab.type === 'browser' && tab.browserSessionId) as tab (tab.id)}
<div class="persisted-tab" class:persisted-tab-hidden={tab.id !== group.activeTabId}>
<BrowserPreview
sessionId={tab.browserSessionId!}
groupId={group.id}
tabId={tab.id}
initialUrl={tab.path}
active={tab.id === group.activeTabId && group.id === activeGroup?.id}
/>
</div>
{/each}
{#if !groupTab}
<FileBrowser />
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
<div class="flex items-center justify-center h-full"><Spinner size={20} /></div>
{:else if groupTab.type === 'browser' && !groupTab.browserSessionId}
<div
class="flex h-full items-center justify-center gap-2 text-xs text-gray-500 dark:text-gray-400"
>
<Spinner size={16} />
<span>{$t('browser.starting')}</span>
</div>
{/if}
{#if $gitReviewOpen && group.id === allGroups[0]?.id}
<div class="persisted-tab git-review-tab">
+1 -1
View File
@@ -37,7 +37,7 @@ class BrowserSession:
status: str = "ready"
device_profile: dict = field(default_factory=dict)
device_mode: str = "auto"
mobile_viewport: tuple[int, int] = (390, 844)
mobile_viewport: tuple[int, int] | None = None
quality_preset: str = "balanced"
resolved_quality: dict = field(default_factory=dict)
+14 -9
View File
@@ -1107,7 +1107,7 @@ class ChromeViewerManager:
"width": viewer.session.mobile_viewport[0],
"height": viewer.session.mobile_viewport[1],
}
if not viewer.personal
if not viewer.personal and viewer.session.mobile_viewport
else None,
}
)
@@ -1267,22 +1267,27 @@ class ChromeViewerManager:
mode = mode if mode in {"auto", "desktop", "mobile"} else "auto"
requested_mobile_viewport = data.get("mobile_viewport")
current_mobile_viewport = viewer.session.mobile_viewport
if isinstance(requested_mobile_viewport, dict):
if "mobile_viewport" not in data:
mobile_viewport = current_mobile_viewport
elif isinstance(requested_mobile_viewport, dict):
try:
mobile_viewport = (
int(requested_mobile_viewport.get("width")),
int(requested_mobile_viewport.get("height")),
)
except (TypeError, ValueError):
mobile_viewport = current_mobile_viewport
if mobile_viewport[0] <= 0 or mobile_viewport[1] <= 0:
mobile_viewport = current_mobile_viewport
mobile_viewport = None
if not mobile_viewport or mobile_viewport[0] <= 0 or mobile_viewport[1] <= 0:
mobile_viewport = None
else:
mobile_viewport = current_mobile_viewport
profile, _ = _effective_device_profile(
requested_profile, mode, mobile_viewport, viewer.host.user_agent
mobile_viewport = None
emulated_viewport = (
mobile_viewport if mode == "mobile" and mobile_viewport else (width, height)
)
layout_viewport = mobile_viewport if mode == "mobile" else (width, height)
profile, _ = _effective_device_profile(
requested_profile, mode, emulated_viewport, viewer.host.user_agent
)
layout_viewport = emulated_viewport
preset, quality = _resolve_quality(
data.get("quality"),
viewer.quality_profiles,