Skip to content

feat(browser): set a default device size for the in-app preview - #2966

Open
heyitsaadin wants to merge 20 commits into
Acode-Foundation:mainfrom
heyitsaadin:feat/preview-default-device
Open

heyitsaadin wants to merge 20 commits into
Acode-Foundation:mainfrom
heyitsaadin:feat/preview-default-device

Conversation

@heyitsaadin

Copy link
Copy Markdown

What
The in-app preview browser always opens in the phone's native mobile view. This adds a way to choose a default preview size.

How it works

  • Turn on Devices, then pick a preset or set a custom Width/Height/Scale.
  • New menu item Set as Default saves the current size. Clear Default removes it.
  • When a default is set, the preview opens in Devices mode with that size.
  • Without a saved default, behavior is unchanged.

Implementation
Values are stored in SharedPreferences (acode_browser). Changes are limited to Browser.java and Emulator.java.

Notes

  • Saved values are screen pixels (clamped on restore), so custom sizes are device-specific.
  • Happy to move this into the Settings page instead if you'd prefer.

Related: "Html Rendering options" feature request on Discord.

@github-actions github-actions Bot added the enhancement New feature or request label Oct 10, 2026
@heyitsaadin

Copy link
Copy Markdown
Author
Screenshot_20261011_093652

@heyitsaadin
heyitsaadin marked this pull request as ready for review October 11, 2026 04:10
@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the startup reload is fixed and no new blocking issue was found.

Summary

The PR saves a default preview size and restores it when the browser opens.

  • The in-app preview opens with your saved device size.

The previous startup-reload finding is fixed. No new actionable issues were found.

Reviews (2) · Last reviewed commit: "fix(browser): only apply dimensions afte..." · Reviewed by Greptile

Comment thread src/plugins/browser/android/com/foxdebug/browser/Browser.java Outdated
@bajrangCoder

This comment was marked as outdated.

Comment on lines +347 to +375
int width = Math.min(
prefs.getInt("default_width", widthSeekBar.getMax()),
widthSeekBar.getMax()
);
int height = Math.min(
prefs.getInt("default_height", heightSeekBar.getMax()),
heightSeekBar.getMax()
);

widthSeekBar.setProgress(width);
heightSeekBar.setProgress(height);
setMaxScale(width, height);
int scale = Math.min(
prefs.getInt("default_scale", 100),
scaleSeekBar.getMax()
);
scaleSeekBar.setProgress(scale);

String name = prefs.getString("default_device", "Custom");
for (Device device : deviceListView.devices) {
if (device.name.equals(name)) {
if (deviceListView.selectedDeviceView != null) {
deviceListView.selectedDeviceView.deselect();
}
deviceListView.select(device);
selectedDevice = device;
break;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the screen size changes, a saved preset comes back with the wrong shape.

The saved width/height are screen pixels taken after selectDevice fitted the preset to the screen at save time. Here they're clamped separately with Math.min, and then the preset is highlighted by name. selectDevice instead shrinks both sides by the same ratio.

Example: save "iPad" in portrait, then open the preview in landscape, split-screen, or on the other screen of a foldable. The width stays the same and only the height gets cut, but the list still shows "iPad". (BrowserActivity handles orientation|screenSize itself, so the screen size really does vary between opens.)

Suggestion: if the saved name is a preset, call selectDevice(device) so it refits to the current screen, then apply the saved scale. Keep the raw width/height restore only for "Custom".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. A saved preset is now re-fitted with selectDevice() to the current screen, then the saved scale is applied. Raw width/height is only used for Custom. Tested by saving Laptop in portrait and reopening in landscape


// Apply the saved mode before the first navigation so the page is not
// loaded with the wrong user agent and then reloaded.
setDesktopMode(true, false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desktop user agent is set before the first load (good), but the first page load still happens at full size, not at the saved size.

BrowserActivity.onCreate calls browser.setUrl(url) right after the constructor, before any layout happens. The saved size only arrives two layout passes later: first the webview's layout listener below, then the emulator's own listener in setReference, which calls restoreDefaultDevice. So the page starts loading at the full webview width and is resized partway through.

CSS media queries will adjust after the resize, but scripts that read innerWidth or measure the layout once on load will keep the full-size values. A fast localhost server may even finish the page before the resize. Switching Devices on by hand doesn't have this problem, because it reloads after the size is applied.

This depends on timing, so could you check it on a device with a page that logs innerWidth on load? If it reproduces, reload once after the saved size is applied, but only if the page has already started loading.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page now reloads once after the saved size is applied, and only if a page was already requested.

menu.setChecked("Console", false);
menu.setVisible("Console", false);
addView(deviceEmulator);
fitWebViewTo(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: at this point the emulator hasn't set up its sliders yet (setReference does that in a later layout pass). So this call shrinks the webview to a placeholder size and pushes that size into the page's viewport before the real size is applied. Switching Devices on by hand has the same flicker, but now it happens during the first page load. Could this call be skipped here and the size left to restoreDefaultDevice?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restoreDefaultDevice handles sizing now


private void updateDefaultItems(boolean emulatorOn) {
menu.setVisible("Set as Default", emulatorOn);
menu.setVisible("Clear Default", emulatorOn);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "Clear Default" shows up in Devices mode even when nothing is saved, and the toast still says "Default cleared". Show it only when Emulator.hasDefault(context) is true, and update its visibility after Set/Clear.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now shown only when hasDefault() is true, and refreshed after Set/Clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants