Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/AppIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
const isInvalidArea = drag !== null && drag.target === null;
const shown = drag ? { x: drag.x, y: drag.y } : home;

const isImagePath = app.icon.startsWith('/');
// icon is optional for store packages (orbit.schema.json).
const isImagePath = typeof app.icon === 'string' && app.icon.startsWith('/');

return (
<>
Expand Down Expand Up @@ -205,7 +206,7 @@
}`}
>
{isImagePath ? (
<img

Check warning on line 209 in src/components/AppIcon.js

View workflow job for this annotation

GitHub Actions / Lint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
src={app.icon}
alt=""
draggable={false}
Expand All @@ -213,7 +214,7 @@
/>
) : (
<span className="text-5xl flex items-center justify-center h-full">
{app.icon}
{app.icon || '📱'}
</span>
)}
{/* Shortcut indicator */}
Expand Down
5 changes: 3 additions & 2 deletions src/components/Taskbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
* A helper component to display either a PNG icon or an emoji.
*/
const IconDisplay = ({ icon, alt, className }) => {
const isImagePath = icon.startsWith('/');
// icon is optional for store packages (orbit.schema.json).
const isImagePath = typeof icon === 'string' && icon.startsWith('/');
return isImagePath ? (
<img src={icon} alt={alt} draggable={false} className={className} />

Check warning on line 26 in src/components/Taskbar.js

View workflow job for this annotation

GitHub Actions / Lint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
) : (
<span className={`flex items-center justify-center text-3xl ${className}`}>
{icon}
{icon || '📱'}
</span>
);
};
Expand Down Expand Up @@ -482,7 +483,7 @@
>
<div className="w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center overflow-hidden">
{user?.avatar ? (
<img

Check warning on line 486 in src/components/Taskbar.js

View workflow job for this annotation

GitHub Actions / Lint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
src={user.avatar}
alt={t('taskbar.avatarAlt')}
className="w-full h-full object-cover"
Expand Down
37 changes: 21 additions & 16 deletions src/pages/api/packages/approved.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
// src/pages/api/packages/approved.js

const DEFAULT_PACKAGES_REPO = 'codehubbers/OrbitOSPackages';

// GITHUB_TOKEN is optional (.env.example): without it the public repo is read
// unauthenticated. Sending "token undefined" makes GitHub answer 401.
function githubHeaders() {
const headers = { Accept: 'application/vnd.github.v3+json' };
if (process.env.GITHUB_TOKEN) {
headers.Authorization = `token ${process.env.GITHUB_TOKEN}`;
}
return headers;
}

export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}

const repo = process.env.ORBIT_PACKAGES_REPO || DEFAULT_PACKAGES_REPO;
const headers = githubHeaders();

try {
console.log('Fetching from repo:', process.env.ORBIT_PACKAGES_REPO);
console.log('Fetching from repo:', repo);
const response = await fetch(
`https://api.github.com/repos/${process.env.ORBIT_PACKAGES_REPO}/contents`,
{
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
Accept: 'application/vnd.github.v3+json',
},
},
`https://api.github.com/repos/${repo}/contents`,
{ headers },
);

if (!response.ok) {
Expand All @@ -38,13 +48,8 @@ export default async function handler(req, res) {
console.log(`Processing folder: ${folder.name}`);
// Get orbit.lock.json
const lockResponse = await fetch(
`https://api.github.com/repos/${process.env.ORBIT_PACKAGES_REPO}/contents/${folder.name}/orbit.lock.json`,
{
headers: {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
Accept: 'application/vnd.github.v3+json',
},
},
`https://api.github.com/repos/${repo}/contents/${folder.name}/orbit.lock.json`,
{ headers },
);

if (lockResponse.ok) {
Expand All @@ -56,7 +61,7 @@ export default async function handler(req, res) {

if (lockData.signature === 'orbit-signed') {
packages.push({
id: folder.name,
id: lockData.manifest?.id || folder.name,
manifest: lockData.manifest,
signature: lockData.signature,
downloadUrl: lockData.downloadUrl,
Expand Down
40 changes: 25 additions & 15 deletions src/pages/apps/appstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ const AppCard = ({
<span className={`px-3 py-1 rounded-full ${theme.app.badge}`}>
v{app.manifest.version}
</span>
<span className={`px-3 py-1 rounded-full ${theme.app.badge}`}>
{app.manifest.category}
</span>
<span className={`px-3 py-1 rounded-full ${theme.app.badge}`}>
{app.manifest.author}
</span>
{app.manifest.category && (
<span className={`px-3 py-1 rounded-full ${theme.app.badge}`}>
{app.manifest.category}
</span>
)}
{app.manifest.author && (
<span className={`px-3 py-1 rounded-full ${theme.app.badge}`}>
{app.manifest.author}
</span>
)}
</div>
</div>
<div className="flex gap-2">
Expand Down Expand Up @@ -110,7 +114,9 @@ const AppModal = ({
<div className="text-6xl">{app.manifest.icon || '📱'}</div>
<div>
<h2 className="text-3xl font-bold">{app.manifest.name}</h2>
<p className="text-lg opacity-75">by {app.manifest.author}</p>
{app.manifest.author && (
<p className="text-lg opacity-75">by {app.manifest.author}</p>
)}
</div>
</div>
<button
Expand Down Expand Up @@ -204,18 +210,22 @@ export default function AppStoreApp() {
const appsPerPage = 6;

const categories = useMemo(() => {
const cats = ['all', ...new Set(apps.map((app) => app.manifest.category))];
// category is optional in orbit.schema.json
const cats = [
'all',
...new Set(apps.map((app) => app.manifest.category).filter(Boolean)),
];
return cats;
}, [apps]);

const filteredApps = useMemo(() => {
const query = searchQuery.toLowerCase();
return apps.filter((app) => {
const matchesSearch =
app.manifest.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
app.manifest.description
.toLowerCase()
.includes(searchQuery.toLowerCase()) ||
app.manifest.author.toLowerCase().includes(searchQuery.toLowerCase());
// Only id, name, version and entry are required by orbit.schema.json.
const { name = '', description = '', author = '' } = app.manifest;
const matchesSearch = [name, description, author].some((field) =>
String(field).toLowerCase().includes(query),
);
const matchesCategory =
selectedCategory === 'all' ||
app.manifest.category === selectedCategory;
Expand Down Expand Up @@ -332,7 +342,7 @@ export default function AppStoreApp() {
payload: {
id: app.id,
name: app.manifest.name,
icon: app.manifest.icon,
icon: app.manifest.icon || '📱',
component: app.id,
},
});
Expand Down
50 changes: 50 additions & 0 deletions tests/AppStore.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { render, screen, fireEvent } from '@testing-library/react';
import AppStoreApp from '@/pages/apps/appstore';

jest.mock('@/context/ThemeContext', () => ({
useTheme: () => ({ theme: { app: {} } }),
}));

jest.mock('@/context/AppContext', () => ({
useApp: () => ({ dispatch: jest.fn() }),
}));

jest.mock('@/lib/session', () => ({
fetchSession: jest.fn().mockResolvedValue({ ok: false, user: null }),
}));

// Only the fields orbit.schema.json requires: no description, author,
// category or icon (#177).
const minimalPackage = {
id: 'orbit-terminal',
signature: 'orbit-signed',
downloadUrl: 'https://example.com/app.zip',
manifest: {
id: 'orbit-terminal',
name: 'Terminal',
version: '1.0.0',
entry: 'App.jsx',
},
};

describe('App Store with a minimal package', () => {
beforeEach(() => {
global.fetch = jest.fn().mockResolvedValue({
json: () => Promise.resolve([minimalPackage]),
});
});

it('renders and searches a package without description, author or icon', async () => {
render(<AppStoreApp />);

expect(await screen.findByText('Terminal')).toBeInTheDocument();
expect(screen.getByText('📱')).toBeInTheDocument();

const search = screen.getByPlaceholderText('Search apps...');
fireEvent.change(search, { target: { value: 'term' } });
expect(screen.getByText('Terminal')).toBeInTheDocument();

fireEvent.change(search, { target: { value: 'nothing-matches' } });
expect(screen.queryByText('Terminal')).not.toBeInTheDocument();
});
});
15 changes: 15 additions & 0 deletions tests/Taskbar.hydration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,18 @@ describe('Taskbar Hydration Error Fix', () => {
expect(clockElement.textContent).toMatch(/[\d:apm]/i);
});
});

describe('Taskbar with store apps', () => {
afterEach(() => {
mockState.openApps = [];
});

test('renders an open app whose manifest has no icon (#177)', () => {
// orbit.schema.json only requires id, name, version and entry.
mockState.openApps = [{ id: 'orbit-terminal', name: 'Terminal' }];

render(React.createElement(Taskbar));

expect(screen.getByTitle('Terminal')).toHaveTextContent('📱');
});
});
82 changes: 82 additions & 0 deletions tests/approvedPackages.api.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import handler from '@/pages/api/packages/approved';

function createResponse() {
return {
status: jest.fn().mockReturnThis(),
json: jest.fn().mockReturnThis(),
};
}

const lockFile = (lock) => ({
content: Buffer.from(JSON.stringify(lock)).toString('base64'),
});

// A package that only has the fields orbit.schema.json requires.
const minimalLock = {
signature: 'orbit-signed',
downloadUrl: 'https://example.com/app.zip',
manifest: {
id: 'orbit-terminal',
name: 'Terminal',
version: '1.0.0',
entry: 'App.jsx',
},
};

function mockGitHub() {
global.fetch = jest.fn((url) => {
const body = url.endsWith('/contents')
? [{ name: 'example-app', type: 'dir' }]
: lockFile(minimalLock);
return Promise.resolve({ ok: true, json: () => Promise.resolve(body) });
});
}

describe('/api/packages/approved', () => {
const env = process.env;

beforeEach(() => {
process.env = { ...env };
delete process.env.GITHUB_TOKEN;
delete process.env.ORBIT_PACKAGES_REPO;
jest.spyOn(console, 'log').mockImplementation(() => {});
mockGitHub();
});

afterEach(() => {
process.env = env;
jest.restoreAllMocks();
});

it('reads the public repo without an Authorization header when GITHUB_TOKEN is unset', async () => {
const res = createResponse();
await handler({ method: 'GET' }, res);

expect(res.status).toHaveBeenCalledWith(200);
for (const [url, options] of global.fetch.mock.calls) {
expect(url).toContain('/repos/codehubbers/OrbitOSPackages/');
expect(options.headers).not.toHaveProperty('Authorization');
}
});

it('sends the token when GITHUB_TOKEN is set', async () => {
process.env.GITHUB_TOKEN = 'secret';
process.env.ORBIT_PACKAGES_REPO = 'someone/packages';
const res = createResponse();
await handler({ method: 'GET' }, res);

for (const [url, options] of global.fetch.mock.calls) {
expect(url).toContain('/repos/someone/packages/');
expect(options.headers.Authorization).toBe('token secret');
}
});

it('keeps manifest.id instead of the folder name', async () => {
const res = createResponse();
await handler({ method: 'GET' }, res);

const [packages] = res.json.mock.calls[0];
expect(packages).toHaveLength(1);
expect(packages[0].id).toBe('orbit-terminal');
});
});
Loading