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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ To start the development server for Firefox:
pnpm dev:firefox
```

This builds the Firefox version and runs it on a connected Android device. Make sure ADB is installed, your device is
connected with USB debugging enabled, and set the `ADB_ID` variable to your device ID (found via `adb devices`).
To develop on Android, this builds the Firefox version and runs it on a connected Android device. Make sure ADB is installed, your device is
connected with USB debugging enabled. You can pass additional `web-ext run` flags after the device ID:

```bash
# Basic usage
pnpm dev:android <device-id>

# With custom source directory
pnpm dev:android <device-id> --s ./custom-output

# With additional web-ext flags
pnpm dev:android <device-id> --adb-remove-old-artifacts
```

> [!NOTE]
> Some `web-ext run` options may not work when targeting Android devices. For example, browser startup options like `--start-url` are not supported on Android.

### Building

To build the extension for chromium browsers:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "royalrefresh",
"version": "1.4.1",
"version": "1.4.2",
"description": "A web extension for royalroad.com. For people who juggle multiple stories",
"main": "background.js",
"directories": {
Expand Down
57 changes: 50 additions & 7 deletions scripts/dev-android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,63 @@ const __dirname = path.dirname(__filename);
// Get the device ID from command line arguments
const deviceId = process.argv[2];
if (!deviceId) {
console.error('Usage: pnpm dev:android <device-id>');
console.error('Usage: pnpm dev:android <device-id> [web-ext flags...]');
console.error('Example: pnpm dev:android emulator-5554 --source-dir ./custom-dir');
process.exit(1);
}

// Get any additional flags to pass to web-ext
const additionalFlags = process.argv.slice(3);

// Extract custom source directory if provided
let customSourceDir = null;
const sourceDirIndex = additionalFlags.findIndex(flag => flag === '--source-dir' || flag === '-s');

if (sourceDirIndex !== -1) {
// Handle -s value or --source-dir value
customSourceDir = additionalFlags[sourceDirIndex + 1];
} else {
// Handle --source-dir=value
const sourceDirFlag = additionalFlags.find(flag => flag.startsWith('--source-dir='));
if (sourceDirFlag) {
customSourceDir = sourceDirFlag.split('=')[1];
}
}

// WXT builds to outDir/firefox-mv2
const wxtOutDir = customSourceDir || '.output';
const actualBuildDir = `${wxtOutDir}/firefox-mv2`;

// Remove source-dir flags from additional flags (we'll set it ourselves)
const filteredFlags = [];
for (let i = 0; i < additionalFlags.length; i++) {
const flag = additionalFlags[i];
if (flag === '--source-dir' || flag === '-s') {
i++; // Skip the next item (the value)
continue;
}
if (flag.startsWith('--source-dir=')) {
continue;
}
filteredFlags.push(flag);
}

// Build web-ext command
const webExtCommand = `web-ext run --target=firefox-android --android-device=${deviceId} --firefox-apk=org.mozilla.fenix --source-dir ${actualBuildDir} ${filteredFlags.join(' ')}`;

// Run the build and web-ext commands
try {
console.log(`Building Firefox extension...`);
execSync('pnpm build:firefox', { stdio: 'inherit', cwd: path.dirname(__dirname) });
// Set environment variable for custom output directory
if (customSourceDir) {
process.env.WXT_OUT_DIR = wxtOutDir;
console.log(`Using custom output directory: ${wxtOutDir}`);
}

console.log('Building Firefox extension...');
execSync('wxt build -b firefox', { stdio: 'inherit', cwd: path.dirname(__dirname) });

console.log(`Running on Android device ${deviceId}...`);
execSync(`web-ext run --target=firefox-android --android-device=${deviceId} --firefox-apk=org.mozilla.fenix --source-dir ./.output/firefox-mv2`, {
stdio: 'inherit',
cwd: path.dirname(__dirname)
});
execSync(webExtCommand, { stdio: 'inherit', cwd: path.dirname(__dirname) });
} catch (error) {
console.error('Command failed:', error.message);
process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from 'wxt';
// See https://wxt.dev/api/config.html
export default defineConfig({
srcDir: 'src',
outDir: process.env.WXT_OUT_DIR || '.output',
modules: ['@wxt-dev/module-svelte'],
manifest: {
name: 'RoyalRefresh',
Expand Down