Skip to content

Commit

Permalink
System Info Displayed
Browse files Browse the repository at this point in the history
I HAPPY AF RN, ABSOLUTELY ECSTATIC THAT I GOT THIS WORKING (took 2 days)
  • Loading branch information
MTSyntho committed Jul 8, 2024
1 parent 1090b28 commit 3a12eb4
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 39 deletions.
15 changes: 13 additions & 2 deletions .zdkrimson/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
{
"lastaccount": "mt.",
"lastaccount": "",
"firsttime": 1,
"lastinstance": ""
"lastinstance": "",
"maximizedefault": false,
"winwidth": 854,
"winheight": 480,
"demomode": false,
"multiplayer": true,
"gamechat": true,
"minmem": 512,
"maxmem": 1024,
"javapath": "javaw",
"jvmargs": "",
"customtheme": ""
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<button>Play</button>
<button>Instances</button>
</div>
<p id=instname class=currentinstance>Current Instance: instname</p>
<p id=instancename class=currentinstance>Current Instance: Loading...</p>
</div>
<div>
<!-- <p class=love>Made with <3</p> -->
Expand Down
141 changes: 131 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,131 @@
window.addEventListener('pywebviewready', function() {
var lastuser = document.getElementById('lastuser');
pywebview.api.get_username('recent').then(function(result) {
// it took me an ungodly amount of time to figure this out, im so pissed rn
lastuser.textContent = "Logged in as: " + result;
});
pywebview.api.get_host().then(function(result) {
// it took me an ungodly amount of time to figure this out, im so pissed rn
hostmachine = result;
document.addEventListener('DOMContentLoaded', function() {
window.addEventListener('pywebviewready', function() {
var lastuser = document.getElementById('lastuser');
var lastinst = document.getElementById('instancename');
pywebview.api.get_username('recent').then(function(result) {
// it took me an ungodly amount of time to figure this out, im so pissed rn
if (result == "") {
lastuser.textContent = "Logged in as: Not Logged In!";
} else {
lastuser.textContent = "Logged in as: " + result;
}
});
pywebview.api.get_recentinstance().then(function(result) {
if (result == "") {
lastinst.textContent = "Current Instance: Not Selected";
} else {
lastinst.textContent = "Current Instance: " + result;
}
});
pywebview.api.get_host().then(function(result) {
// it took me an ungodly amount of time to figure this out, im so pissed rn
console.log('Host Machine: ' + result);
localStorage.setItem('hostmachine', result);
});
pywebview.api.get_mem().then(function(result) {
// i love copy n paste :)
console.log('Memory: ' + result);
localStorage.setItem('sysmem', result);
});
pywebview.api.get_gpu().then(function(result) {
console.log('GPU: ' + result);
localStorage.setItem('sysgpu', result);
});
pywebview.api.get_cpu().then(function(result) {
console.log('CPU: ' + result);
localStorage.setItem('syscpu', result);
});
});
});

// window.addEventListener('message', function(event) {
// if (event.data === 'awaitConfig') {
// console.log("'awaitConfig' Message from settings.js received by index.js")
// // Sending settings to iframe (settings.html)
// window.addEventListener('pywebviewready', function() {
// var settingsiframe = document.getElementById('settings');
// pywebview.api.get_settings().then(function(result) {
// console.log(result);
// var customtheme = result.customtheme;
// var demomode = result.demomode;
// var firsttime = result.firsttime;
// var gamechat = result.gamechat;
// var javapath = result.javapath;
// var jvmargs = result.jvmargs;
// var lastaccount = result.lastaccount;
// var lastinstance = result.lastinstance;
// var maximizedefault = result.maximizedefault;
// var minmem = result.minmem;
// var maxmem = result.maxmem;
// var multiplayer = result.multiplayer;
// var winheight = result.winheight;
// var winwidth = result.winwidth;
// document.addEventListener('DOMContentLoaded', function() {
// console.log('Sending...')
// document.getElementById("settings").contentWindow.postMessage(result, '*'); // '*' allows sending to any origin
// console.log('Sent')
// });
// });
// });
// }
// });

// window.addEventListener('message', function(event) {
// if (event.data === 'awaitConfig') {
// console.log("'awaitConfig' Message from settings.js received by index.js");

// window.addEventListener('pywebviewready', function() {
// var settingsiframe = document.getElementById('settings');
// pywebview.api.get_settings().then(function(result) {
// console.log(result);
// settingsiframe.contentWindow.postMessage(result, '*');
// }).catch(function(error) {
// console.error('Error fetching settings:', error);
// });
// });
// }
// });

document.addEventListener('DOMContentLoaded', function() {
window.addEventListener('message', function(event) {
if (event.data === 'awaitConfig') {
console.log("'awaitConfig' Message from settings.js received by index.js")
// Sending settings to iframe (settings.html)
window.addEventListener('pywebviewready', function() {
var settingsiframe = document.getElementById('settings');
pywebview.api.get_settings().then(function(result) {
console.log(result);
// var customtheme = result.customtheme;
// var demomode = result.demomode;
// var firsttime = result.firsttime;
// var gamechat = result.gamechat;
// var javapath = result.javapath;
// var jvmargs = result.jvmargs;
// var lastaccount = result.lastaccount;
// var lastinstance = result.lastinstance;
// var maximizedefault = result.maximizedefault;
// var minmem = result.minmem;
// var maxmem = result.maxmem;
// var multiplayer = result.multiplayer;
// var winheight = result.winheight;
// var winwidth = result.winwidth;
localStorage.setItem('customtheme', result.customtheme);
localStorage.setItem('demomode', result.demomode);
localStorage.setItem('firsttime', result.firsttime);
localStorage.setItem('gamechat', result.gamechat);
localStorage.setItem('javapath', result.javapath);
localStorage.setItem('jvmargs', result.jvmargs);
localStorage.setItem('lastaccount', result.lastaccount);
localStorage.setItem('lastinstance', result.lastinstance);
localStorage.setItem('maximizedefault', result.maximizedefault);
localStorage.setItem('minmem', result.minmem);
localStorage.setItem('maxmem', result.maxmem);
localStorage.setItem('multiplayer', result.multiplayer);
localStorage.setItem('winheight', result.winheight);
localStorage.setItem('winwidth', result.winwidth);
});
});
}
});
});

Expand Down Expand Up @@ -40,6 +159,8 @@ function help(status) {

// Listen for messages from iframe
window.addEventListener('message', function(event) {
console.log(event)
console.log(event.data)
// Verify origin of the iframe (optional, for security)
// if (event.origin !== 'https://your-iframe-domain.com') return;

Expand All @@ -53,4 +174,4 @@ window.addEventListener('message', function(event) {
// Call help function in the parent window
help('hide');
}
});
});
110 changes: 98 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import modelfetch
import json
import os
import psutil
import humanize
import GPUtil
import platform
from os import path

syshost=modelfetch.system.Model
Expand All @@ -27,55 +31,137 @@
config = {
"lastaccount": "",
"firsttime": 1,
"lastinstance": ""
"lastinstance": "",
"maximizedefault": False,
"winwidth": 854,
"winheight": 480,
"demomode": False,
"multiplayer": True,
"gamechat": True,
"minmem": 512,
"maxmem": 1024,
"javapath": "javaw",
"jvmargs": "",
"customtheme": ""
}
configjson = json.dumps(config, indent=2)
with open(".zdkrimson\\settings.json", "w") as outfile:
outfile.write(configjson)
lastaccount=""
firstime=1
lastinstance=""
maximizedefault=False
winwidth=854
winheight=480
demomode=False
multiplayer=True
gamechat=True
minmem=512
maxmem=1024
javapath="javaw" # a command gets executed instead assuming java's installed already
jvmargs=""
customtheme="" # themes aren't implemented yet, but i added this option anyway :p

if os.path.exists(".zdkrimson\\instances")==False:
print("instances folder doesn't exist, created one just now.")
print("Instances Folder is missing! Folder has been created for you")
os.mkdir(".zdkrimson\\instances")

# loading json files
with open('.zdkrimson\\settings.json', 'r') as openfile:
configjson = json.load(openfile)
try:
print(configjson['lastaccount'])
print(configjson['firsttime'])
print(configjson['lastinstance'])
lastaccount=configjson['lastaccount']
firsttime=configjson['firsttime']
lastinstance=configjson['lastinstance']
print("imported settings json")
print(lastaccount)
maximizedefault=configjson['maximizedefault']
winwidth=configjson['winwidth']
winheight=configjson['winheight']
demomode=configjson['demomode']
multiplayer=configjson['multiplayer']
gamechat=configjson['gamechat']
minmem=configjson['minmem']
maxmem=configjson['maxmem']
javapath=configjson['javapath']
jvmargs=configjson['jvmargs']
customtheme=configjson['customtheme']
# print(configjson)
print("Successfully imported 'settings.json'")
if lastaccount=="":
print("Last Used Account: Not Logged In!")
else:
print("Last Used Account:" + lastaccount)
except KeyError:
print("Settings file isn't up-to-date")
print("Settings file isn't up-to-date, settings file should now be updated (info reset)")
config = {
"lastaccount": "",
"firsttime": 1,
"lastinstance": ""
"lastinstance": "",
"maximizedefault": False,
"winwidth": 854,
"winheight": 480,
"demomode": False,
"multiplayer": True,
"gamechat": True,
"minmem": 512,
"maxmem": 1024,
"javapath": "javaw",
"jvmargs": "",
"customtheme": ""
}
configjson = json.dumps(config, indent=2)
with open(".zdkrimson\\settings.json", "w") as outfile:
outfile.write(configjson)
lastaccount=""
lastaccount=""
firstime=1
lastinstance=""
maximizedefault=False
winwidth=854
winheight=480
demomode=False
multiplayer=True
gamechat=True
minmem=512
maxmem=1024
javapath="javaw" # a command gets executed instead assuming java's installed already
jvmargs=""
customtheme="" # themes aren't implemented yet, but i added this option anyway :p

class Api:
def get_host(self):
print(syshost)
print("System Host: " + syshost)
return syshost

def get_username(self, uuid):
print(uuid)
print("Account UUID: " + uuid)
if uuid=='recent':
return lastaccount

def get_recentinstance(self):
print("Last Instance: " + lastinstance)
return lastinstance

def get_settings(self):
return configjson

def get_mem(self):
# print('RAM: ' + psutil.virtual_memory().total)
print(psutil.virtual_memory().total)
print(humanize.naturalsize(psutil.virtual_memory().total))
return humanize.naturalsize(psutil.virtual_memory().total)

def get_gpu(self):
gpus = GPUtil.getGPUs()
if not gpus:
print('No GPUs Detected.')
return 'No Dedicated GPUs Found'
else:
print('GPU: ' + gpus.name)
return gpus.name

def get_cpu(self):
cpu_info = platform.uname()
print('CPU: ' + cpu_info.processor)
return cpu_info.processor
api = Api()
webview.create_window('zdkrimson', background_color="#210202", url="index.html", js_api=api)
webview.start(debug=True)
11 changes: 8 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
customtkinter
tkinter
customtkinter - deprecated
pyngrok
requests
portablemc
portablemc
pywebview
wmi
psutil
humanize
gputil
lib-platform
1 change: 1 addition & 0 deletions settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ hr {
overflow-y: auto;
width: 100%;
height: 100%;
pointer-events: none;
}

.section {
Expand Down
12 changes: 6 additions & 6 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ <h1>Launcher</h1>
</div>
<h2>Your Device</h2>
<div class=section>
<p>CPU: </p>
<p>GPU: </p>
<p>Memory: </p>
<p id=syshost>Host: </p>
<p id=sysplat>Platform: </p>
<p id=sysres>Resolution: </p>
<p id=syscpu>CPU: Loading... </p>
<p id=sysgpu>GPU: Loading... </p>
<p id=sysmem>Memory: Loading... </p>
<p id=syshost>Host: Loading...</p>
<p id=sysplat>Platform: Loading...</p>
<p id=sysres>Resolution: Loading...</p>
</div>
<h2>Minecraft Information</h2>
<div class=section>
Expand Down
Loading

0 comments on commit 3a12eb4

Please sign in to comment.