.
675 |
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | # XWaydroid
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | XWaydroid, the Waydroid launcher tool to improve the user experience of KDE / X-Server users!
20 |
21 | ## Note-able Features
22 | - Directly launch the full `waydroid` UI in a `wayland` session window
23 | - Directly launch `waydroid` apps in a `wayland` session window
24 | - Easily patch all your `waydroid.*.desktop` files,
25 | to directly launch in a `wayland` session window through `xwaydroid`!
26 |
27 | ## Dependencies
28 | XWaydroid requires the following dependencies to work properly,
29 | installation of these is out of the scope of this guide.
30 |
31 | - [Waydroid](https://github.com/waydroid/waydroid) *(Guide assumes `waydroid-container.service` has been enabled)*
32 | - [KWin_Wayland](https://community.kde.org/KWin/Wayland)
33 | - [ADB](https://developer.android.com/tools/adb)
34 |
35 | ## Installation
36 | 1. Download the latest [XWaydroid](https://github.com/Rikj000/XWaydroid/releases) release
37 | 2. Unzip it somewhere (e.g. `/home//Documents/XWaydroid/>`)
38 | 3. Create a symbolic link to `/usr/bin/xwaydroid`:
39 | ```bash
40 | # Alter !
41 | sudo ln -s /home//Documents/XWaydroid/xwaydroid.sh /usr/bin/xwaydroid
42 | ```
43 |
44 | ## Updates
45 | 1. Download the latest [XWaydroid](https://github.com/Rikj000/XWaydroid/releases) release.
46 | 2. Unzip it to the previous installation location (default. `/home//Documents/XWaydroid/>`)
47 |
48 | ## Usage
49 | ```bash
50 | Usage:
51 | xwaydroid [options]
52 |
53 | Example:
54 | xwaydroid --app=com.android.calculator2
55 |
56 | Optional-Arguments:
57 | | Shorthand | Full notation | Description |
58 | | --------------------- | ------------------------------------- | ----------------------------------------------------------------- |
59 | | -h | --help | Show this help. |
60 | | -v | --version | Show the currently installed XWaydroid version number |
61 | | -a= | --app= | Name of the Waydroid app to open, defaults to: '' (show-full-ui) |
62 | | -l | --list | Lists all names of installed app. (Waydroid must be running) |
63 | | -pdf | --patch-desktop-files | Patches all the |
64 | | | | "/home//.local/share/applications/waydroid.*.desktop" |
65 | | | | files, to automatically launch through XWaydroid. |
66 | | -wb= | --waydroid-bin= | Path to the Waydroid binary, defaults to: 'waydroid' |
67 | | -wwb= | --wayland-window-bin= | Path to the Wayland window, defaults to: 'kwin_wayland' |
68 | | | | Others not yet supported. |
69 | | -www= | --wayland-window-width= | Pixel width of the Wayland window, defaults to: 3440 |
70 | | -wwh= | --wayland-window-height= | Pixel height of the Wayland window, defaults to: 1340 |
71 | ```
72 |
73 | ## Notes
74 | - Please be patient when starting the first `waydroid` app through `xwaydroid`.
75 | A black `kwin_wayland` window for a few minutes, before you see the LineageOS loading logo, is normal.
76 | - If switching between `waydroid` apps through `xwaydroid`, it's recommended to leave the `kwin_wayland` window open.
77 | Closing / re-opening the `kwin_wayland` window leads to a "reboot" of the `waydroid` session which takes a while.
78 | Leaving the `kwin_wayland` window, leads to instant startup of new `waydroid` apps.
79 | - Opening / using multiple `waydroid` apps through `xwaydroid` is supported, albeit through a single `kwin_wayland` window.
80 | - The default values of some optional-options,
81 | can be configured in the `Default Settings` section at the start of the `xwaydroid` script.
82 |
--------------------------------------------------------------------------------
/xwaydroid.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # region Default Settings
4 |
5 | WAYDROID_LAUNCH_APP="";
6 | WAYDROID_BIN="waydroid";
7 | XWAYDROID_BIN="xwaydroid";
8 | WAYLAND_WINDOW_BIN="kwin_wayland";
9 | WAYLAND_WINDOW_WIDTH=3440
10 | WAYLAND_WINDOW_HEIGHT=1340
11 |
12 | # endregion Default Settings
13 |
14 |
15 | # region Helpers
16 |
17 | usage() {
18 | cat << EOF
19 |
20 | Usage:
21 | xwaydroid [options]
22 |
23 | Example:
24 | xwaydroid --app=com.android.calculator2
25 |
26 | Optional-Arguments:
27 | | Shorthand | Full notation | Description |
28 | | --------------------- | ------------------------------------- | ----------------------------------------------------------------- |
29 | | -h | --help | Show this help. |
30 | | -v | --version | Show the currently installed XWaydroid version number |
31 | | -a= | --app= | Name of the Waydroid app to open, defaults to: '' (show-full-ui) |
32 | | -l | --list | Lists all names of installed app. (Waydroid must be running) |
33 | | -pdf | --patch-desktop-files | Patches all the |
34 | | | | "/home//.local/share/applications/waydroid.*.desktop" |
35 | | | | files, to automatically launch through XWaydroid. |
36 | | -wb= | --waydroid-bin= | Path to the Waydroid binary, defaults to: 'waydroid' |
37 | | -wwb= | --wayland-window-bin= | Path to the Wayland window, defaults to: 'kwin_wayland' |
38 | | | | Others not yet supported. |
39 | | -www= | --wayland-window-width= | Pixel width of the Wayland window, defaults to: 3440 |
40 | | -wwh= | --wayland-window-height= | Pixel height of the Wayland window, defaults to: 1340 |
41 |
42 | EOF
43 | exit 0
44 | }
45 |
46 | WAYLAND_WINDOW_WAS_OPEN=false;
47 | wayland_window_running() {
48 | if pgrep -x "$WAYLAND_WINDOW_BIN" >/dev/null
49 | then
50 | log "Service '$WAYLAND_WINDOW_BIN' is already running...";
51 | WAYLAND_WINDOW_WAS_OPEN=true;
52 | else
53 | log "Service '$WAYLAND_WINDOW_BIN' starting up...";
54 | $WAYLAND_WINDOW_BIN --width $WAYLAND_WINDOW_WIDTH --height $WAYLAND_WINDOW_HEIGHT &
55 | log_success "Service '$WAYLAND_WINDOW_BIN' started up!";
56 | fi
57 | }
58 |
59 | waydroid_running() {
60 | if [[ $WAYLAND_WINDOW_WAS_OPEN = true ]] && [[ $(pgrep -f "$WAYDROID_BIN show-full-ui") != "" ]]
61 | then
62 | log "Service '$WAYDROID_BIN' is already running...";
63 | else
64 | log "Service '$WAYDROID_BIN' starting up...";
65 | $WAYDROID_BIN session stop;
66 |
67 | while read -r line; do
68 | if [[ $line == *"Established ADB connection to Waydroid device at"* ]]; then
69 | log_success "Service '$WAYDROID_BIN' started up!";
70 | break
71 | fi
72 | done < <($WAYDROID_BIN show-full-ui 2>&1)
73 | fi
74 | }
75 |
76 | waydroid_launch_app() {
77 | if [ "$WAYDROID_LAUNCH_APP" != "" ]; then
78 | WAYDROID_LAUNCH_ACTIVITY=$(
79 | adb shell cmd package resolve-activity -c android.intent.category.LAUNCHER "$WAYDROID_LAUNCH_APP" | \
80 | sed -n '/name=/s/^.*name=//p');
81 |
82 | log "App '$WAYDROID_LAUNCH_APP' with launch activity '$WAYDROID_LAUNCH_ACTIVITY' starting up...";
83 | adb shell am start "$WAYDROID_LAUNCH_APP"/"$WAYDROID_LAUNCH_ACTIVITY" >/dev/null;
84 | log_success "App '$WAYDROID_LAUNCH_APP' with launch activity '$WAYDROID_LAUNCH_ACTIVITY' started up!";
85 | fi
86 | }
87 |
88 | waydroid_list_apps() { $WAYDROID_BIN app list | grep packageName | cut -c 14-; }
89 |
90 | xwaydroid_patch_desktop_files() {
91 | DESKTOP_FILES_PATH="/home/$(whoami)/.local/share/applications";
92 |
93 | SEARCH_STRING="Exec=waydroid app launch ";
94 | REPLACE_STRING="Exec=${XWAYDROID_BIN} --app=";
95 | sed -i "/^${SEARCH_STRING}/s#${SEARCH_STRING}#${REPLACE_STRING}#" "$DESKTOP_FILES_PATH/waydroid."*".desktop";
96 |
97 | SEARCH_STRING="Exec=waydroid show-full-ui";
98 | REPLACE_STRING="Exec=${XWAYDROID_BIN}";
99 | sed -i "/^${SEARCH_STRING}/s#${SEARCH_STRING}#${REPLACE_STRING}#" "$DESKTOP_FILES_PATH/Waydroid.desktop";
100 |
101 | log_success "Patched 'waydroid.*.desktop' files under '$DESKTOP_FILES_PATH/' to launch with XWaydroid!"
102 | }
103 |
104 | # ANSI text coloring
105 | GREEN='\033[0;32m';
106 | RED='\033[0;31m';
107 | END='\033[m';
108 |
109 | log() { echo "[$(date +"%H:%M:%S")] $1"; }
110 |
111 | log_success() { echo -e "${GREEN}$(log "$1")${END}"; }
112 |
113 | log_error() { echo -e "${RED}$(log "$1")${END}"; }
114 |
115 | # endregion Helpers
116 |
117 |
118 | # region Process Parameters
119 |
120 | # Loop through arguments and process them
121 | for arg in "$@"
122 | do
123 | case $arg in
124 | -a=*|--app=*)
125 | WAYDROID_LAUNCH_APP="${arg#*=}";
126 | shift
127 | ;;
128 | -wb=*|--waydroid-bin=*)
129 | WAYDROID_BIN="${arg#*=}";
130 | shift
131 | ;;
132 | -wwb=*|--waydroid-window-bin=*)
133 | WAYLAND_WINDOW_BIN="${arg#*=}";
134 | shift
135 | ;;
136 | -www=*|--wayland-window-width=*)
137 | WAYLAND_WINDOW_WIDTH=${arg#*=};
138 | shift
139 | ;;
140 | -wwh=*|--wayland-window-height=*)
141 | WAYLAND_WINDOW_HEIGHT=${arg#*=};
142 | shift
143 | ;;
144 | -l|--list)
145 | waydroid_list_apps;
146 | exit;
147 | shift
148 | ;;
149 | -pdf|--patch-desktop-files)
150 | xwaydroid_patch_desktop_files;
151 | exit;
152 | shift
153 | ;;
154 | -h|--help)
155 | usage
156 | shift
157 | ;;
158 | -v|--version)
159 | echo "v1.0.0"
160 | exit;
161 | shift
162 | ;;
163 | *)
164 | log_error " 🙉 Illegal argument(s) used!";
165 | echo "";
166 | log "Please see the 'xwaydroid --help' output below for the correct usage:";
167 | usage;
168 | exit;
169 | ;;
170 | esac
171 | done
172 |
173 | # endregion Process Parameters
174 |
175 |
176 | # region Main Script
177 |
178 | wayland_window_running; # 1. Ensure the Wayland window is running, open it if not
179 | waydroid_running; # 2. Ensure the Waydroid main UI is running, open it if not
180 | waydroid_launch_app; # 3. Launch the Waydroid app, if any have been provided
181 |
182 | # endregion Main Script
183 |
--------------------------------------------------------------------------------