Skip to content

Commit 5d2ee5c

Browse files
Merge pull request #79 from corbindavenport/dev
Nexus Tools 5.7
2 parents a1b1c63 + ff6a441 commit 5d2ee5c

File tree

6 files changed

+117
-99
lines changed

6 files changed

+117
-99
lines changed

.github/workflows/compile.yaml

+27-10
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ on:
33
workflow_dispatch:
44

55
jobs:
6-
compile_linux:
6+
build_linux_x64:
77
runs-on: ubuntu-latest
88
steps:
99
# Checks-out repository under $GITHUB_WORKSPACE
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
1111
# Install dependencies
1212
- name: Install Dart SDK
1313
run: |
@@ -24,40 +24,57 @@ jobs:
2424
dart compile exe "./bin/main.dart" -o "./nexustools"
2525
# Upload binary
2626
- name: Upload Dart executable
27-
uses: actions/upload-artifact@v2
27+
uses: actions/upload-artifact@v4
2828
with:
2929
name: nexustools-linux-x64
3030
path: nexustools
31-
compile_windows:
31+
build_windows_x64:
3232
runs-on: windows-latest
3333
steps:
3434
- name: Install Dart SDK
3535
run: |
3636
choco install dart-sdk
37-
- uses: actions/checkout@v2
37+
- uses: actions/checkout@v4
3838
- name: Compile Dart executable
3939
run: |
4040
C:\tools\dart-sdk\bin\dart pub get
4141
C:\tools\dart-sdk\bin\dart compile exe "bin\main.dart" -o "nexustools.exe"
4242
- name: Upload Dart executable
43-
uses: actions/upload-artifact@v2
43+
uses: actions/upload-artifact@v4
4444
with:
4545
name: nexustools-windows-x64
4646
path: nexustools.exe
47-
compile_macos:
48-
runs-on: macos-latest
47+
build_macos_x64:
48+
runs-on: macos-12
4949
steps:
5050
- name: Install Dart SDK
5151
run: |
5252
brew tap dart-lang/dart
5353
brew install dart
54-
- uses: actions/checkout@v2
54+
- uses: actions/checkout@v4
5555
- name: Compile Dart executable
5656
run: |
5757
dart pub get
5858
dart compile exe "./bin/main.dart" -o "./nexustools"
5959
- name: Upload Dart executable
60-
uses: actions/upload-artifact@v2
60+
uses: actions/upload-artifact@v4
6161
with:
6262
name: nexustools-macos-x64
63+
path: nexustools
64+
build_macos_arm:
65+
runs-on: macos-latest
66+
steps:
67+
- name: Install Dart SDK
68+
run: |
69+
brew tap dart-lang/dart
70+
brew install dart
71+
- uses: actions/checkout@v4
72+
- name: Compile Dart executable
73+
run: |
74+
dart pub get
75+
dart compile exe "./bin/main.dart" -o "./nexustools"
76+
- name: Upload Dart executable
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: nexustools-macos-arm64
6380
path: nexustools

bin/main.dart

+30-26
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-
1010
String linuxZip = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip';
1111
String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip';
1212
Map envVars = io.Platform.environment;
13-
double appVersion = 5.6;
13+
double appVersion = 5.7;
1414
String baseRepo = 'corbindavenport/nexus-tools';
1515

1616
// Function for checking for update
@@ -50,7 +50,7 @@ String nexusToolsDir() {
5050
}
5151

5252
// Function for installing Platform Tools package
53-
Future installPlatformTools() async {
53+
Future installPlatformTools(cpuArch) async {
5454
print('[INFO] You agree to the Terms & Conditions by installing this software: https://developer.android.com/studio/terms');
5555
var dir = nexusToolsDir();
5656
// Get the proper ZIP file
@@ -68,7 +68,7 @@ Future installPlatformTools() async {
6868
try {
6969
var data = await http.readBytes(net);
7070
var archive = ZipDecoder().decodeBytes(data);
71-
extractArchiveToDisk(archive, dir);
71+
await extractArchiveToDisk(archive, dir);
7272
} catch (e) {
7373
print('[EROR] There was an error downloading Platform Tools: ' + e.toString());
7474
io.exit(1);
@@ -102,19 +102,23 @@ Future installPlatformTools() async {
102102
}
103103
// Windows-specific functions
104104
if (io.Platform.isWindows) {
105-
// Check if Universal Adb Driver package is already installed
106-
var info = await io.Process.run('wmic', ['product', 'get', 'Name']);
107-
var parsedInfo = info.stdout.toString();
108-
if (parsedInfo.contains('Universal Adb Driver')) {
109-
print('[ OK ] Universal ADB Drivers already installed.');
110-
} else {
111-
// Prompt to install drivers
112-
print('[WARN] Drivers may be required for ADB if they are not already installed.');
113-
io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] ');
114-
var input = io.stdin.readLineSync();
115-
if (input?.toLowerCase() == 'y') {
116-
await installWindowsDrivers(dir);
105+
// Install Universal Adb Driver package on x86_64 Windows
106+
if (cpuArch == 'AMD64') {
107+
var info = await io.Process.run('PowerShell', ['-Command', 'Get-WmiObject -Class Win32_Product | Select-Object -Property Name']);
108+
var parsedInfo = info.stdout.toString();
109+
if (parsedInfo.contains('Universal Adb Driver')) {
110+
print('[ OK ] Universal ADB Drivers already installed.');
111+
} else {
112+
// Prompt to install drivers
113+
print('[WARN] Drivers may be required for ADB if they are not already installed.');
114+
io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] ');
115+
var input = io.stdin.readLineSync();
116+
if (input?.toLowerCase() == 'y') {
117+
await installWindowsDrivers(dir);
118+
}
117119
}
120+
} else {
121+
print('[WARN] Universal ADB Driver package cannot be installed on $cpuArch, some devices might not work.');
118122
}
119123
// Check if old Nexus Tools directory needs to be deleted
120124
var oldFolder = envVars['UserProfile'] + r'\NexusTools';
@@ -207,7 +211,7 @@ Future installWindowsDrivers(String dir) async {
207211
}
208212

209213
// Function for Plausible Analytics reporting
210-
void connectAnalytics() async {
214+
void connectAnalytics(String cpuArch) async {
211215
var uuid = Uuid();
212216
var id = uuid.v4();
213217
// Get exact operating system
@@ -221,12 +225,11 @@ void connectAnalytics() async {
221225
} else {
222226
realOS = io.Platform.operatingSystem;
223227
}
224-
var cpu = await sys.getCPUArchitecture();
225228
// Set data
226229
var net = Uri.parse('https://plausible.io/api/event');
227230
final ipv4 = await Ipify.ipv4();
228231
var netHeaders = {'user-agent': 'Nexus Tools', 'X-Forwarded-For': ipv4, 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 ($realOS) AppleWebKit/500 (KHTML, like Gecko) Chrome/$appVersion $id'};
229-
var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpu","domain":"nexustools.corbin.io"}';
232+
var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpuArch","domain":"nexustools.corbin.io"}';
230233
// Send request
231234
try {
232235
await http.post(net, headers: netHeaders, body: netBody);
@@ -236,7 +239,7 @@ void connectAnalytics() async {
236239
}
237240

238241
// Pre-installation steps
239-
Future checkInstall() async {
242+
Future checkInstall(String cpuArch) async {
240243
// Check if directory already exists
241244
var dir = nexusToolsDir();
242245
var installExists = false;
@@ -270,9 +273,9 @@ Future checkInstall() async {
270273
}
271274
}
272275

273-
void printHelp() {
276+
void printHelp(cpuArch) {
274277
var helpDoc = '''
275-
Nexus Tools $appVersion
278+
Nexus Tools $appVersion on $cpuArch
276279
Downloader/management app for Android SDK Platform Tools
277280
278281
Usage: nexustools [OPTIONS]
@@ -290,8 +293,9 @@ Example: nexustools -i (this installs Platform Tools)
290293
}
291294

292295
void main(List<String> arguments) async {
296+
var cpuArch = await sys.getCPUArchitecture();
293297
if (arguments.contains('-i') || arguments.contains('--install')) {
294-
print('[INFO] Nexus Tools $appVersion');
298+
print('[INFO] Nexus Tools $appVersion on $cpuArch');
295299
// Check version unless Nexus Tools is running from web (curl) installer
296300
// The web installer adds the -w parameter
297301
if (!arguments.contains('-w')) {
@@ -301,11 +305,11 @@ void main(List<String> arguments) async {
301305
if (arguments.contains('--no-analytics')) {
302306
print('[ OK ] Plausible Analytics are disabled.');
303307
} else {
304-
connectAnalytics();
308+
connectAnalytics(cpuArch);
305309
}
306310
// Start installation
307-
await checkInstall();
308-
await installPlatformTools();
311+
await checkInstall(cpuArch);
312+
await installPlatformTools(cpuArch);
309313
// Post-install
310314
var appName = '';
311315
if (io.Platform.isWindows) {
@@ -322,7 +326,7 @@ void main(List<String> arguments) async {
322326
// Start removal
323327
await removePlatformTools();
324328
} else if (arguments.contains('-h') || arguments.contains('--help')) {
325-
printHelp();
329+
printHelp(cpuArch);
326330
} else if (arguments.contains('-c') || arguments.contains('--check')) {
327331
await checkUpdate();
328332
} else {

install.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ fi
3333
mkdir -p $DIR
3434

3535
# Start Dart executable
36-
if [ "$OS" = "Darwin" ]; then # macOS
37-
# Install Rosetta x86 emulation layer if needed
38-
if [ "$ARCH" = "arm64" ]; then
39-
echo "[WARN] Rosetta 2 compatibility layer is required. If installation fails, run Nexus Tools again after running this command: /usr/sbin/softwareupdate --install-rosetta"
40-
fi
36+
if [ "$OS" = "Darwin" ] && [ "$ARCH" = "arm64" ]; then # Apple Silicon Mac
37+
DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-arm64.zip"
38+
_run_executable
39+
elif [ "$OS" = "Darwin" ] && [ "$ARCH" = "x86_64" ]; then # Intel Mac
4140
DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-x64.zip"
4241
_run_executable
4342
elif [ "$OS" = "Linux" ] && [ "$ARCH" = "x86_64" ]; then # Generic Linux

lib/sys.dart

+11-13
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,24 @@ void checkIfInstalled(String dir, String command, String commandName) async {
2525
}
2626
}
2727

28-
// Function get current CPU architecture
28+
// Function to get the current CPU architecture
2929
Future<String> getCPUArchitecture() async {
3030
if (io.Platform.isWindows) {
31+
// Possible values: AMD64, ARM64
3132
var cpu = envVars['PROCESSOR_ARCHITECTURE'];
32-
return cpu;
33-
} else if (io.Platform.isMacOS) {
34-
// Get architecture reported by the system
35-
var info = await io.Process.run('uname', ['-m']);
36-
var cpu = info.stdout.toString().replaceAll('\n', '');
37-
if (cpu == 'x86_64') {
38-
// Check if running under Rosetta 2
39-
var rosetta = await io.Process.run('sysctl', ['-in', 'sysctl.proc_translated']);
40-
var rosettaStr = rosetta.stdout.toString().replaceAll('\n', '');
41-
// This command will run '1' if we're running under Rosetta 2
42-
if (rosettaStr == '1') {
43-
cpu = 'arm64';
33+
// Check if being emulated in ARM and return true architecture
34+
try {
35+
var buildArch = await io.Process.run('reg', ['query', r'HKEY_LOCAL_MACHINE\SYSTEM\Software\Microsoft\BuildLayers\DesktopEditions', '/v', 'BuildArch']);
36+
if (buildArch.stdout.toString().toLowerCase().contains('arm64')) {
37+
cpu = 'ARM64';
4438
}
39+
} catch (e) {
40+
// Fail silently
4541
}
4642
return cpu;
4743
} else {
44+
// Possible values: x86_64, arm64
45+
// This doesn't check for Rosetta emulation on macOS
4846
var info = await io.Process.run('uname', ['-m']);
4947
var cpu = info.stdout.toString().replaceAll('\n', '');
5048
return cpu;

0 commit comments

Comments
 (0)