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
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"features": {
"ghcr.io/devcontainers/features/node:2.1": {
"version": "2.1.0",
"resolved": "ghcr.io/devcontainers/features/node@sha256:586c9a6f7dd40bd3ba2cd41e7f2f88dcc31fbe5d1442afcbf07ffbc66b686857",
"integrity": "sha256:586c9a6f7dd40bd3ba2cd41e7f2f88dcc31fbe5d1442afcbf07ffbc66b686857"
"version": "2.1.1",
"resolved": "ghcr.io/devcontainers/features/node@sha256:2a19d3b0b3879437637cfd292eb29fee0afcfbe6364e33db9afc4f80c5c1f956",
"integrity": "sha256:2a19d3b0b3879437637cfd292eb29fee0afcfbe6364e33db9afc4f80c5c1f956"
},
"ghcr.io/nordcominc/devcontainer-features/android-sdk:2": {
"version": "2.0.0",
Expand Down
1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ multline = "multline"
sav = "sav"
ist = "ist"
Hel = "Hel"
edn = "edn"
# Apple simulator device identifier
udid = "udid"
4 changes: 2 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"files": {
"includes": [
"src/**/*.js",
"src/**/*.ts",
"dev/**/*.js",
"src/lang/**/*.json",
"src/native/**/*.ts",
"src/platforms/**/*.ts",
"tests/**",
"!fastlane/**/*",
"!platforms/**/*"
]
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"@deadlyjack/ajax": "^1.2.6",
"@emmetio/codemirror6-plugin": "^0.4.1",
"@lezer/common": "^1.5.2",
"@lezer/highlight": "^1.2.3",
"@lezer/highlight": "^1.2.5",
"@lezer/lr": "^1.4.10",
"@ungap/custom-elements": "^1.3.0",
"@xterm/addon-attach": "^0.12.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public void onDownloadStart(String url, String userAgent,
createMenu();
addView(titleLayout);
addView(webViewContainer);
restoreEmulator();
}

private void createMenu() {
Expand All @@ -228,6 +229,10 @@ private void createMenu() {
menu.addItem(Ui.Icons.DEVICES, "Devices", false);
menu.addItem(Ui.Icons.NO_CACHE, "Disable Cache", false);
menu.addItem(Ui.Icons.TERMINAL, "Console", false);
menu.addItem(Ui.Icons.TUNE, "Set as Default");
menu.addItem(Ui.Icons.REFRESH, "Clear Default");
menu.setVisible("Set as Default", false);
menu.setVisible("Clear Default", false);
menu.addItem(Ui.Icons.OPEN_IN_BROWSER, "Open in Browser");
menu.addItem(Ui.Icons.EXIT, "Exit");

Expand All @@ -242,6 +247,7 @@ public void onSelect(String action, Boolean checked) {
}

emulator = checked;
updateDefaultItems(checked);
if (checked) {
setDesktopMode(true);
setConsoleVisible(false);
Expand Down Expand Up @@ -276,6 +282,26 @@ public void onGlobalLayout() {
case "Console":
setConsoleVisible(checked);
break;
case "Set as Default":
if (deviceEmulator != null) {
deviceEmulator.saveAsDefault();
updateDefaultItems(emulator);
Toast
.makeText(
context,
"Saved as default preview",
Toast.LENGTH_SHORT
)
.show();
}
break;
case "Clear Default":
Emulator.clearDefault(context);
updateDefaultItems(emulator);
Toast
.makeText(context, "Default cleared", Toast.LENGTH_SHORT)
.show();
break;
case "Disable Cache":
webView
.getSettings()
Expand All @@ -300,6 +326,75 @@ public void onGlobalLayout() {
);
}

private void updateDefaultItems(boolean emulatorOn) {
menu.setVisible("Set as Default", emulatorOn);
menu.setVisible(
"Clear Default",
emulatorOn && Emulator.hasDefault(context)
);
}

private void reloadAfterLayout() {
// If no page was requested yet, the first load will already happen at
// the saved size, so there is nothing to reload.
if (url.isEmpty()) return;

webView
.getViewTreeObserver()
.addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
webView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
webView.reload();
}
}
);
}

private void restoreEmulator() {
if (onlyConsole) return;
if (!Emulator.hasDefault(context)) return;

// 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);

webView
.getViewTreeObserver()
.addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (webView.getMeasuredWidth() == 0) return;
webView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

if (deviceEmulator == null) {
createDeviceEmulatorLayout();
deviceEmulator.setRestoredListener(
new Runnable() {
@Override
public void run() {
reloadAfterLayout();
}
}
);
}

emulator = true;
menu.setChecked("Devices", true);
updateDefaultItems(true);
setConsoleVisible(false);
menu.setChecked("Console", false);
menu.setVisible("Console", false);
addView(deviceEmulator);
// The emulator sets up its sliders on a later layout pass and then
// applies the saved size itself, so the webview is not resized here.
}
}
);
}

private void createDeviceEmulatorLayout() {
Browser browser = this;
deviceEmulator = new Emulator(context, theme);
Expand Down Expand Up @@ -331,6 +426,10 @@ private void setTextViewProperties(TextView textView, int height) {
}

private void setDesktopMode(boolean enabled) {
setDesktopMode(enabled, true);
}

private void setDesktopMode(boolean enabled, boolean reload) {
int width = 0;
int height = 0;
WebSettings webSettings = webView.getSettings();
Expand All @@ -352,7 +451,9 @@ private void setDesktopMode(boolean enabled) {
webSettings.setLoadWithOverviewMode(enabled);
webSettings.setSupportZoom(enabled);
webSettings.setBuiltInZoomControls(enabled);
webView.reload();
if (reload) {
webView.reload();
}
}

public void setDesktopMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
if (listener != null) {
listener.onChange(iWidth, correctedHeight, 1);
}

restoreDefaultDevice();
}
}
);
Expand Down Expand Up @@ -300,6 +302,108 @@
listener.onChange(width, height, maxScale / 100f);
}

public static boolean hasDefault(Context context) {
return context
.getSharedPreferences("acode_browser", Context.MODE_PRIVATE)
.getBoolean("default_set", false);
}

public static void clearDefault(Context context) {
context
.getSharedPreferences("acode_browser", Context.MODE_PRIVATE)
.edit()
.putBoolean("default_set", false)
.apply();
}

public void saveAsDefault() {
context
.getSharedPreferences("acode_browser", Context.MODE_PRIVATE)
.edit()
.putBoolean("default_set", true)
.putInt("default_width", getWidthProgress())
.putInt("default_height", getHeightProgress())
.putInt("default_scale", seekBars.get("scale").getProgress())
.putString(
"default_device",
selectedDevice != null ? selectedDevice.name : "Custom"
)
.apply();
}

private Runnable restoredListener;

public void setRestoredListener(Runnable listener) {
restoredListener = listener;
}

private void restoreDefaultDevice() {
if (!hasDefault(context)) return;

android.content.SharedPreferences prefs = context.getSharedPreferences(
"acode_browser",
Context.MODE_PRIVATE
);
SeekBar widthSeekBar = seekBars.get("width");
SeekBar heightSeekBar = seekBars.get("height");
SeekBar scaleSeekBar = seekBars.get("scale");
String name = prefs.getString("default_device", "Custom");

Device preset = null;
for (Device device : deviceListView.devices) {
if (device.id != customDevice.id && device.name.equals(name)) {
preset = device;
break;
}
}

if (preset != null && listener != null) {
// A preset is re-fitted to the current screen, so it keeps its shape if
// the screen size changed since it was saved (rotation, split-screen,
// foldables). Only the scale is restored from the saved value.
if (deviceListView.selectedDeviceView != null) {
deviceListView.selectedDeviceView.deselect();
}
deviceListView.select(preset);
selectDevice(preset);

int scale = Math.min(
prefs.getInt("default_scale", scaleSeekBar.getMax()),
scaleSeekBar.getMax()
);
scaleSeekBar.setProgress(scale);
listener.onChange(getWidthProgress(), getHeightProgress(), scale / 100f);
} else {
// Custom sizes are restored from the saved width/height.
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);
selectedDevice = customDevice;

if (listener != null) {
listener.onChange(width, height, scale / 100f);
}
}

if (restoredListener != null) {
restoredListener.run();
}
}

private void setMaxScale(int width, int height) {
SeekBar scaleSeekBar = seekBars.get("scale");
SeekBar widthSeekBar = seekBars.get("width");
Expand Down Expand Up @@ -365,6 +469,7 @@
class DeviceListView extends ScrollView {

DeviceView selectedDeviceView;
ArrayList<Device> devices = new ArrayList<Device>();

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (paid, fdroid)

cannot find symbol

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (paid, fdroid)

cannot find symbol

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (paid, store)

cannot find symbol

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (paid, store)

cannot find symbol

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (free, store)

cannot find symbol

Check failure on line 472 in platforms/android/app/src/main/java/com/foxdebug/acode/browser/Emulator.java

View workflow job for this annotation

GitHub Actions / Android (free, store)

cannot find symbol
LinearLayout deviceListLayout;
Callback callback;
Context context;
Expand Down Expand Up @@ -405,6 +510,7 @@
}

public void add(Device device) {
devices.add(device);
DeviceView deviceView = new DeviceView(context, device, theme);
deviceListLayout.addView(deviceView);

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img src='res/logo_1.png' width='250'>
</p>

[![](https://img.shields.io/endpoint?logo=telegram&label=Acode&style=flat&url=https%3A%2F%2Facode.app%2Fapi%2Ftelegram-members-count)](https://t.me/foxdebug_acode) [![](https://dcbadge.vercel.app/api/server/vVxVWYUAWD?style=flat)](https://discord.gg/vVxVWYUAWD)
[![](https://img.shields.io/endpoint?logo=telegram&label=Acode&style=flat&url=https%3A%2F%2Facode.app%2Fapi%2Ftelegram-members-count)](https://t.me/foxdebug_acode) [![](https://dcbadge.limes.pink/api/server/https://discord.gg/vVxVWYUAWD?style=flat)](https://discord.gg/vVxVWYUAWD)

## • Overview

Expand Down
7 changes: 2 additions & 5 deletions src/cm/baseExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { highlightSelectionMatches } from "@codemirror/search";
import type { Extension } from "@codemirror/state";
import { EditorState, Prec } from "@codemirror/state";
import indentationFolding from "./indentationFolding";
import {
crosshairCursor,
drawSelection,
Expand All @@ -27,6 +26,7 @@ import {
rectangularSelection,
tooltips,
} from "@codemirror/view";
import indentationFolding from "./indentationFolding";

export interface BaseExtensionOptions {
autoIndent?: boolean;
Expand All @@ -51,10 +51,7 @@ export default function createBaseExtensions(
highlightActiveLine: enableHighlightActiveLine = true,
highlightSelectionMatches: enableHighlightSelectionMatches = true,
} = options;
const extensions: Extension[] = [
highlightSpecialChars(),
history(),
];
const extensions: Extension[] = [highlightSpecialChars(), history()];

if (enableHighlightActiveLine) extensions.push(highlightActiveLineGutter());
if (codeFolding) extensions.push(foldGutter(), indentationFolding);
Expand Down
5 changes: 2 additions & 3 deletions src/cm/colorChip.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { LSPClient } from "@codemirror/lsp-client";
import { getAllLspPlugins } from "./lsp/clientLoader";
import type { Range } from "@codemirror/state";
import { Decoration, EditorView, WidgetType } from "@codemirror/view";
import pickColor from "dialogs/color";
import color from "utils/color";
import type { Color as LspColor } from "vscode-languageserver-types";
import { getAllLspPlugins } from "./lsp/clientLoader";

export const COLOR_CHIP_CLASS = "cm-color-chip";
export const COLOR_CHIP_SOURCE_ATTR = "data-color-source";
Expand Down Expand Up @@ -96,8 +96,7 @@ export function isViewEditable(view: EditorView): boolean {
export function hasLspColorProvider(view: EditorView): boolean {
return getAllLspPlugins(view, "documentColor").some(
(lsp) =>
lsp.client.connected &&
!!lsp.client.serverCapabilities?.colorProvider,
lsp.client.connected && !!lsp.client.serverCapabilities?.colorProvider,
);
}

Expand Down
Loading
Loading