-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: adds comments and breaks donw code info smaller fucntions
Signed-off-by: hitg00 <[email protected]>
- Loading branch information
Showing
3 changed files
with
67 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,68 @@ | ||
chrome.runtime.onConnectExternal.addListener((port) => { | ||
let strInfo, cpuInfo, memInfo; | ||
port.onMessage.addListener((message) => { | ||
//to fetch cpu stats | ||
const getCpuInfo = async () => { | ||
return new Promise((resolve, reject) => { | ||
chrome.system.cpu.getInfo((info) => { | ||
cpuInfo = info; | ||
if (info) { | ||
resolve(info); | ||
} else { | ||
reject("Unable to get cpu information"); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
//to fetch memory information | ||
const getMemoryInfo = async () => { | ||
return new Promise((resolve, reject) => { | ||
chrome.system.memory.getInfo((info) => { | ||
memInfo = info; | ||
if (info) { | ||
resolve(info); | ||
} else { | ||
reject("Unable to get memory information"); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
//to fetch storage information | ||
const getStorageInfo = async () => { | ||
return new Promise((resolve, reject) => { | ||
chrome.system.storage.getInfo((info) => { | ||
strInfo = info; | ||
}); | ||
port.postMessage({ | ||
strInfo, | ||
cpuInfo, | ||
memInfo, | ||
if (info) { | ||
resolve(info); | ||
} else { | ||
reject("Unable to get storage information"); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
const fetchDataFromSystem = () => { | ||
return new Promise((resolve, reject) => { | ||
Promise.all([getCpuInfo(), getMemoryInfo(), getStorageInfo()]).then( | ||
(values) => { | ||
const cpuInfo = values[0]; | ||
const memInfo = values[1]; | ||
const strInfo = values[2]; | ||
resolve({ | ||
strInfo, | ||
cpuInfo, | ||
memInfo, | ||
}); | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
//listen to incoming port connection requests | ||
chrome.runtime.onConnectExternal.addListener((port) => { | ||
port.onMessage.addListener(async (message) => { | ||
try { | ||
const systemInfo = await fetchDataFromSystem(); | ||
console.log(systemInfo); | ||
port.postMessage(systemInfo); | ||
} catch (error) { | ||
port.postMessage(error); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters