From e4476580e6b31e441b488aec8caf933e0e848beb Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sat, 29 Apr 2023 17:06:52 -0400 Subject: [PATCH 01/14] Update version, move install folder for Windows --- bin/main.dart | 13 ++++-- pubspec.lock | 111 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 82 insertions(+), 42 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index fa0c10c..d3add84 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -13,7 +13,7 @@ String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip'; List supportedCPUs = ['amd64', 'x86_64', 'AMD64']; Map envVars = io.Platform.environment; -double appVersion = 5.4; +double appVersion = 5.5; // Function for checking for update Future checkUpdate() async { @@ -43,7 +43,7 @@ String nexusToolsDir() { } else if (io.Platform.isLinux) { home = envVars['HOME']; } else if (io.Platform.isWindows) { - home = envVars['UserProfile']; + home = envVars['AppData']; } if (home.endsWith('/')) { home = home.substring(0, home.length - 1); @@ -115,7 +115,7 @@ Future installPlatformTools() async { '[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); } - // Install drivers on Windows + // 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']); @@ -133,6 +133,13 @@ Future installPlatformTools() async { await installWindowsDrivers(dir); } } + // Check if old Nexus Tools directory needs to be deleted + var oldFolder = envVars['UserProfile'] + r'\' + 'NexusTools'; + var oldFolderExists = await io.Directory(oldFolder).exists(); + if (oldFolderExists) { + await io.Directory(oldFolder).delete(recursive: true); + print('[ OK ] Deleted old directory at $oldFolder.'); + } } } diff --git a/pubspec.lock b/pubspec.lock index 0e1a545..c553f92 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,120 +5,153 @@ packages: dependency: "direct dev" description: name: archive - url: "https://pub.dartlang.org" + sha256: "0c8368c9b3f0abbc193b9d6133649a614204b528982bebc7026372d61677ce3a" + url: "https://pub.dev" source: hosted - version: "3.2.2" + version: "3.3.7" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "2.11.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.1" console: dependency: "direct dev" description: name: console - url: "https://pub.dartlang.org" + sha256: e04e7824384c5b39389acdd6dc7d33f3efe6b232f6f16d7626f194f6a01ad69a + url: "https://pub.dev" source: hosted version: "4.1.0" + convert: + dependency: transitive + description: + name: convert + sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592" + url: "https://pub.dev" + source: hosted + version: "3.1.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67 + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" http: dependency: "direct dev" description: name: http - url: "https://pub.dartlang.org" + sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482" + url: "https://pub.dev" source: hosted - version: "0.13.4" + version: "0.13.5" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" source: hosted - version: "4.0.0" + version: "4.0.2" io: dependency: "direct dev" description: name: io - url: "https://pub.dartlang.org" + sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e" + url: "https://pub.dev" + source: hosted + version: "1.0.4" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" source: hosted - version: "1.0.3" + version: "0.6.7" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" + source: hosted + version: "1.8.3" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "3.7.3" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" uuid: dependency: "direct dev" description: name: uuid - url: "https://pub.dartlang.org" + sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313" + url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.7" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.19.0 <3.0.0" From e52004c27a5f294bec115dd2119a34bc9c06eca6 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sat, 29 Apr 2023 19:31:20 -0400 Subject: [PATCH 02/14] Create uninstall entry on Windows --- bin/main.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/main.dart b/bin/main.dart index d3add84..8198a13 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -134,17 +134,31 @@ Future installPlatformTools() async { } } // Check if old Nexus Tools directory needs to be deleted - var oldFolder = envVars['UserProfile'] + r'\' + 'NexusTools'; + var oldFolder = envVars['UserProfile'] + r'\NexusTools'; var oldFolderExists = await io.Directory(oldFolder).exists(); if (oldFolderExists) { await io.Directory(oldFolder).delete(recursive: true); print('[ OK ] Deleted old directory at $oldFolder.'); } + // Add entry to Windows Installed Apps List + // Documentation: https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key + var uninstallString = dir + r'\nexustools.exe'; + var regEntry = 'Windows Registry Editor Version 5.00\n\n'; + regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; + regEntry += '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; + regEntry += '\n"Publisher"="Corbin Davenport"'; + regEntry += '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; + regEntry += '\n"NoModify"=dword:00000001'; + regEntry += '\n' + r'"UninstallString"="\"' + uninstallString.replaceAll(r'\', r'\\') + r'\" --remove"'; + var regFile = await io.File('$dir/nexustools.reg'); + await regFile.writeAsString(regEntry, mode: io.FileMode.writeOnly); + await io.Process.run('reg', ['import', '$dir/nexustools.reg']); } } // Function for removing Platform Tools package Future removePlatformTools() async { + // TODO: Add support for new directory on Windows // Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools var dir = nexusToolsDir(); var installExists = false; @@ -161,6 +175,11 @@ Future removePlatformTools() async { // Proceed with deletion await io.Directory(dir).delete(recursive: true); print('[ OK ] Deleted directory at $dir.'); + // Delete registry keys on Windows + if (io.Platform.isWindows) { + await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']); + print('[ OK ] Removed registry keys.'); + } print('[INFO] Nexus Tools can be re-installed at https://git.io/JBuTh.'); } else { print('[EROR] No installation found at $dir.'); From a68c2a3fd361048516dc3b721e9e2b42c3d792ce Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sun, 30 Apr 2023 23:01:10 -0400 Subject: [PATCH 03/14] Remove CPU check, it's not needed anymore --- bin/main.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 8198a13..4c5aab2 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -11,7 +11,6 @@ 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'; -List supportedCPUs = ['amd64', 'x86_64', 'AMD64']; Map envVars = io.Platform.environment; double appVersion = 5.5; @@ -267,17 +266,6 @@ Future checkInstall() async { sys.checkIfInstalled(dir, 'adb', 'ADB'); // Check if Fastboot is already installed sys.checkIfInstalled(dir, 'fastboot', 'Fastboot'); - // Check CPU architecture - var cpu = await sys.getCPUArchitecture(); - if (supportedCPUs.contains(cpu)) { - print('[ OK ] Your hardware platform is supported, yay!'); - } else if (io.Platform.isMacOS && (cpu == 'arm64')) { - print('[ OK ] Your hardware platform is supported, yay!'); - } else { - print( - '[EROR] Your hardware platform is detected as $cpu. Google only provides Platform Tools for x86-based platforms.'); - io.exit(1); - } // Display environment-specific warnings var isWSL = await io.Directory('/mnt/c/Windows').exists(); var isChromeOS = await io.Directory('/usr/share/themes/CrosAdapta').exists(); From e2baa2c3813953634e674c78503ba26fcd6d767e Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sun, 30 Apr 2023 23:18:54 -0400 Subject: [PATCH 04/14] Uninstall command now handles both Windows dirs --- bin/main.dart | 57 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 4c5aab2..8dc4094 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -143,12 +143,18 @@ Future installPlatformTools() async { // Documentation: https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key var uninstallString = dir + r'\nexustools.exe'; var regEntry = 'Windows Registry Editor Version 5.00\n\n'; - regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; - regEntry += '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; + regEntry += + r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; + regEntry += + '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; regEntry += '\n"Publisher"="Corbin Davenport"'; - regEntry += '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; + regEntry += + '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; regEntry += '\n"NoModify"=dword:00000001'; - regEntry += '\n' + r'"UninstallString"="\"' + uninstallString.replaceAll(r'\', r'\\') + r'\" --remove"'; + regEntry += '\n' + + r'"UninstallString"="\"' + + uninstallString.replaceAll(r'\', r'\\') + + r'\" --remove"'; var regFile = await io.File('$dir/nexustools.reg'); await regFile.writeAsString(regEntry, mode: io.FileMode.writeOnly); await io.Process.run('reg', ['import', '$dir/nexustools.reg']); @@ -157,32 +163,43 @@ Future installPlatformTools() async { // Function for removing Platform Tools package Future removePlatformTools() async { + print( + '[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.'); + io.stdout.write('[WARN] Continue with removal? [Y/N] '); + var input = io.stdin.readLineSync(); + if (input?.toLowerCase() != 'y') { + return; + } + // Delete primary directory if it exists // TODO: Add support for new directory on Windows // Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools var dir = nexusToolsDir(); var installExists = false; installExists = await io.Directory(dir).exists(); if (installExists) { - print( - '[WARN] Deleting $dir will delete Android System Tools (ADB, Fastboot, etc.).'); - print('[WARN] This will also delete the Nexus Tools application.'); - io.stdout.write('[WARN] Continue with removal? [Y/N] '); - var input = io.stdin.readLineSync(); - if (input?.toLowerCase() != 'y') { - return; - } // Proceed with deletion await io.Directory(dir).delete(recursive: true); print('[ OK ] Deleted directory at $dir.'); - // Delete registry keys on Windows - if (io.Platform.isWindows) { - await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']); - print('[ OK ] Removed registry keys.'); + } + // Windows-specific functions + if (io.Platform.isWindows) { + var oldDir = envVars['UserProfile'] + r'\NexusTools'; + var oldinstallExists = await io.Directory(oldDir).exists(); + if (oldinstallExists) { + // Proceed with deletion + await io.Directory(oldDir).delete(recursive: true); + print('[ OK ] Deleted directory at $oldDir.'); } - print('[INFO] Nexus Tools can be re-installed at https://git.io/JBuTh.'); - } else { - print('[EROR] No installation found at $dir.'); + // Clean up registry + await io.Process.run('reg', [ + 'delete', + r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', + '/f' + ]); + print('[ OK ] Removed registry keys.'); } + // Exit message + print('[INFO] Nexus Tools can be re-installed at https://git.io/JBuTh.'); } // Function for installing Windows Universal ADB drivers @@ -287,7 +304,7 @@ Usage: nexustools [OPTIONS] Example: nexustools -i (this installs Platform Tools) -i, --install Install/update Android Platform Tools - -r, --remove Remove Platform Tools + -r, --remove Remove Nexus Tools & Android Platform Tools -n, --no-analytics Run Nexus Tools without Plausible Analytics (analytics is only run on install) -c, --check Check for Nexus Tools update From e31ccd8074e33367bf32ceadf8c7242eabd0df9f Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sun, 30 Apr 2023 23:20:01 -0400 Subject: [PATCH 05/14] Fix short line endings --- bin/main.dart | 98 +++++++++++++++------------------------------------ lib/sys.dart | 2 +- 2 files changed, 29 insertions(+), 71 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 8dc4094..ca46abf 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -5,26 +5,21 @@ import 'package:uuid/uuid.dart'; import 'dart:convert'; import 'package:nexustools/sys.dart' as sys; -String macZip = - 'https://dl.google.com/android/repository/platform-tools-latest-darwin.zip'; -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'; +String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-darwin.zip'; +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.5; // Function for checking for update Future checkUpdate() async { - var net = Uri.parse( - 'https://api.github.com/repos/corbindavenport/nexus-tools/releases/latest'); + var net = Uri.parse('https://api.github.com/repos/corbindavenport/nexus-tools/releases/latest'); try { var data = await http.read(net); var parsedData = json.decode(data); // Compare versions if (double.parse(parsedData['tag_name']) > appVersion) { - print( - '[INFO] Nexus Tools update available! Download: https://git.io/JBuTh'); + print('[INFO] Nexus Tools update available! Download: https://git.io/JBuTh'); } else { print('[INFO] You have the latest version of Nexus Tools.'); } @@ -80,13 +75,10 @@ Future installPlatformTools() async { } // Move files out of platform-tools subdirectory and delete the subdirectory if (io.Platform.isWindows) { - await io.Process.run('move', ['$dir\\platform-tools\\*', '$dir'], - runInShell: true); - await io.Process.run('rmdir', ['/Q', '/S', '$dir\\platform-tools'], - runInShell: true); + await io.Process.run('move', ['$dir\\platform-tools\\*', '$dir'], runInShell: true); + await io.Process.run('rmdir', ['/Q', '/S', '$dir\\platform-tools'], runInShell: true); } else { - await io.Process.run( - '/bin/sh', ['-c', 'mv -f -v $dir/platform-tools/* $dir/']); + await io.Process.run('/bin/sh', ['-c', 'mv -f -v $dir/platform-tools/* $dir/']); await io.Process.run('/bin/sh', ['-c', 'rm -rf $dir/platform-tools']); } // Mark binaries in directory as executable @@ -100,19 +92,13 @@ Future installPlatformTools() async { // Create help link if (io.Platform.isWindows) { var file = io.File('$dir\\About Nexus Tools.url'); - await file.writeAsString( - '[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', - mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isMacOS) { var file = io.File('$dir/About Nexus Tools.url'); - await file.writeAsString( - '[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', - mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isLinux) { var file = io.File('$dir/About Nexus Tools.desktop'); - await file.writeAsString( - '[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', - mode: io.FileMode.writeOnly); + await file.writeAsString('[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); } // Windows-specific functions if (io.Platform.isWindows) { @@ -123,10 +109,8 @@ Future installPlatformTools() async { 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] '); + 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); @@ -143,18 +127,12 @@ Future installPlatformTools() async { // Documentation: https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key var uninstallString = dir + r'\nexustools.exe'; var regEntry = 'Windows Registry Editor Version 5.00\n\n'; - regEntry += - r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; - regEntry += - '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; + regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; + regEntry += '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; regEntry += '\n"Publisher"="Corbin Davenport"'; - regEntry += - '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; + regEntry += '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; regEntry += '\n"NoModify"=dword:00000001'; - regEntry += '\n' + - r'"UninstallString"="\"' + - uninstallString.replaceAll(r'\', r'\\') + - r'\" --remove"'; + regEntry += '\n' + r'"UninstallString"="\"' + uninstallString.replaceAll(r'\', r'\\') + r'\" --remove"'; var regFile = await io.File('$dir/nexustools.reg'); await regFile.writeAsString(regEntry, mode: io.FileMode.writeOnly); await io.Process.run('reg', ['import', '$dir/nexustools.reg']); @@ -163,8 +141,7 @@ Future installPlatformTools() async { // Function for removing Platform Tools package Future removePlatformTools() async { - print( - '[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.'); + print('[WARN] This will delete the Android System Tools (ADB, Fastboot, etc.) installed by Nexus Tools, as well as the Nexus Tools application.'); io.stdout.write('[WARN] Continue with removal? [Y/N] '); var input = io.stdin.readLineSync(); if (input?.toLowerCase() != 'y') { @@ -191,11 +168,7 @@ Future removePlatformTools() async { print('[ OK ] Deleted directory at $oldDir.'); } // Clean up registry - await io.Process.run('reg', [ - 'delete', - r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', - '/f' - ]); + await io.Process.run('reg', ['delete', r'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools', '/f']); print('[ OK ] Removed registry keys.'); } // Exit message @@ -206,19 +179,15 @@ Future removePlatformTools() async { // Drivers provided by ClockWorkMod: https://adb.clockworkmod.com/ Future installWindowsDrivers(String dir) async { print('[....] Downloading drivers, please wait.'); - var net = Uri.parse( - 'https://github.com/koush/adb.clockworkmod.com/releases/latest/download/UniversalAdbDriverSetup.msi'); + var net = Uri.parse('https://github.com/koush/adb.clockworkmod.com/releases/latest/download/UniversalAdbDriverSetup.msi'); try { var data = await http.readBytes(net); var file = io.File('$dir\\ADB Drivers.msi'); await file.writeAsBytes(data, mode: io.FileMode.writeOnly); print('[....] Opening driver installer.'); - await io.Process.run( - 'start', ['/wait', 'msiexec.exe', '/i', '$dir\\ADB Drivers.msi'], - runInShell: true); + await io.Process.run('start', ['/wait', 'msiexec.exe', '/i', '$dir\\ADB Drivers.msi'], runInShell: true); } catch (e) { - print( - '[EROR] There was an error downloading drivers, try downloading them from adb.clockworkmod.com.'); + print('[EROR] There was an error downloading drivers, try downloading them from adb.clockworkmod.com.'); } } @@ -240,15 +209,8 @@ void connectAnalytics() async { var cpu = await sys.getCPUArchitecture(); // Set data var net = Uri.parse('https://plausible.io/api/event'); - var netHeaders = { - 'user-agent': 'Nexus Tools', - 'X-Forwarded-For': '127.0.0.1', - '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 netHeaders = {'user-agent': 'Nexus Tools', 'X-Forwarded-For': '127.0.0.1', '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"}'; // Send request try { await http.post(net, headers: netHeaders, body: netBody); @@ -268,8 +230,7 @@ Future checkInstall() async { installExists = await io.File('$dir/adb').exists(); } if (installExists) { - io.stdout.write( - '[WARN] Platform tools already installed in $dir. Continue? [Y/N] '); + io.stdout.write('[WARN] Platform tools already installed in $dir. Continue? [Y/N] '); var input = io.stdin.readLineSync(); if (input?.toLowerCase() != 'y') { io.exit(0); @@ -287,8 +248,7 @@ Future checkInstall() async { var isWSL = await io.Directory('/mnt/c/Windows').exists(); var isChromeOS = await io.Directory('/usr/share/themes/CrosAdapta').exists(); if (isWSL) { - print( - '[WARN] WSL does not support USB devices, you will only be able to use ADB over Wi-Fi.'); + print('[WARN] WSL does not support USB devices, you will only be able to use ADB over Wi-Fi.'); } else if (isChromeOS) { print('[WARN] Chrome OS 75 or higher is required for USB support.'); } @@ -337,11 +297,9 @@ void main(List arguments) async { } else { appName = 'Terminal window'; } - print( - '[INFO] Installation complete! Open a new $appName to apply changes.'); + print('[INFO] Installation complete! Open a new $appName to apply changes.'); print('[INFO] Run "nexustools --help" at any time for more options.'); - print( - '[INFO] Join the Discord server: https://discord.com/invite/59wfy5cNHw'); + print('[INFO] Join the Discord server: https://discord.com/invite/59wfy5cNHw'); print('[INFO] Donate to support development: https://git.io/J4jct'); } else if (arguments.contains('-r') || arguments.contains('--remove')) { print('[INFO] Nexus Tools $appVersion'); diff --git a/lib/sys.dart b/lib/sys.dart index a68b1b8..7daf3d6 100644 --- a/lib/sys.dart +++ b/lib/sys.dart @@ -76,4 +76,4 @@ Future addPath(String path) async { print('[WARN] Shell could not be detected, you will need to manually add $path to your PATH.'); } } -} \ No newline at end of file +} From f16ec625e2f3e3c58e45d282104f4774978c2bd2 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sun, 30 Apr 2023 23:49:30 -0400 Subject: [PATCH 06/14] Replace git.io shortlinks --- bin/main.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index ca46abf..7eda5fe 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -19,7 +19,7 @@ Future checkUpdate() async { var parsedData = json.decode(data); // Compare versions if (double.parse(parsedData['tag_name']) > appVersion) { - print('[INFO] Nexus Tools update available! Download: https://git.io/JBuTh'); + print('[INFO] Nexus Tools update available! https://github.com/corbindavenport/nexus-tools/blob/main/README.md'); } else { print('[INFO] You have the latest version of Nexus Tools.'); } @@ -172,7 +172,7 @@ Future removePlatformTools() async { print('[ OK ] Removed registry keys.'); } // Exit message - print('[INFO] Nexus Tools can be re-installed at https://git.io/JBuTh.'); + print('[INFO] Nexus Tools can be re-installed from here: https://github.com/corbindavenport/nexus-tools'); } // Function for installing Windows Universal ADB drivers @@ -300,7 +300,7 @@ void main(List arguments) async { print('[INFO] Installation complete! Open a new $appName to apply changes.'); print('[INFO] Run "nexustools --help" at any time for more options.'); print('[INFO] Join the Discord server: https://discord.com/invite/59wfy5cNHw'); - print('[INFO] Donate to support development: https://git.io/J4jct'); + print('[INFO] Donate to support development: https://tinyurl.com/nexusdonate'); } else if (arguments.contains('-r') || arguments.contains('--remove')) { print('[INFO] Nexus Tools $appVersion'); // Start removal From b5b033c7bc4e0b423352dc0041f5f5b69809c9f8 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Sun, 30 Apr 2023 23:57:39 -0400 Subject: [PATCH 07/14] Update readme and help links --- README.md | 34 ++++++++++------------------------ bin/main.dart | 6 +++--- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c888d5f..8314075 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ # Nexus Tools -Nexus Tools is an installer for the [Android SDK Platform Tools](https://developer.android.com/studio/releases/platform-tools) package, which includes [ADB](https://developer.android.com/studio/command-line/adb.html), Fastboot, and other applications. Nexus Tools is writen in Dart, and can run on Linux, macOS, Windows, Windows Subsystem for Linux, and Chrome OS. +Nexus Tools is an installer and updater for [Android SDK Platform Tools](https://developer.android.com/studio/releases/platform-tools), which includes [ADB](https://developer.android.com/studio/command-line/adb.html), Fastboot, and other applications. Nexus Tools is writen in Dart, and can run on Linux, macOS, Windows, and Chrome OS. -Nexus Tools downloads the latest Platform tools package directly from Google's servers (so you're always getting the latest version), saves them to `~/.nexustools` (`$Home\NexusTools` on Windows), and adds the directory to your system's path. On Windows, Nexus Tools can optionally install [Koush's Universal ADB Driver](https://github.com/koush/UniversalAdbDriver). +Nexus Tools downloads the latest Platform tools package directly from Google's servers, so you're always getting the latest version. The tools are installed to `~/.nexustools` (`%AppData%\NexusTools` on Windows), and adds the directory to your system's path. On Windows, Nexus Tools can optionally install [Koush's Universal ADB Driver](https://github.com/koush/UniversalAdbDriver). The SDK Platform Tools can be updated by running `nexustools -i`, or you can uninstall everything by running `nexustools -r`. -Once Nexus Tools is finished, you can run `adb`, `fastboot`, and other commands with no problems. **You need to open a new terminal/command line window after installation for changes to take effect.** The SDK Platform Tools can be updated by running `nexustools -i`, or you can uninstall everything by running `nexustools -r`. +(screenshot will go here) -_Featured on [MakeUseOf](https://www.makeuseof.com/how-to-unlock-android-device-bootloader), [XDA](https://www.xda-developers.com/set-up-adb-and-fastboot-on-linux-mac-os-x-and-chrome-os-with-a-single-command/), [Android Police](https://www.androidpolice.com/install-and-use-adb-on-windows-mac-linux-android-chromebooks-browser/), [9to5Google](https://9to5google.com/2021/12/02/how-to-downgrade-from-android-12-to-android-11-on-google-pixel/#:~:text=Nexus%20Tools), [Wccftech](https://wccftech.com/set-android-adb-fastboot-mac-os/), [Redmond Pie](https://www.redmondpie.com/how-to-install-android-5.0-lollipop-on-nexus-5-using-mac-the-easy-way/), and others!_ +## How to use on Linux, macOS, and Chrome OS -### How to use on Linux, macOS, and Chrome OS - -Paste this command into the Terminal app: +Paste this command into your Terminal app: ``` bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/main/install.sh) @@ -18,7 +16,7 @@ bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/mai You can also download the Mac and Linux versions from the [latest release page](https://github.com/corbindavenport/nexus-tools/releases/), un-zip the file, and run it from the Terminal. -### How to use on Windows +## How to use on Windows Open Windows PowerShell from the Start Menu and paste this command: @@ -28,15 +26,9 @@ iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercon You can also download the Windows version from the [latest release page](https://github.com/corbindavenport/nexus-tools/releases/), un-zip the file, and run it from Windows PowerShell or the Command Prompt. -### Compatibility - -The Nexus Tools installer is compiled as an x86_64 (64-bit x86) application for macOS, x86_64 Linux, and Windows. It can run in the [Rosetta 2 compatibility layer](https://support.apple.com/en-us/HT211861) on Macs with Apple Silicon chips, like M1 and M2. It also works on ARM Windows 10 and 11 through the [WOW64 translation layer](https://docs.microsoft.com/en-us/windows/arm/apps-on-arm-x86-emulation). - -ADB, Fastboot, and other applications in the Platform Tools package are compiled for x86_64 on Windows and Linux. The Mac versions are Universal Binaries, so they run natively on both Intel and Apple Silicon Mac computers. - -### Analytics +## Privacy & Analytics -Nexus Tools uses [Plausible Analytics](https://plausible.io) to transmit your operating system and CPU architecture during the installation process. This data is not sold or shared in any way, it's only for me to know which hardware platforms I should focus my attention on. You can disable analytics reporting by adding the `--no-analytics` parameter to the install command, like this: +Nexus Tools uses [Plausible Analytics](https://plausible.io) to transmit your operating system and CPU architecture during the installation process for development purposes. This data is not sold or shared in any way. You can disable analytics reporting by adding the `--no-analytics` parameter to the install command, like this: ``` bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/main/install.sh) --no-analytics @@ -50,12 +42,6 @@ nexustools --no-analytics This analytics data is viewable publicly at [plausible.io/nexustools.corbin.io](https://plausible.io/nexustools.corbin.io). -### Development info - -Nexus Tools is written in Dart, so you need the [Dart SDK](https://dart.dev/get-dart) to work on it. You can run Nexus Tools from source like this: - -``` -dart ./bin/main.dart -``` +--- -The `compile.sh` (macOS and Linux) and `compile.ps1` scripts create executables and zip them. You can also use GitHub Actions to compile Nexus Tools, by navigating to Actions > Compile Nexus Tools > Run workflow. +Nexus Tools has been featured on [MakeUseOf](https://www.makeuseof.com/how-to-unlock-android-device-bootloader), [XDA](https://www.xda-developers.com/set-up-adb-and-fastboot-on-linux-mac-os-x-and-chrome-os-with-a-single-command/), [Android Police](https://www.androidpolice.com/install-and-use-adb-on-windows-mac-linux-android-chromebooks-browser/), [9to5Google](https://9to5google.com/2021/12/02/how-to-downgrade-from-android-12-to-android-11-on-google-pixel/#:~:text=Nexus%20Tools), [Wccftech](https://wccftech.com/set-android-adb-fastboot-mac-os/), [Redmond Pie](https://www.redmondpie.com/how-to-install-android-5.0-lollipop-on-nexus-5-using-mac-the-easy-way/), and other places. \ No newline at end of file diff --git a/bin/main.dart b/bin/main.dart index 7eda5fe..fb8d06d 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -92,13 +92,13 @@ Future installPlatformTools() async { // Create help link if (io.Platform.isWindows) { var file = io.File('$dir\\About Nexus Tools.url'); - await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isMacOS) { var file = io.File('$dir/About Nexus Tools.url'); - await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isLinux) { var file = io.File('$dir/About Nexus Tools.desktop'); - await file.writeAsString('[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/master/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); } // Windows-specific functions if (io.Platform.isWindows) { From 7aadf21a204301f1dfdd05d4daceb62fc29bf963 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 1 May 2023 00:18:49 -0400 Subject: [PATCH 08/14] Update installation scripts --- install.ps1 | 2 +- install.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/install.ps1 b/install.ps1 index 0648285..6a8addb 100644 --- a/install.ps1 +++ b/install.ps1 @@ -1,6 +1,6 @@ # This script is just a wrapper to start the Dart executable from the GitHub releases page. -$Dir = "$Home\NexusTools" +$Dir = "$ENV:APPDATA\NexusTools" $Arch = $ENV:Processor_Architecture $BaseUrl = "https://github.com/corbindavenport/nexus-tools" $Download = "$BaseUrl/releases/latest/download/nexustools-windows-x64.zip" diff --git a/install.sh b/install.sh index 297e9c9..5a4b3bb 100755 --- a/install.sh +++ b/install.sh @@ -36,9 +36,7 @@ mkdir -p $DIR if [ "$OS" = "Darwin" ]; then # macOS # Install Rosetta x86 emulation layer if needed if [ "$ARCH" = "arm64" ]; then - echo "[WARN] Apple Rosetta compatibility layer will be enabled, if it has not been already. Press ENTER to install or X to cancel." - read -sn1 input - [ "$input" = "" ] && /usr/sbin/softwareupdate --install-rosetta --agree-to-license || exit + 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 DOWNLOAD="$BASEURL/releases/latest/download/nexustools-macos-x64.zip" _run_executable From ca0d871a6d080b771a5eebc266ef11b98322df45 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 1 May 2023 22:50:46 -0400 Subject: [PATCH 09/14] Update readme --- README.md | 8 ++++---- bin/main.dart | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8314075..54fa74f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ Nexus Tools is an installer and updater for [Android SDK Platform Tools](https:/ Nexus Tools downloads the latest Platform tools package directly from Google's servers, so you're always getting the latest version. The tools are installed to `~/.nexustools` (`%AppData%\NexusTools` on Windows), and adds the directory to your system's path. On Windows, Nexus Tools can optionally install [Koush's Universal ADB Driver](https://github.com/koush/UniversalAdbDriver). The SDK Platform Tools can be updated by running `nexustools -i`, or you can uninstall everything by running `nexustools -r`. -(screenshot will go here) +
+ +
## How to use on Linux, macOS, and Chrome OS @@ -28,7 +30,7 @@ You can also download the Windows version from the [latest release page](https:/ ## Privacy & Analytics -Nexus Tools uses [Plausible Analytics](https://plausible.io) to transmit your operating system and CPU architecture during the installation process for development purposes. This data is not sold or shared in any way. You can disable analytics reporting by adding the `--no-analytics` parameter to the install command, like this: +Nexus Tools uses [Plausible Analytics](https://plausible.io) to transmit your operating system and CPU architecture during the installation process for development purposes. This analytics data is viewable publicly at [plausible.io/nexustools.corbin.io](https://plausible.io/nexustools.corbin.io). You can disable analytics reporting by adding the `--no-analytics` parameter to the install command, like this: ``` bash <(curl -s https://raw.githubusercontent.com/corbindavenport/nexus-tools/main/install.sh) --no-analytics @@ -40,8 +42,6 @@ It also works when running Nexus Tools locally: nexustools --no-analytics ``` -This analytics data is viewable publicly at [plausible.io/nexustools.corbin.io](https://plausible.io/nexustools.corbin.io). - --- Nexus Tools has been featured on [MakeUseOf](https://www.makeuseof.com/how-to-unlock-android-device-bootloader), [XDA](https://www.xda-developers.com/set-up-adb-and-fastboot-on-linux-mac-os-x-and-chrome-os-with-a-single-command/), [Android Police](https://www.androidpolice.com/install-and-use-adb-on-windows-mac-linux-android-chromebooks-browser/), [9to5Google](https://9to5google.com/2021/12/02/how-to-downgrade-from-android-12-to-android-11-on-google-pixel/#:~:text=Nexus%20Tools), [Wccftech](https://wccftech.com/set-android-adb-fastboot-mac-os/), [Redmond Pie](https://www.redmondpie.com/how-to-install-android-5.0-lollipop-on-nexus-5-using-mac-the-easy-way/), and other places. \ No newline at end of file diff --git a/bin/main.dart b/bin/main.dart index fb8d06d..0765a32 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -300,7 +300,7 @@ void main(List arguments) async { print('[INFO] Installation complete! Open a new $appName to apply changes.'); print('[INFO] Run "nexustools --help" at any time for more options.'); print('[INFO] Join the Discord server: https://discord.com/invite/59wfy5cNHw'); - print('[INFO] Donate to support development: https://tinyurl.com/nexusdonate'); + print('[INFO] Donate to support development: https://tinyurl.com/nexusdonate\n'); } else if (arguments.contains('-r') || arguments.contains('--remove')) { print('[INFO] Nexus Tools $appVersion'); // Start removal @@ -310,6 +310,6 @@ void main(List arguments) async { } else if (arguments.contains('-c') || arguments.contains('--check')) { await checkUpdate(); } else { - print('[EROR] Invalid arguments. Run nexustools -h for help!'); + print('[EROR] Invalid arguments. Run nexustools -h for help!\n'); } } From e4954ac12b26b742cfcfeb03f988f32a5bb55966 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Mon, 1 May 2023 22:54:57 -0400 Subject: [PATCH 10/14] Fix image on readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 54fa74f..5679185 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Nexus Tools is an installer and updater for [Android SDK Platform Tools](https:/ Nexus Tools downloads the latest Platform tools package directly from Google's servers, so you're always getting the latest version. The tools are installed to `~/.nexustools` (`%AppData%\NexusTools` on Windows), and adds the directory to your system's path. On Windows, Nexus Tools can optionally install [Koush's Universal ADB Driver](https://github.com/koush/UniversalAdbDriver). The SDK Platform Tools can be updated by running `nexustools -i`, or you can uninstall everything by running `nexustools -r`.
- +
## How to use on Linux, macOS, and Chrome OS From 68c6422495e3bfc167273473cb86b84609f12919 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Thu, 4 May 2023 16:27:18 -0400 Subject: [PATCH 11/14] Simplify update checker --- bin/main.dart | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 0765a32..036fa22 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -13,16 +13,12 @@ double appVersion = 5.5; // Function for checking for update Future checkUpdate() async { + print('[INFO] Your installed version of Nexus Tools: $appVersion'); var net = Uri.parse('https://api.github.com/repos/corbindavenport/nexus-tools/releases/latest'); try { var data = await http.read(net); var parsedData = json.decode(data); - // Compare versions - if (double.parse(parsedData['tag_name']) > appVersion) { - print('[INFO] Nexus Tools update available! https://github.com/corbindavenport/nexus-tools/blob/main/README.md'); - } else { - print('[INFO] You have the latest version of Nexus Tools.'); - } + print('[INFO] Latest available version: ' + parsedData['tag_name'] + '\n[INFO] Get the latest version: https://github.com/corbindavenport/nexus-tools/blob/main/README.md\n'); } catch (e) { print('[EROR] Could not check for updates.'); } @@ -148,7 +144,6 @@ Future removePlatformTools() async { return; } // Delete primary directory if it exists - // TODO: Add support for new directory on Windows // Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools var dir = nexusToolsDir(); var installExists = false; @@ -157,6 +152,8 @@ Future removePlatformTools() async { // Proceed with deletion await io.Directory(dir).delete(recursive: true); print('[ OK ] Deleted directory at $dir.'); + } else { + print('[ OK ] No installation found at $dir'); } // Windows-specific functions if (io.Platform.isWindows) { @@ -172,7 +169,7 @@ Future removePlatformTools() async { print('[ OK ] Removed registry keys.'); } // Exit message - print('[INFO] Nexus Tools can be re-installed from here: https://github.com/corbindavenport/nexus-tools'); + print('[INFO] Nexus Tools can be re-installed from here: https://github.com/corbindavenport/nexus-tools\n'); } // Function for installing Windows Universal ADB drivers From 31011873657103ad8f835f0f2f4748e0ae27e055 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Thu, 4 May 2023 16:35:27 -0400 Subject: [PATCH 12/14] Move GitHub repo to variable --- bin/main.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 036fa22..5a54bfb 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -10,15 +10,16 @@ String linuxZip = 'https://dl.google.com/android/repository/platform-tools-lates String windowsZip = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip'; Map envVars = io.Platform.environment; double appVersion = 5.5; +String baseRepo = 'corbindavenport/nexus-tools'; // Function for checking for update Future checkUpdate() async { print('[INFO] Your installed version of Nexus Tools: $appVersion'); - var net = Uri.parse('https://api.github.com/repos/corbindavenport/nexus-tools/releases/latest'); + var net = Uri.parse('https://api.github.com/repos/$baseRepo/releases/latest'); try { var data = await http.read(net); var parsedData = json.decode(data); - print('[INFO] Latest available version: ' + parsedData['tag_name'] + '\n[INFO] Get the latest version: https://github.com/corbindavenport/nexus-tools/blob/main/README.md\n'); + print('[INFO] Latest available version: ' + parsedData['tag_name'] + '[INFO] Get the latest version: https://github.com/$baseRepo/blob/main/README.md\n'); } catch (e) { print('[EROR] Could not check for updates.'); } @@ -88,13 +89,13 @@ Future installPlatformTools() async { // Create help link if (io.Platform.isWindows) { var file = io.File('$dir\\About Nexus Tools.url'); - await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/$baseRepo/blob/main/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isMacOS) { var file = io.File('$dir/About Nexus Tools.url'); - await file.writeAsString('[InternetShortcut]\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[InternetShortcut]\nURL=https://github.com/$baseRepo/blob/main/README.md', mode: io.FileMode.writeOnly); } else if (io.Platform.isLinux) { var file = io.File('$dir/About Nexus Tools.desktop'); - await file.writeAsString('[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/corbindavenport/nexus-tools/blob/main/README.md', mode: io.FileMode.writeOnly); + await file.writeAsString('[Desktop Entry]\nEncoding=UTF-8\nIcon=text-html\nType=Link\nName=About Nexus Tools\nURL=https://github.com/$baseRepo/blob/main/README.md', mode: io.FileMode.writeOnly); } // Windows-specific functions if (io.Platform.isWindows) { @@ -126,7 +127,7 @@ Future installPlatformTools() async { regEntry += r'[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\NexusTools]'; regEntry += '\n"DisplayName"="Nexus Tools (ADB, Fastboot, Android SDK Platform Tools)"'; regEntry += '\n"Publisher"="Corbin Davenport"'; - regEntry += '\n"URLInfoAbout"="https://github.com/corbindavenport/nexus-tools"'; + regEntry += '\n"URLInfoAbout"="https://github.com/$baseRepo"'; regEntry += '\n"NoModify"=dword:00000001'; regEntry += '\n' + r'"UninstallString"="\"' + uninstallString.replaceAll(r'\', r'\\') + r'\" --remove"'; var regFile = await io.File('$dir/nexustools.reg'); @@ -169,7 +170,7 @@ Future removePlatformTools() async { print('[ OK ] Removed registry keys.'); } // Exit message - print('[INFO] Nexus Tools can be re-installed from here: https://github.com/corbindavenport/nexus-tools\n'); + print('[INFO] Nexus Tools can be reinstalled from here: https://github.com/$baseRepo\n'); } // Function for installing Windows Universal ADB drivers From 26d62ca1202ce2c1bab24b7262f8c52e706e48bb Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Thu, 4 May 2023 16:40:46 -0400 Subject: [PATCH 13/14] Revert "Simplify update checker" This reverts commit 68c6422495e3bfc167273473cb86b84609f12919. --- bin/main.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 5a54bfb..d4a33c2 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -14,12 +14,16 @@ String baseRepo = 'corbindavenport/nexus-tools'; // Function for checking for update Future checkUpdate() async { - print('[INFO] Your installed version of Nexus Tools: $appVersion'); var net = Uri.parse('https://api.github.com/repos/$baseRepo/releases/latest'); try { var data = await http.read(net); var parsedData = json.decode(data); - print('[INFO] Latest available version: ' + parsedData['tag_name'] + '[INFO] Get the latest version: https://github.com/$baseRepo/blob/main/README.md\n'); + // Compare versions + if (double.parse(parsedData['tag_name']) > appVersion) { + print('[INFO] Nexus Tools update available! https://github.com/$baseRepo/blob/main/README.md'); + } else { + print('[INFO] You have the latest version of Nexus Tools.'); + } } catch (e) { print('[EROR] Could not check for updates.'); } @@ -145,6 +149,7 @@ Future removePlatformTools() async { return; } // Delete primary directory if it exists + // TODO: Add support for new directory on Windows // Nexus Tools 3.2+ (August 2016-Present) installs binaries in ~/.nexustools var dir = nexusToolsDir(); var installExists = false; @@ -153,8 +158,6 @@ Future removePlatformTools() async { // Proceed with deletion await io.Directory(dir).delete(recursive: true); print('[ OK ] Deleted directory at $dir.'); - } else { - print('[ OK ] No installation found at $dir'); } // Windows-specific functions if (io.Platform.isWindows) { From a4b3eff90be94a90d0d032150b1c549759aaa444 Mon Sep 17 00:00:00 2001 From: Corbin Davenport Date: Tue, 9 May 2023 23:19:01 -0400 Subject: [PATCH 14/14] Update analytics --- bin/main.dart | 4 +++- pubspec.lock | 8 ++++++++ pubspec.yaml | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index d4a33c2..6b6bf45 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -3,6 +3,7 @@ import 'package:http/http.dart' as http; import 'dart:io' as io; import 'package:uuid/uuid.dart'; import 'dart:convert'; +import 'package:dart_ipify/dart_ipify.dart'; import 'package:nexustools/sys.dart' as sys; String macZip = 'https://dl.google.com/android/repository/platform-tools-latest-darwin.zip'; @@ -210,7 +211,8 @@ void connectAnalytics() async { var cpu = await sys.getCPUArchitecture(); // Set data var net = Uri.parse('https://plausible.io/api/event'); - var netHeaders = {'user-agent': 'Nexus Tools', 'X-Forwarded-For': '127.0.0.1', 'Content-Type': 'application/json', 'User-Agent': 'Mozilla/5.0 ($realOS) AppleWebKit/500 (KHTML, like Gecko) Chrome/$appVersion $id'}; + 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"}'; // Send request try { diff --git a/pubspec.lock b/pubspec.lock index c553f92..e3fda98 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.2" + dart_ipify: + dependency: "direct dev" + description: + name: dart_ipify + sha256: "3b70d589504126107e81ad0703d91394cc8e2039cb0a11ebd92b9b824a5e9561" + url: "https://pub.dev" + source: hosted + version: "1.1.1" http: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 962f8b0..5e5eb37 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,4 +14,5 @@ dev_dependencies: io: uuid: archive: ^3.2.2 - console: \ No newline at end of file + console: + dart_ipify: ^1.1.1 \ No newline at end of file