mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
PublicIP: print location
This commit is contained in:
@@ -23,6 +23,7 @@ Features:
|
||||
* Support detecting brightness of external displays with DDC/CI (guard behind `--allow-slow-operations`) (Brightness)
|
||||
* Add option `--size-ndigits` and `--size-max-prefix` (#494)
|
||||
* Add option `--processing-timeout` to the timeout when waiting for child processes.
|
||||
* Public IP module prints the IP location if `--publicip-url` is not set
|
||||
|
||||
# 1.12.2
|
||||
|
||||
|
||||
@@ -10,10 +10,17 @@
|
||||
static FFNetworkingState state;
|
||||
static int status = -1;
|
||||
|
||||
static inline void wrapYyjsonFree(yyjson_doc** doc)
|
||||
{
|
||||
assert(doc);
|
||||
if (*doc)
|
||||
yyjson_doc_free(*doc);
|
||||
}
|
||||
|
||||
void ffPreparePublicIp(FFPublicIpOptions* options)
|
||||
{
|
||||
if (options->url.length == 0)
|
||||
status = ffNetworkingSendHttpRequest(&state, "ipinfo.io", "/ip", NULL);
|
||||
status = ffNetworkingSendHttpRequest(&state, "ipinfo.io", "/json", NULL);
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY host = ffStrbufCreateCopy(&options->url);
|
||||
@@ -56,6 +63,22 @@ void ffPrintPublicIp(FFPublicIpOptions* options)
|
||||
if (options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(FF_PUBLICIP_DISPLAY_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
|
||||
|
||||
if (options->url.length == 0)
|
||||
{
|
||||
yyjson_doc* __attribute__((__cleanup__(wrapYyjsonFree))) doc = yyjson_read_opts(result.chars, result.length, 0, NULL, NULL);
|
||||
if (doc)
|
||||
{
|
||||
yyjson_val* root = yyjson_doc_get_root(doc);
|
||||
printf("%s (%s, %s)\n",
|
||||
yyjson_get_str(yyjson_obj_get(root, "ip")),
|
||||
yyjson_get_str(yyjson_obj_get(root, "city")),
|
||||
yyjson_get_str(yyjson_obj_get(root, "country"))
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufPutTo(&result, stdout);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user