Skip to content

Commit

Permalink
more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Oct 4, 2024
1 parent 5803847 commit 62c5b98
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 84 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<script type="text/javascript" src="lib/api/WmApi.js"></script>
<script type="text/javascript" src="lib/AliceWM.js"></script>
<script type="text/javascript" src="lib/Taskbar.js"></script>
<script type="text/javascript" src="lib/api/ContextMenuAPI.js"></script>
<script type="text/javascript" src="lib/api/ContextMenu.js"></script>
<script type="text/javascript" src="lib/Launcher.js"></script>
<script type="text/javascript" src="lib/QuickSettings.js"></script>
<script type="text/javascript" src="lib/Calendar.js"></script>
Expand Down
14 changes: 2 additions & 12 deletions src/AliceWM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,18 @@ type SnappedWindow = {
direction: "left" | "right" | "ne" | "nw" | "se" | "sw";
};

let splitBar: WMSplitBar | null = null;

const minimizedSnappedWindows: SnappedWindow[] = [];

const snappedWindows: SnappedWindow[] = [];

/**
* to show a floating dialog displaying the given dom element
* @param {Object} title "title of the dialog"
*/

const windowInformation = {};
const windowID = 0;
let splitBar: WMSplitBar | null = null;

class WindowInformation {
title: string;
height: string;
width: string;
minwidth: number;
height: string;
minheight: number;
allowMultipleInstance = false;
resizable: boolean;
}

Expand Down Expand Up @@ -1206,7 +1197,6 @@ let AliceWM = {
minwidth: 40,
width: "1000px",
height: "500px",
allowMultipleInstance: false,
resizable: true,
};
// Param given in argument
Expand Down
60 changes: 1 addition & 59 deletions src/Anura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Anura {
uri = new URIHandlerAPI();
files = new FilesAPI();
wm = new WMAPI();
ContextMenu = ContextMenuAPI;
ContextMenu = ContextMenu;

private constructor(
fs: AnuraFilesystem,
Expand Down Expand Up @@ -225,64 +225,6 @@ class Anura {
}
}

interface AppManifest {
/**
* The name of the app.
*/
name: string;
/**
* The type of the app. This can be "manual", "auto" or "webview". If it is "manual", the app will be handled by the
* handler specified in the handler field. If it is "auto", the app will be handled by the index file
* specified in the index field. If it is "webview", the app will be handled by the website specified in the src field.
* If the type is not "manual", "auto", or "webview", it will be handled by the anura
* library specified in the type field.
*/
type: "manual" | "auto" | "webview" | string;
/**
* The package name of the app. This should be unique to the app and should be in reverse domain notation.
* For example, if the app is called "My App" and is made by "My Company", the package name should be
*/
package: string;
/**
* The index file for the app. This is the file that will be loaded when the app is launched when the app
* is in auto mode.
*/
index?: string;
/**
* The icon for the app. This should be a URL to an image file.
*/
icon: string;
/**
* The handler for the app. This is the file that will be loaded when the app is launched when the app
* is in manual mode.
*/
handler?: string;
/**
* The link for the app. This is the website that will be loaded when the app is launched when the app
* is in webview mode.
*/
src?: string;
/**
* Whether or not the app should be hidden from the app list. This is useful for apps that are
* only meant to be launched by other apps.
*/
hidden?: boolean;
/**
* The background color of the element directly behind the app's window. This is optional and defaults
* to the system theme's background color.
*/
background?: string;
/**
* This contains the properties for the default app window.
*/
wininfo: string | WindowInformation;
/**
* Whether or not the app should use the IDB wrapper. This option allows the app to access indexedDB without
* worrying about the app purging anura's own databases.
*/
useIdbWrapper?: boolean;
}

class SWProcess extends Process {
pid = 0;
title = "Service Worker";
Expand Down
3 changes: 2 additions & 1 deletion src/Taskbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class Taskbar {
</li>
));
}
#contextMenu = new ContextMenuAPI(true); // This is going to be before anura is initialized, so we can't use anura.ContextMenu

#contextMenu = new ContextMenu(true); // This is going to be before anura is initialized, so we can't use anura.ContextMenu
showcontext(app: App, e: MouseEvent) {
if (app.windows.length > 0) {
this.#contextMenu.removeAllItems();
Expand Down
1 change: 1 addition & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function catBufs(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
}

function dbg(ref: object) {
const name = Object.keys(ref)[0]!;
dg[name] = name;
Expand Down
2 changes: 1 addition & 1 deletion src/api/ContextMenuAPI.tsx → src/api/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ContextMenuAPI {
class ContextMenu {
large = false;
#element = (
<div class={`custom-menu${this.large ? " large" : ""}`} style=""></div>
Expand Down
61 changes: 59 additions & 2 deletions src/coreapps/ExternalApp.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
interface AppManifest {
/**
* The name of the app.
*/
name: string;
/**
* The type of the app. This can be "manual", "auto" or "webview". If it is "manual", the app will be handled by the
* handler specified in the handler field. If it is "auto", the app will be handled by the index file
* specified in the index field. If it is "webview", the app will be handled by the website specified in the src field.
* If the type is not "manual", "auto", or "webview", it will be handled by the anura
* library specified in the type field.
*/
type: "manual" | "auto" | "webview" | string;
/**
* The package name of the app. This should be unique to the app and should be in reverse domain notation.
* For example, if the app is called "My App" and is made by "My Company", the package name should be
*/
package: string;
/**
* The index file for the app. This is the file that will be loaded when the app is launched when the app
* is in auto mode.
*/
index?: string;
/**
* The icon for the app. This should be a URL to an image file.
*/
icon: string;
/**
* The handler for the app. This is the file that will be loaded when the app is launched when the app
* is in manual mode.
*/
handler?: string;
/**
* The link for the app. This is the website that will be loaded when the app is launched when the app
* is in webview mode.
*/
src?: string;
/**
* Whether or not the app should be hidden from the app list. This is useful for apps that are
* only meant to be launched by other apps.
*/
hidden?: boolean;
/**
* The background color of the element directly behind the app's window. This is optional and defaults
* to the system theme's background color.
*/
background?: string;
/**
* This contains the properties for the default app window.
*/
wininfo: string | WindowInformation;
/**
* Whether or not the app should use the IDB wrapper. This option allows the app to access indexedDB without
* worrying about the app purging anura's own databases.
*/
useIdbWrapper?: boolean;
}

class ExternalApp extends App {
manifest: AppManifest;
source: string;
Expand Down Expand Up @@ -36,10 +94,9 @@ class ExternalApp extends App {
);
});
}

//@ts-expect-error manual apps exist
async open(args: string[] = []): Promise<WMWindow | undefined> {
// TODO: have a "allowmultiinstance" option in manifest? it might confuse users, some windows open a second, some focus
// if (this.windowinstance) return;
if (this.manifest.type === "auto") {
const win = anura.wm.create(this, this.manifest.wininfo as object);

Expand Down
16 changes: 8 additions & 8 deletions src/v86.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ V86.prototype.serial1_send = function (a: string) {
const SLICE_SIZE = 2 ** 17 * 32;
const BUF_SIZE = 256;

interface FakeFile {
slice: (start: number, end: number) => Promise<Blob>;
save: (emulator?: any) => Promise<void>;
delete: () => Promise<void>;
resize: (size: number) => Promise<void>;
size: number;
}

async function InitV86Hdd(): Promise<FakeFile> {
// all right! time to explain what goes on here

Expand Down Expand Up @@ -845,11 +853,3 @@ class V86Backend {
};
}
}

interface FakeFile {
slice: (start: number, end: number) => Promise<Blob>;
save: (emulator?: any) => Promise<void>;
delete: () => Promise<void>;
resize: (size: number) => Promise<void>;
size: number;
}

0 comments on commit 62c5b98

Please sign in to comment.