Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus Tools 5.7 #79

Merged
merged 16 commits into from
Jun 29, 2024
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
37 changes: 27 additions & 10 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ on:
workflow_dispatch:

jobs:
compile_linux:
build_linux_x64:
runs-on: ubuntu-latest
steps:
# Checks-out repository under $GITHUB_WORKSPACE
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# Install dependencies
- name: Install Dart SDK
run: |
Expand All @@ -24,40 +24,57 @@ jobs:
dart compile exe "./bin/main.dart" -o "./nexustools"
# Upload binary
- name: Upload Dart executable
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: nexustools-linux-x64
path: nexustools
compile_windows:
build_windows_x64:
runs-on: windows-latest
steps:
- name: Install Dart SDK
run: |
choco install dart-sdk
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Compile Dart executable
run: |
C:\tools\dart-sdk\bin\dart pub get
C:\tools\dart-sdk\bin\dart compile exe "bin\main.dart" -o "nexustools.exe"
- name: Upload Dart executable
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: nexustools-windows-x64
path: nexustools.exe
compile_macos:
runs-on: macos-latest
build_macos_x64:
runs-on: macos-12
steps:
- name: Install Dart SDK
run: |
brew tap dart-lang/dart
brew install dart
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Compile Dart executable
run: |
dart pub get
dart compile exe "./bin/main.dart" -o "./nexustools"
- name: Upload Dart executable
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: nexustools-macos-x64
path: nexustools
build_macos_arm:
runs-on: macos-latest
steps:
- name: Install Dart SDK
run: |
brew tap dart-lang/dart
brew install dart
- uses: actions/checkout@v4
- name: Compile Dart executable
run: |
dart pub get
dart compile exe "./bin/main.dart" -o "./nexustools"
- name: Upload Dart executable
uses: actions/upload-artifact@v4
with:
name: nexustools-macos-arm64
path: nexustools
56 changes: 30 additions & 26 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-
String linuxZip = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip';
String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip';
Map envVars = io.Platform.environment;
double appVersion = 5.6;
double appVersion = 5.7;
String baseRepo = 'corbindavenport/nexus-tools';

// Function for checking for update
Expand Down Expand Up @@ -50,7 +50,7 @@ String nexusToolsDir() {
}

// Function for installing Platform Tools package
Future installPlatformTools() async {
Future installPlatformTools(cpuArch) async {
print('[INFO] You agree to the Terms & Conditions by installing this software: https://developer.android.com/studio/terms');
var dir = nexusToolsDir();
// Get the proper ZIP file
Expand All @@ -68,7 +68,7 @@ Future installPlatformTools() async {
try {
var data = await http.readBytes(net);
var archive = ZipDecoder().decodeBytes(data);
extractArchiveToDisk(archive, dir);
await extractArchiveToDisk(archive, dir);
} catch (e) {
print('[EROR] There was an error downloading Platform Tools: ' + e.toString());
io.exit(1);
Expand Down Expand Up @@ -102,19 +102,23 @@ Future installPlatformTools() async {
}
// Windows-specific functions
if (io.Platform.isWindows) {
// Check if Universal Adb Driver package is already installed
var info = await io.Process.run('wmic', ['product', 'get', 'Name']);
var parsedInfo = info.stdout.toString();
if (parsedInfo.contains('Universal Adb Driver')) {
print('[ OK ] Universal ADB Drivers already installed.');
} else {
// Prompt to install drivers
print('[WARN] Drivers may be required for ADB if they are not already installed.');
io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] ');
var input = io.stdin.readLineSync();
if (input?.toLowerCase() == 'y') {
await installWindowsDrivers(dir);
// Install Universal Adb Driver package on x86_64 Windows
if (cpuArch == 'AMD64') {
var info = await io.Process.run('PowerShell', ['-Command', 'Get-WmiObject -Class Win32_Product | Select-Object -Property Name']);
var parsedInfo = info.stdout.toString();
if (parsedInfo.contains('Universal Adb Driver')) {
print('[ OK ] Universal ADB Drivers already installed.');
} else {
// Prompt to install drivers
print('[WARN] Drivers may be required for ADB if they are not already installed.');
io.stdout.write('[WARN] Install drivers from adb.clockworkmod.com? [Y/N] ');
var input = io.stdin.readLineSync();
if (input?.toLowerCase() == 'y') {
await installWindowsDrivers(dir);
}
}
} else {
print('[WARN] Universal ADB Driver package cannot be installed on $cpuArch, some devices might not work.');
}
// Check if old Nexus Tools directory needs to be deleted
var oldFolder = envVars['UserProfile'] + r'\NexusTools';
Expand Down Expand Up @@ -207,7 +211,7 @@ Future installWindowsDrivers(String dir) async {
}

// Function for Plausible Analytics reporting
void connectAnalytics() async {
void connectAnalytics(String cpuArch) async {
var uuid = Uuid();
var id = uuid.v4();
// Get exact operating system
Expand All @@ -221,12 +225,11 @@ void connectAnalytics() async {
} else {
realOS = io.Platform.operatingSystem;
}
var cpu = await sys.getCPUArchitecture();
// Set data
var net = Uri.parse('https://plausible.io/api/event');
final ipv4 = await Ipify.ipv4();
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'};
var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpu","domain":"nexustools.corbin.io"}';
var netBody = '{"name":"pageview","url":"app://localhost/$realOS/$cpuArch","domain":"nexustools.corbin.io"}';
// Send request
try {
await http.post(net, headers: netHeaders, body: netBody);
Expand All @@ -236,7 +239,7 @@ void connectAnalytics() async {
}

// Pre-installation steps
Future checkInstall() async {
Future checkInstall(String cpuArch) async {
// Check if directory already exists
var dir = nexusToolsDir();
var installExists = false;
Expand Down Expand Up @@ -270,9 +273,9 @@ Future checkInstall() async {
}
}

void printHelp() {
void printHelp(cpuArch) {
var helpDoc = '''
Nexus Tools $appVersion
Nexus Tools $appVersion on $cpuArch
Downloader/management app for Android SDK Platform Tools

Usage: nexustools [OPTIONS]
Expand All @@ -290,8 +293,9 @@ Example: nexustools -i (this installs Platform Tools)
}

void main(List<String> arguments) async {
var cpuArch = await sys.getCPUArchitecture();
if (arguments.contains('-i') || arguments.contains('--install')) {
print('[INFO] Nexus Tools $appVersion');
print('[INFO] Nexus Tools $appVersion on $cpuArch');
// Check version unless Nexus Tools is running from web (curl) installer
// The web installer adds the -w parameter
if (!arguments.contains('-w')) {
Expand All @@ -301,11 +305,11 @@ void main(List<String> arguments) async {
if (arguments.contains('--no-analytics')) {
print('[ OK ] Plausible Analytics are disabled.');
} else {
connectAnalytics();
connectAnalytics(cpuArch);
}
// Start installation
await checkInstall();
await installPlatformTools();
await checkInstall(cpuArch);
await installPlatformTools(cpuArch);
// Post-install
var appName = '';
if (io.Platform.isWindows) {
Expand All @@ -322,7 +326,7 @@ void main(List<String> arguments) async {
// Start removal
await removePlatformTools();
} else if (arguments.contains('-h') || arguments.contains('--help')) {
printHelp();
printHelp(cpuArch);
} else if (arguments.contains('-c') || arguments.contains('--check')) {
await checkUpdate();
} else {
Expand Down
9 changes: 4 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ fi
mkdir -p $DIR

# Start Dart executable
if [ "$OS" = "Darwin" ]; then # macOS
# Install Rosetta x86 emulation layer if needed
if [ "$ARCH" = "arm64" ]; then
echo "[WARN] Rosetta 2 compatibility layer is required. If installation fails, run Nexus Tools again after running this command: /usr/sbin/softwareupdate --install-rosetta"
fi
if [ "$OS" = "Darwin" ] && [ "$ARCH" = "arm64" ]; then # Apple Silicon Mac
DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-arm64.zip"
_run_executable
elif [ "$OS" = "Darwin" ] && [ "$ARCH" = "x86_64" ]; then # Intel Mac
DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-x64.zip"
_run_executable
elif [ "$OS" = "Linux" ] && [ "$ARCH" = "x86_64" ]; then # Generic Linux
Expand Down
24 changes: 11 additions & 13 deletions lib/sys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,24 @@ void checkIfInstalled(String dir, String command, String commandName) async {
}
}

// Function get current CPU architecture
// Function to get the current CPU architecture
Future<String> getCPUArchitecture() async {
if (io.Platform.isWindows) {
// Possible values: AMD64, ARM64
var cpu = envVars['PROCESSOR_ARCHITECTURE'];
return cpu;
} else if (io.Platform.isMacOS) {
// Get architecture reported by the system
var info = await io.Process.run('uname', ['-m']);
var cpu = info.stdout.toString().replaceAll('\n', '');
if (cpu == 'x86_64') {
// Check if running under Rosetta 2
var rosetta = await io.Process.run('sysctl', ['-in', 'sysctl.proc_translated']);
var rosettaStr = rosetta.stdout.toString().replaceAll('\n', '');
// This command will run '1' if we're running under Rosetta 2
if (rosettaStr == '1') {
cpu = 'arm64';
// Check if being emulated in ARM and return true architecture
try {
var buildArch = await io.Process.run('reg', ['query', r'HKEY_LOCAL_MACHINE\SYSTEM\Software\Microsoft\BuildLayers\DesktopEditions', '/v', 'BuildArch']);
if (buildArch.stdout.toString().toLowerCase().contains('arm64')) {
cpu = 'ARM64';
}
} catch (e) {
// Fail silently
}
return cpu;
} else {
// Possible values: x86_64, arm64
// This doesn't check for Rosetta emulation on macOS
var info = await io.Process.run('uname', ['-m']);
var cpu = info.stdout.toString().replaceAll('\n', '');
return cpu;
Expand Down
Loading