Skip to content

Commit

Permalink
regedit
Browse files Browse the repository at this point in the history
  • Loading branch information
BomberFish committed Sep 1, 2024
1 parent d1db89a commit 273af9e
Show file tree
Hide file tree
Showing 10 changed files with 327 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dreamlandjs
Submodule dreamlandjs updated 1 files
+2 −3 package.json
25 changes: 25 additions & 0 deletions public/assets/icons/regedit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/assets/icons/system-monitor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
></script>
<script type="text/javascript" src="lib/coreapps/AboutApp.js"></script>
<script type="text/javascript" src="lib/coreapps/Dialog.js"></script>
<script type="text/javascript" src="lib/coreapps/RegEdit.js"></script>
<script
type="text/javascript"
src="lib/libs/NodePolyfills/NodeFS.js"
Expand Down
3 changes: 3 additions & 0 deletions src/Boot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ document.addEventListener("anura-login-completed", async () => {
const explore = new ExploreApp();
anura.registerApp(explore);

const regedit = new RegEdit();
anura.registerApp(regedit);

const dialog = new Dialog();
const dialogApp = await anura.registerApp(dialog);
(anura.dialog as any) = dialogApp;
Expand Down
16 changes: 11 additions & 5 deletions src/api/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Settings {
private cache: { [key: string]: any } = {};
cache: { [key: string]: any } = {};
fs: AnuraFilesystem;
private constructor(fs: AnuraFilesystem, inital: { [key: string]: any }) {
this.fs = fs;
Expand Down Expand Up @@ -59,6 +59,10 @@ class Settings {
initial["user-xapps"] = [];
}

if (!initial["disable-regedit-warning"]) {
initial["disable-regedit-warning"] = false;
}

try {
const raw = await fs.promises.readFile("/anura_settings.json");
// This Uint8Array is actuallly a buffer, so JSON.parse can handle it
Expand All @@ -77,11 +81,16 @@ class Settings {
return prop in this.cache;
}
async set(prop: string, val: any, subprop?: string) {
console.debug("Setting " + prop + " to " + val);
if (subprop) {
this.cache[prop][subprop] = val;
} else {
this.cache[prop] = val;
}
this.save();
}
async save() {
console.debug("Saving settings to fs", this.cache);
await this.fs.promises.writeFile(
"/anura_settings.json",
JSON.stringify(this.cache),
Expand All @@ -96,9 +105,6 @@ class Settings {
} else {
delete this.cache[prop];
}
await this.fs.promises.writeFile(
"/anura_settings.json",
JSON.stringify(this.cache),
);
this.save();
}
}
274 changes: 274 additions & 0 deletions src/coreapps/RegEdit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
function hasChildren(entry: any[]) {
return (
Object.entries(entry[1]).filter((setting) => {
return (
setting[1] instanceof Object && !(setting[1] instanceof Array)
);
}).length > 0
);
}

const DisclosureGroup: Component<{
entry: any[];
sel: { [key: string]: any };
level?: number;
}> = function () {
if (!this.level) this.level = 1;

this.css = `
margin-left: ${0.8 * this.level!}em;
`;

return (
<div>
{hasChildren(this.entry) ? (
<details>
<summary>
<span
on:click={(e: MouseEvent) => {
e.preventDefault();
this.sel = this.entry[1];
}}
>
{this.entry[0]}
</span>
</summary>
{Object.entries(this.entry[1])
.filter((setting) => {
return (
setting[1] instanceof Object &&
!(setting[1] instanceof Array)
);
})
.map((item: any) => (
<DisclosureGroup
entry={item}
bind:sel={use(this.sel)}
sel={this.sel}
level={this.level! + 1}
/>
))}
</details>
) : (
<span
on:click={() => {
this.sel = this.entry[1];
}}
>
{this.entry[0]}
</span>
)}
</div>
);
};

class RegEdit extends App {
hidden = false;
constructor() {
super();
this.name = "Registry Editor";
this.icon = "/assets/icons/regedit.svg";
this.package = "anura.regedit";
}

css = css`
display: flex;
border-top: 1px solid var(--theme-border) #pane-left {
width: max(10%, 200px);
border-right: 1px solid var(--theme-border);
overflow: scroll;
text-overflow: nowrap;
white-space: nowrap;
padding-left: 0.5em;
}
#pane-right {
width: calc(100% - max(10%, 200px));
min-width: 400px;
padding-inline: 0.5em;
}
#detail {
width: 100%;
height: 100%;
}
table {
width: 100%;
margin: 0;
}
.value {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 8em;
}
.name {
max-width: 8em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
`;
state = $state({
selected: anura.settings.cache,
});

page = async () => (
<div
style={{
height: "100%",
width: "100%",
position: "absolute",
color: use(anura.ui.theme.state.foreground),
background: use(anura.ui.theme.state.background),
}}
class={`background ${this.css}`}
>
<div id="pane-left">
<div id="detail">
<details open>
<summary>
<span
on:click={(e: MouseEvent) => {
e.preventDefault();
this.state.selected = anura.settings.cache;
}}
>
System
</span>
</summary>
{Object.entries(anura.settings.cache)
.filter((setting) => {
return (
setting[1] instanceof Object &&
!(setting[1] instanceof Array)
);
})
.map((item: any) => (
<DisclosureGroup
entry={item}
bind:sel={use(this.state.selected)}
sel={this.state.selected}
/>
))}
</details>
</div>
</div>

<div id="pane-right">
{/* someone else can make this resizable, i cba */}
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Value</th>
</tr>
{use(this.state.selected, (sel) =>
Object.entries(sel)
.filter((setting) => {
return (
!(setting[1] instanceof Object) ||
setting[1] instanceof Array
);
})
.map((item: any) => (
<tr
on:dblclick={() => {
switch (typeof item[1]) {
case "boolean":
anura.dialog
.confirm(
`The key will be set to ${!item[1]}`,
`Change value of ${item[0]}?`,
)
.then((value) => {
if (value) {
sel[item[0]] =
!item[1];
anura.settings.save();
}
});
break;
case "number":
anura.dialog
.prompt(
`Enter new value for ${item[0]}`,
item[1],
)
.then((value) => {
if (value !== null) {
const val2 = parseInt(
value as string,
);
sel[item[0]] = val2;
anura.settings.save();
}
});
break;
case "object":
// anura.dialog.prompt(`Enter new value for ${item[0]}`, item[1])
// .then((value) => {
// if (value !== null) {
// let val2 = JSON.parse(value as string);
// sel[item[0]] = val2;
// anura.settings.save();
// }
// });
break;
default:
anura.dialog
.prompt(
`Enter new value for ${item[0]}`,
item[1],
)
.then((value) => {
if (value !== null) {
const val2 =
value as string;
sel[item[0]] = val2;
anura.settings.save();
}
});
break;
}
}}
>
<td class="name">{item[0]}</td>
<td class="type">{typeof item[1]}</td>
<td class="value">{item[1]}</td>
</tr>
)),
)}
</table>
</div>
</div>
);

async open(): Promise<WMWindow | undefined> {
const win = anura.wm.create(this, {
title: "Registry Editor",
width: "910px",
height: `${(720 * window.innerHeight) / 1080}px`,
resizable: true,
});

win.content.appendChild(await this.page());
if (!anura.settings.get("disable-regedit-warning")) {
anura.dialog
.confirm(
"Are you sure you want to continue?",
"Editing the registry can cause irreparable damage to your system!",
)
.then((value) => {
if (value === false) {
win.close();
}
});
}

return win;
}
}
2 changes: 1 addition & 1 deletion src/coreapps/TaskManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class TaskManager extends App {
constructor() {
super();
this.name = "Task Manager";
this.icon = "/assets/icons/generic.png";
this.icon = "/assets/icons/system-monitor.svg";
this.package = "anura.taskmgr";
}

Expand Down
2 changes: 1 addition & 1 deletion x86_image_wizard/twisp

0 comments on commit 273af9e

Please sign in to comment.