Skip to content

Commit 91768ae

Browse files
committed
Alpha 7 - Added SDK to AzuOS
- Created an SDK for AzuOS (Still in development) - Logging in is faster due to the use of the enter key - Redid app launching functionality - Probably much more that i forgot to document
1 parent 3ca3d37 commit 91768ae

32 files changed

Lines changed: 1277 additions & 217 deletions

desktop.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<link rel="stylesheet" href="index.css">
66
</head>
77
<body>
8-
<div id=welcome class=welcome>
8+
<!-- <div id=welcome class=welcome>
99
<script src=scripts/welcome.js></script>
1010
<p class=welcometext>Welcome!</p>
1111
</div>
12-
<div id=desktop class=desktop>
12+
--> <div id=desktop class=desktop>
1313
<link rel="stylesheet" href="scripts/winbox.min.css">
1414
<link rel="stylesheet" href="window.css">
1515
<script src=scripts/winbox.min.js></script>
File renamed without changes.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<html>
33
<head>
44
<title>AzuOS</title>
5-
<link rel="stylesheet" href="boot.css">
6-
<link rel="stylesheet" href="login.css">
5+
<link rel="stylesheet" href="stylesheets/boot.css">
6+
<link rel="stylesheet" href="stylesheets/login.css">
77
<script src=pkgs/bootloader.js></script>
88
</head>
99
<body>

index.py

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,58 @@
11
import webview
22
import subprocess
3+
import os
4+
import pathlib
35

46
class Api:
57
def get_wifi_networks(self):
68
print('not implemented')
79

10+
def fetch_directory(self, path):
11+
if path.startswith("~/"):
12+
result = os.listdir(pathlib.Path.home() / path[2:])
13+
else:
14+
result = os.listdir(path)
15+
16+
# Separate files and folders
17+
files = []
18+
folders = []
19+
20+
for entry in result:
21+
full_path = pathlib.Path(path).expanduser() / entry # Get the full path of the entry
22+
if full_path.is_file():
23+
files.append(entry) # Add to files list
24+
elif full_path.is_dir():
25+
folders.append(entry) # Add to folders list
26+
27+
return files, folders # Return both lists
28+
29+
def fetch_file(self, type, path):
30+
if type=="plain":
31+
if path.startswith("~/"):
32+
# Open the file in read mode
33+
with open(os.path.expanduser(path), 'r') as file:
34+
return file.read()
35+
else:
36+
with open(path, 'r') as file:
37+
return file.read()
38+
39+
if type=="path":
40+
if path.startswith("~/"):
41+
return 'file://' + os.path.expanduser(path)
42+
else:
43+
return 'file://' + path
44+
45+
846
print('Starting AzuOS...')
947

10-
webview.create_window('AzuOS', url="desktop/index.html", background_color='#000000', fullscreen=True)
11-
webview.start(private_mode=False)
48+
# Instantiate Api class
49+
api = Api()
50+
51+
webview.settings = {
52+
'ALLOW_FILE_URLS': True
53+
}
54+
# webview.create_window('AzuOS', url="index.html", background_color='#000000', fullscreen=True, js_api=api)
55+
56+
webview.create_window('AzuOS', url="index.html", background_color='#000000', js_api=api)
57+
58+
webview.start(debug=True)
File renamed without changes.

libs/api/fileManagement.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
File Manager API for AzuOS
3+
Written by: MTSyntho @ AzuSystem 2024
4+
*/
5+
6+
// function fetch_directory(path) {
7+
// result = pywebview.api.fetch_directory(path);
8+
// return result
9+
// console.log('[File Interaction API] Returned Directory Items')
10+
// }
11+
12+
async function fetch_directory(path) {
13+
try {
14+
const result = await pywebview.api.fetch_directory(path);
15+
console.log('[File Interaction API] Returned Directory Items', result);
16+
return result; // Return the result for further use
17+
} catch (error) {
18+
console.error("[File Interaction API] Error Occured while fetching directory: ", error);
19+
return null; // Return null or handle the error as needed
20+
}
21+
}
22+
23+
24+
// function fetch_file(path, type) {
25+
// result = pywebview.api.fetch_file(type, path);
26+
// return result
27+
// }
28+
29+
async function fetch_file(path, type) {
30+
try {
31+
const result = await pywebview.api.fetch_file(type, path);
32+
if (type==='plain') {
33+
console.log(`[File Interaction API] Returned Plain Text from '${path}'`)
34+
} else if (type==='path') {
35+
console.log(`[File Interaction API] Returned File URL from '${path}'`)
36+
}
37+
return result; // Return the result if needed
38+
} catch (error) {
39+
console.error("[File Interaction API] Error Occured while fetching file: ", error);
40+
return null; // Or handle the error as needed
41+
}
42+
}

libs/loadmodule.js

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,72 @@
33
Written by: Someone on StackOverflow - https://stackoverflow.com/a/950146
44
*/
55

6-
function loadPackage(file) {
7-
var script = document.createElement("script");
8-
script.src = `pkgs/${file}`;
9-
document.head.appendChild(script);
6+
function loadPackage(packagePath) {
7+
const splitPath = packagePath.split(':', 2);
8+
const scriptPath = `pkgs/${splitPath[0]}/${splitPath[1]}`;
9+
// console.log(`result: ${splitPath}`)
1010

11-
console.log(`[Package Injector] Imported '${file}'`)
12-
};
11+
var script = document.createElement("script");
12+
script.src = scriptPath;
13+
document.head.appendChild(script);
14+
15+
console.log(`[Package Injector] Imported '${scriptPath}'`);
16+
}
17+
18+
function loadLibrary(libraryPath) {
19+
const splitPath = libraryPath.split(':', 2);
20+
const scriptPath = `libs/${splitPath[0]}/${splitPath[1]}`;
21+
// console.log(`result: ${libraryPath}`)
1322

14-
function loadLibrary(file) {
1523
var script = document.createElement("script");
16-
script.src = `libs/${file}`;
24+
script.src = scriptPath;
1725
document.head.appendChild(script);
1826

19-
console.log(`[Library Injector] Imported '${file}'`)
20-
};
27+
console.log(`[Library Injector] Imported '${libraryPath}'`)
28+
}
29+
30+
function loadPromisedPackage(packagePath) {
31+
return new Promise((resolve, reject) => {
32+
const splitPath = packagePath.split(':', 2);
33+
const scriptPath = `pkgs/${splitPath[0]}/${splitPath[1]}`;
34+
35+
var script = document.createElement("script");
36+
script.src = `scriptPath`;
37+
38+
script.onload = () => {
39+
console.log(`[Package Injector] Imported '${scriptPath}'`);
40+
resolve();
41+
};
42+
43+
script.onerror = () => {
44+
console.error(`[Package Injector] Failed to import '${scriptPath}'`);
45+
reject(new Error(`[Package Injector] Failed to load package: '${scriptPath}'`));
46+
};
47+
48+
document.head.appendChild(script);
49+
});
50+
}
51+
52+
function loadPromisedLibrary(file) {
53+
return new Promise((resolve, reject) => {
54+
var script = document.createElement("script");
55+
script.src = `libs/${file}`;
56+
57+
script.onload = () => {
58+
console.log(`[Library Injector] Imported '${file}'`);
59+
resolve();
60+
};
61+
62+
script.onerror = () => {
63+
console.error(`[Library Injector] Failed to import '${file}'`);
64+
reject(new Error(`[Library Injector] Failed to load library: ${file}`));
65+
};
66+
67+
document.head.appendChild(script);
68+
});
69+
}
70+
71+
2172

2273
function loadJS(file) {
2374
var script = document.createElement("script");
@@ -27,34 +78,66 @@ function loadJS(file) {
2778
console.log(`[Javascript Injector] Imported '${file}'`)
2879
};
2980

30-
function unloadPackage(file) {
31-
const script = document.querySelector(`script[src="pkgs/${file}"]`);
81+
function unloadPackage(packagePath) {
82+
const splitPath = packagePath.split(':', 2);
83+
const scriptPath = `pkgs/${splitPath[0]}/${splitPath[1]}`;
84+
85+
const script = document.querySelector(`script[src="${scriptPath}"]`);
3286
if (script) {
3387
script.remove();
34-
console.log(`[Package Injector] Unloaded '${file}'.`);
88+
console.log(`[Package Injector] Unloaded '${scriptPath}'.`);
3589
} else {
36-
console.error(`[Package Injector] Can't locate '${file}' for unloading.`);
90+
console.error(`[Package Injector] Can't locate '${scriptPath}' for unloading.`);
3791
}
3892
}
3993

4094
function loadCSS(file) {
4195
var link = document.createElement('link');
4296
link.rel = 'stylesheet';
4397
link.type = 'text/css';
44-
link.href = file;
98+
link.href = `stylesheets/${file}`;
4599

46100
document.head.appendChild(link);
47101
console.log(`[CSS Injector] Imported '${file}'`)
48102
}
49103

104+
function loadRawPathCSS(file) {
105+
var link = document.createElement('link');
106+
link.rel = 'stylesheet';
107+
link.type = 'text/css';
108+
link.href = file;
109+
110+
document.head.appendChild(link);
111+
console.log(`[CSS Injector] Imported '${file}' from Raw Path`)
112+
}
113+
50114
// Generate by ChatGTP
51-
// However I still can't figure it out
52115
function unloadCSS(file) {
53-
const link = document.querySelector(`link[href="${file}"]`);
116+
const link = document.querySelector(`link[href="stylesheets/${file}"]`);
54117
if (link) {
55118
link.remove();
56119
console.log(`[CSS Injector] Removed CSS file: ${file}`);
57120
} else {
58121
console.error(`[CSS Injector] CSS file not found: ${file}`);
59122
}
123+
}
124+
125+
function loadTheme(file) {
126+
var link = document.createElement('link');
127+
link.rel = 'stylesheet';
128+
link.type = 'text/css';
129+
link.href = `themes/${file}`;
130+
131+
document.head.appendChild(link);
132+
console.log(`[Theme Manager] Imported '${file}'`)
133+
}
134+
135+
function unloadTheme(file) {
136+
const link = document.querySelector(`link[href="themes/${file}"]`);
137+
if (link) {
138+
link.remove();
139+
console.log(`[Theme Manager] Removed Theme: ${file}`);
140+
} else {
141+
console.error(`[Theme Manager] Theme not found: ${file}`);
142+
}
60143
}

0 commit comments

Comments
 (0)