Restyle Charles with Flat Look-and-Feel
- 中
- en
What is Charles
A man-in-the-middle proxy that can be used to intercept network traffics between 2 devices.
By default it uses whatever the Java Swing default is, so… here we are:
Install FlatLAF for Arch Linux
Firstly, prepare our workspace directory and download FlatLAF 2.3:
sudo mkdir -p /opt/charles_flatlaf
sudo wget -O /opt/charles_flatlaf/flatlaf-2.3.jar \
'https://search.maven.org/remotecontent?filepath=com/formdev/flatlaf/2.3/flatlaf-2.3.jar'
Write our loader to the workspace:
sudo tee /opt/charles_flatlaf/launch_charles <<'EOF'
#!/bin/sh
# Setup some variables...
JAVA="java"
CHARLES_LIB="/usr/share/java/charles"
THEME="com.formdev.flatlaf.FlatLightLaf"
exec "$JAVA" $OPTS \
-Xmx1024M \
-Dawt.useSystemAAFontSettings=on \
-Dswing.aatext=true \
-Dswing.defaultlaf="$THEME" \
-Dswing.crossplatformlaf="$THEME" \
-Dcharles.config="${XDG_CONFIG_HOME:-~/.config/charles}/.charles.config" \
-Djava.library.path="$CHARLES_LIB" \
-classpath "/opt/charles_flatlaf/flatlaf-2.3.jar:${CHARLES_LIB}/charles.jar" \
com.xk72.charles.gui.MainWithClassLoader \
"$@"
EOF
Finally, mark it as executable, and have it in the $PATH
with higher priority:
sudo chmod a+x /opt/charles_flatlaf/launch_charles
sudo ln -s /opt/charles_flatlaf/launch_charles /usr/local/bin/charles
If we don’t want it anymore, just remove them:
sudo rm -rf "/opt/charles_flatlaf/"
sudo rm "/usr/local/bin/charles"
※ Flags were inspired from discussions in AUR 1.
※ Does not work in Ubuntu. Please wait for update or adjust the script accordingly…
Install FlatLAF for Windows
Windows is a bit tricky - it uses an executable file to load the Java application, and ignores swing
flags.
We’ll have to get our hands dirty in this case…
- Install a full copy of JDK 11, for instance Adoptium JDK 11. Embedded JDK is missing some modules.
- Remember the path you’ve installed to. The default should be:
C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot\
- Download the latest release of CharlesFlatLAF or compile your own, place it under
<Charles>/lib
; - Update
Charles.ini
:- Make a backup.
- Insert the following line after
classpath.1
:classpath.2=lib/charles_flatlaf-1.0-SNAPSHOT-jar-with-dependencies.jar
- Replace the line with
main.class
to:main.class=uk.jixun.charles.theme.Main
- Insert the following line after
vmarg.4
:vmarg.5=-javaagent=lib/charles_flatlaf-1.0-SNAPSHOT-jar-with-dependencies.jar
- Replace the line with
vm.location
to:vm.location=<JDK path>\bin\server\jvm.dll
… and your final Charles.ini
should look some-what like this:
working.directory=.
classpath.1=lib/charles.jar
classpath.2=lib/CharlesFlatLAF-1.0-SNAPSHOT-jar-with-dependencies.jar
main.class=uk.jixun.charles.theme.Main
vm.version.min=11
vm.location=C:\Program Files\Eclipse Adoptium\jdk-11.0.15.10-hotspot\bin\server\jvm.dll
vmarg.1=-Dsun.java2d.d3d=false
vmarg.2=-Djava.net.preferIPv4Stack=false
vmarg.3=-Djava.net.preferIPv6Addresses=true
vmarg.4=-Djava.library.path=lib
vmarg.5=-javaagent:lib/CharlesFlatLAF-1.0-SNAPSHOT-jar-with-dependencies.jar
dde.enabled=true
dde.class=com.xk72.charles.win32.Win32DDEManager
dde.server.name=Charles
dde.topic=System
single.instance=dde
log.level=warning
[ErrorMessages]
java.not.found=The bundled Java installation was not found. Please uninstall and reinstall Charles.
java.failed=The bundled Java installation is broken. Please uninstall and reinstall Charles.
Start Charles via Desktop shortcut, just as expected:
Afterthoughts
You might have noticed that it looks exactly like zaproxy
.
Indeed, I was researching for alternatives and I quite liked the zaproxy
theming; however I’d like to make the layout closer to Charles…
I thought, they are both made of Java. There must’ve been a way to apply the same theme. So I went and looked around, got this Java Agent to monkey patch things.
Experimenting further under Linux, it works without the agent - what a surprise. Tried to back-port the steps to Windows, no joy. welp.
See this AUR comment regarding Font AA & GTK theming for Charles. ↩︎