From 6d19960de2580971015f28d30b28cf942ade191d Mon Sep 17 00:00:00 2001 From: dubisdev Date: Mon, 11 Mar 2024 19:46:54 +0100 Subject: [PATCH] fix: avoid getting the ip each time --- extensions/ip/src/index.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/ip/src/index.ts b/extensions/ip/src/index.ts index 41e0b77..88c2a96 100644 --- a/extensions/ip/src/index.ts +++ b/extensions/ip/src/index.ts @@ -6,15 +6,15 @@ const noInternetItem = new InfoItem({ subtitle: 'You are offline' }); +let ip = ''; + const run: ExtensionModule['run'] = async ({ display, actions }) => { if (navigator.onLine === false) { return display([noInternetItem]); } - const ip = await getIp(); - const ipItem = new ScriptItem({ - title: 'Your IP', + title: 'IP:', subtitle: ip, run: async () => { actions.copyToClipboard(ip); @@ -26,6 +26,13 @@ const run: ExtensionModule['run'] = async ({ display, actions }) => { const IpExtension: ExtensionModule = { name: 'Ip', + initializeAsync: async (send) => { + const ip = await getIp(); + send(ip); + }, + onMessage (dataIp) { + ip = dataIp as string; + }, run, icon: '' };