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
4 changes: 4 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"48": "assets/icon48.png",
"128": "assets/icon128.png"
},
"options_ui": {
"page": "settings.html",
"open_in_tab": true
},
"web_accessible_resources": [
"recap.html",
"assets/videos/*.mp4"
Expand Down
2 changes: 1 addition & 1 deletion src/popup/HomeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const HomeView = ({ onSelectTimeRange, loading, onOpenSettings}) => (
HomeView.propTypes = {
onSelectTimeRange: PropTypes.func.isRequired,
loading: PropTypes.bool,
onOpenSettings: PropTypes.func // optional for now
onOpenSettings: PropTypes.func.isRequired
};

export default HomeView;
6 changes: 5 additions & 1 deletion src/popup/popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ const Popup = () => {
browser.tabs.create({ url });
};

const handleOpenSettings = () => {
browser.runtime.openOptionsPage();
};

return view === 'home'
? <HomeView onSelectTimeRange={onSelectTimeRange} />
? <HomeView onSelectTimeRange={onSelectTimeRange} onOpenSettings={handleOpenSettings} />
: <SlideShow timeRange={timeRange} setView={setView} />;
};

Expand Down
59 changes: 59 additions & 0 deletions src/settings/Settings.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React, { useState, useEffect } from 'react';

const Settings = () => {
const [hasPermission, setHasPermission] = useState(null);
const [requesting, setRequesting] = useState(false);
const [error, setError] = useState('');

const checkPermission = async () => {
try {
const granted = await browser.permissions.contains({ permissions: ['trialML'] });
setHasPermission(granted);
} catch (err) {
setError('Could not check permission status.');
setHasPermission(false);
}
};

useEffect(() => {
checkPermission();
}, []);

const handleRequestPermission = async () => {
setRequesting(true);
setError('');
try {
const granted = await browser.permissions.request({ permissions: ['trialML'] });
setHasPermission(granted);
if (!granted) setError('Permission was not granted.');
} catch (err) {
setError('An error occurred while requesting permission.');
setHasPermission(false);
} finally {
setRequesting(false);
}
};

return (
<div style={{ padding: 20, fontFamily: 'Arial, sans-serif', color: '#333' }}>
<h1>Settings</h1>
<h2>ML Engine Permission</h2>
{hasPermission === null && <p>Checking permission status...</p>}
{hasPermission && <p style={{ color: 'green' }}>✅ trialML permission granted.</p>}
{hasPermission === false && (
<div>
<p style={{ color: 'red' }}>❌ trialML permission is required for ML features.</p>
<button onClick={handleRequestPermission} disabled={requesting}>
{requesting ? 'Requesting...' : 'Grant Permission'}
</button>
{error && <p style={{ color: 'red', marginTop: 10 }}>{error}</p>}
</div>
)}
<p style={{ marginTop: 20, fontSize: '0.9em', color: '#666' }}>
Note: You might need to enable <code>browser.ml.enable</code> and <code>extensions.ml.enabled</code> in <code>about:config</code> in Firefox Nightly.
</p>
</div>
);
};

export default Settings;
11 changes: 11 additions & 0 deletions src/settings/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import Settings from './Settings.jsx';

const container = document.getElementById('root');
if (container) {
const root = createRoot(container);
root.render(<Settings />);
} else {
console.error('Could not find #root container for settings');
}
16 changes: 16 additions & 0 deletions src/settings/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Firefox Recap Settings</title>
<style>
body { margin: 0; font-family: sans-serif; }
button { padding: 8px 15px; font-size: 14px; cursor: pointer; }
button:disabled { opacity: 0.6; cursor: not-allowed; }
</style>
</head>
<body>
<div id="root"></div>
<script src="settings.js"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
entry: {
popup: './src/popup/index.jsx',
recap: './src/popup/recap.jsx',
background: './src/background/background.js'
background: './src/background/background.js',
settings: './src/settings/index.jsx'
},
output: {
filename: '[name].js',
Expand Down Expand Up @@ -33,6 +34,7 @@ module.exports = {
{ from: 'src/manifest.json', to: 'manifest.json' },
{ from: 'src/popup/popup.html', to: 'popup.html' },
{ from: 'src/popup/recap.html', to: 'recap.html' },
{ from: 'src/settings/settings.html', to: 'settings.html' },
{ from: 'src/assets', to: 'assets' }
]
})
Expand Down