toJson method

  1. @override
Map<String, String?> toJson({
  1. int? pidProcces,
})
override

General Library Documentation Undocument By General Corporation & Global Corporation & General Developer

Implementation

@override
Map<String, String?> toJson({
  int? pidProcces,
}) {
  final OperatingSystemData operatingSystemData = getOperatingSystemData();
  final CpuData cpuData = getCpuData();
  final MemoryData memory_ram = get_ram_data ?? MemoryData({});
//     {
//     "OS": "Ubuntu 23.10 x86_64",
//     "Host": "Modern 14 B5M REV:1.0",
//     "Kernel": "6.5.0-13-generic",
//     "Uptime": "5 days, 4 hours, 26 mins",
//     "Packages": "2123 (dpkg), 18 (flatpak), 16 (snap)",
//     "Shell": "zsh 5.9",
//     "Resolution": "1920x1080",
//     "DE": "GNOME 45.0",
//     "WM": "Mutter",
//     "WM Theme": "WhiteSur-Dark",
//     "Theme": "WhiteSur-Dark [GTK2/3]",
//     "Icons": "BigSur-Originals [GTK2/3]",
//     "Terminal": "gnome-terminal",
//     "CPU": "AMD Ryzen 5 5500U with Radeon Graphics (12) @ 4.056GHz",
//     "GPU": "AMD ATI 03:00.0   Lucienne",
//     "GPU": "AMD ATI 03:00.0 Lucienne",
//     "Memory": "11383MiB / 15338MiB",
//     "Version": "7.1.0"
// }
  final (int bandwith_download, bandwith_upload) = get_network_bandwith_usage;
  final (int bandwith_download_by_pid, bandwith_upload_by_pid) =
      get_network_bandwith_usage_by_pid(
    pidProcces: pidProcces,
  );
  // get_arch;
  final Map<String, String?> data = {
    "title": get_title,
    "os": operatingSystemData.name,
    "platform_type": () {
      if (Dart.isWeb) {
        return "Web";
      }

      if (Dart.isAndroid) {
        return "Android";
      }
      if (Dart.isFuchsia) {
        return "Fuchsia";
      }
      if (Dart.isLinux) {
        return "Linux";
      }

      if (Dart.isIOS) {
        return "iOS";
      }
      if (Dart.isMacOS) {
        return "macOS";
      }
      if (Dart.isWindows) {
        return "Windows";
      }
      return null;
    }(),
    "executable_type": get_executable_type,
    "arch": "",
    "host": get_model,
    "device_name": get_model,
    "kernel": get_kernel,
    "uptime_program": DateTime.now()
        .extension_general_lib_countAgoFromDateTime(dateTime: date_start),
    "uptime": get_uptime.toString(),
    "shell": get_shell,
    "resolution": null,
    "de": null,
    "wm": "",
    "wm_theme": "",
    "theme": "",
    "icons": "",
    "terminal": "",
    "cpu": cpuData.name,
    "gpu": get_gpu,
    "network": get_network,
    "disk": get_disk,
    "power": get_power,
    "power_consumtion": get_power_consumtion,
    "ram_total": FileSize.filesize(
      size: memory_ram.mem_total ?? 0,
    ),
    "ram_available": FileSize.filesize(size: memory_ram.mem_available ?? 0),
    "ram_usage": FileSize.filesize(
      size: (memory_ram.mem_total ?? 0) - (memory_ram.mem_available ?? 0),
    ),
    "ram_cached": FileSize.filesize(size: (memory_ram.cached ?? 0)),
    "swap_total": FileSize.filesize(size: memory_ram.swap_total ?? 0),
    "swap_available": FileSize.filesize(size: memory_ram.swap_free ?? 0),
    "swap_cache": FileSize.filesize(size: memory_ram.swap_cached ?? 0),
    "ram_commited": FileSize.filesize(size: memory_ram.committed_a_s ?? 0),
    "ram_swap_total": FileSize.filesize(
      size: (memory_ram.swap_total ?? 0) + (memory_ram.mem_total ?? 0),
    ),
    "version": "",
    // "total_bandwith_download": bandwith_download,

    "total_bandwith_download": FileSize.filesize(
      size: bandwith_download,
    ),
    "total_bandwith_upload": FileSize.filesize(
      size: bandwith_upload,
    ),
    "total_bandwith": FileSize.filesize(
      size: bandwith_upload + bandwith_download,
    ),

    // "total_bandwith_download_by_this_program": FileSize.filesize(
    //   size: bandwith_download_by_pid,
    // ),
    // "total_bandwith_upload_by_this_program": FileSize.filesize(
    //   size: bandwith_upload_by_pid,
    // ),
    // "total_bandwith_by_this_program": FileSize.filesize(
    //   size: bandwith_upload_by_pid + bandwith_download_by_pid,
    // ),
    "ram_usage_by_this_program": FileSize.filesize(
      size: get_ram_usage_by_pid(
        pidProcces: pidProcces,
      ),
    ),
    "program_unique_id": _uniqueId,
    "system_information_version": "0.0.0",
  };

  data.removeWhere((key, value) => value == null);

  data.removeWhere((key, value) {
    if (value != null && value.trim().isEmpty) {
      return true;
    }
    return false;
  });
  return data;
}