Skip to content

Commit db1dea7

Browse files
authored
Custom-rendered app bar (#10)
2 parents 234f5f6 + c3c2b57 commit db1dea7

File tree

16 files changed

+515
-4
lines changed

16 files changed

+515
-4
lines changed

lib/.storybook/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import type { StorybookConfig } from '@storybook/react-vite';
33
const config: StorybookConfig = {
44
stories: ['../src/**/*.stories.@(ts|tsx)'],
55
framework: '@storybook/react-vite',
6+
viteFinal: (config) => {
7+
config.resolve ??= {};
8+
config.resolve.alias = {
9+
...(config.resolve.alias as Record<string, string> ?? {}),
10+
'@tauri-apps/api/window': new URL('./tauri-window-mock.ts', import.meta.url).pathname,
11+
};
12+
return config;
13+
},
614
};
715

816
export default config;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const mockWindow = {
2+
isMaximized: () => Promise.resolve(false),
3+
onResized: (_callback: () => void) => Promise.resolve(() => {}),
4+
minimize: () => Promise.resolve(),
5+
toggleMaximize: () => Promise.resolve(),
6+
close: () => Promise.resolve(),
7+
};
8+
9+
export function getCurrentWindow() {
10+
return mockWindow;
11+
}

lib/src/components/Pond.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,30 @@ export function Pond({
16881688
const handleReattachRef = useRef(handleReattach);
16891689
handleReattachRef.current = handleReattach;
16901690

1691+
// Listen for external "new terminal" requests (e.g. from the standalone AppBar)
1692+
useEffect(() => {
1693+
const handler = () => {
1694+
const api = apiRef.current;
1695+
if (!api) return;
1696+
const newId = generatePaneId();
1697+
const active = api.activePanel;
1698+
let direction: 'right' | 'below' = 'right';
1699+
if (active) {
1700+
direction = (active.api.width - active.api.height > 0) ? 'right' : 'below';
1701+
}
1702+
api.addPanel({
1703+
id: newId,
1704+
component: 'terminal',
1705+
tabComponent: 'terminal',
1706+
title: '<unnamed>',
1707+
position: active ? { referencePanel: active.id, direction } : undefined,
1708+
});
1709+
selectPanel(newId);
1710+
};
1711+
window.addEventListener('mouseterm:new-terminal', handler);
1712+
return () => window.removeEventListener('mouseterm:new-terminal', handler);
1713+
}, [generatePaneId, selectPanel]);
1714+
16911715
const addSplitPanel = useCallback((
16921716
id: string | null,
16931717
direction: 'right' | 'below',

lib/src/stories/AppBar.stories.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import { AppBar } from '../../../standalone/src/AppBar';
3+
4+
const DEFAULT_SHELLS = [
5+
{ name: 'bash', path: '/bin/bash' },
6+
{ name: 'zsh', path: '/bin/zsh' },
7+
{ name: 'fish', path: '/usr/bin/fish' },
8+
];
9+
10+
function AppBarStory(props: React.ComponentProps<typeof AppBar>) {
11+
return (
12+
<div style={{ width: '100%' }}>
13+
<AppBar {...props} />
14+
</div>
15+
);
16+
}
17+
18+
const meta: Meta<typeof AppBarStory> = {
19+
title: 'Components/AppBar',
20+
component: AppBarStory,
21+
args: {
22+
projectDir: '/home/user/projects/mouseterm',
23+
homeDir: '/home/user',
24+
shells: DEFAULT_SHELLS,
25+
},
26+
};
27+
28+
export default meta;
29+
type Story = StoryObj<typeof AppBarStory>;
30+
31+
export const Default: Story = {};
32+
33+
export const HomeDirectory: Story = {
34+
args: {
35+
projectDir: '/home/user',
36+
homeDir: '/home/user',
37+
},
38+
};
39+
40+
export const LongPath: Story = {
41+
args: {
42+
projectDir: '/home/user/projects/very-deep/nested/directory/structure/my-project',
43+
homeDir: '/home/user',
44+
},
45+
};
46+
47+
export const SingleShell: Story = {
48+
args: {
49+
shells: [{ name: 'bash', path: '/bin/bash' }],
50+
},
51+
};
52+
53+
export const ManyShells: Story = {
54+
args: {
55+
shells: [
56+
{ name: 'bash', path: '/bin/bash' },
57+
{ name: 'zsh', path: '/bin/zsh' },
58+
{ name: 'fish', path: '/usr/bin/fish' },
59+
{ name: 'sh', path: '/bin/sh' },
60+
{ name: 'nu', path: '/usr/bin/nu' },
61+
],
62+
},
63+
};
64+
65+
export const AbsolutePathOutsideHome: Story = {
66+
args: {
67+
projectDir: '/var/www/my-site',
68+
homeDir: '/home/user',
69+
},
70+
};

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ packages:
44
- standalone/sidecar
55
- vscode-ext
66
- website
7+
minimumReleaseAge: 20160

standalone/src-tauri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

standalone/src-tauri/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ authors = ["DiffPlug"]
66
license = "FSL-1.1-MIT"
77
edition = "2021"
88

9+
[registry]
10+
global-min-publish-age = "14 days"
11+
912
[lib]
1013
name = "mouseterm_lib"
1114
crate-type = ["lib", "cdylib", "staticlib"]

standalone/src-tauri/capabilities/default.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"windows": ["main"],
55
"permissions": [
66
"core:default",
7+
"core:window:allow-minimize",
8+
"core:window:allow-toggle-maximize",
9+
"core:window:allow-close",
10+
"core:window:allow-is-maximized",
11+
"core:window:allow-start-dragging",
712
"shell:allow-spawn",
813
"shell:allow-stdin-write",
914
"shell:allow-kill",

standalone/src-tauri/gen/schemas/acl-manifests.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"default":{"identifier":"default","description":"Default capability set for MouseTerm","local":true,"windows":["main"],"permissions":["core:default","shell:allow-spawn","shell:allow-stdin-write","shell:allow-kill"]}}
1+
{"default":{"identifier":"default","description":"Default capability set for MouseTerm","local":true,"windows":["main"],"permissions":["core:default","core:window:allow-minimize","core:window:allow-toggle-maximize","core:window:allow-close","core:window:allow-is-maximized","core:window:allow-start-dragging","shell:allow-spawn","shell:allow-stdin-write","shell:allow-kill","shell:allow-open"]}}

0 commit comments

Comments
 (0)