Skip to content

Commit

Permalink
Merge pull request #213 from prettydiff/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
prettydiff authored Jan 23, 2024
2 parents 77ec534 + f84c4d5 commit e65c33a
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 68 deletions.
1 change: 1 addition & 0 deletions lib/browser/content/file_browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ const file_browser:module_fileBrowser = {
file_browser.tools.selectNone(box);
network.send(payload, "file-system");
file_browser.events.select(event);
event.stopPropagation();
},

/* Shows child elements of a directory */
Expand Down
10 changes: 7 additions & 3 deletions lib/browser/utilities/agent_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const agent_status:module_agentStatus = {
}
},
active:boolean = (agent_status.selfStatus.status === "active"),
localDevice:HTMLElement = document.getElementById(browser.identity.hashDevice);
localDevice:HTMLElement = (browser.identity.hashDevice === "")
? null
: document.getElementById(browser.identity.hashDevice);
if (active === false && localDevice !== null) {
localDevice.setAttribute("class", "active");
agent_status.selfStatus.status = "active";
Expand All @@ -46,8 +48,10 @@ const agent_status:module_agentStatus = {
},
idle: function browser_utilities_agentStatus_idle():void {
const localDevice:HTMLElement = document.getElementById(browser.identity.hashDevice),
currentStatus:activityStatus = localDevice.getAttribute("class") as activityStatus;
if (currentStatus === "active") {
currentStatus:activityStatus = (localDevice === null)
? null
: localDevice.getAttribute("class") as activityStatus;
if (currentStatus === "active" && localDevice !== null) {
localDevice.setAttribute("class", "idle");
agent_status.selfStatus.status = "idle";
network.send(agent_status.selfStatus, "agent-status");
Expand Down
30 changes: 15 additions & 15 deletions lib/browser/utilities/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
import uiDefault from "../../common/uiDefault.js";

const browser:browser = {
agents: {
agents: { // agents - stores agent objects by agent hash id
device: {},
user: {}
},
content: document.getElementById("content-area"),
identity: {
content: document.getElementById("content-area"), // content - stores a reference to the content area of the page
identity: { // identity - stores identifiers for the given user/device
hashDevice: "",
hashUser: "",
nameDevice: "",
nameUser: "",
secretDevice: "",
secretUser: ""
},
loading: true,
loadQueue: [],
network: null,
message: [],
pageBody: document.getElementsByTagName("body")[0],
scrollbar: 0,
socket: null,
style: document.createElement("style"),
testBrowser: null,
title: "",
ui: uiDefault,
visible: true
loading: true, // loading - whether the page is still loading events from start/restart
loadQueue: [], // loadQueue - a message queue to store network messages pending page load
network: null, // network - stores network identifiers such as ports and IP addresses
message: [], // message - stores text messages to/from the respective device
pageBody: document.getElementsByTagName("body")[0], // pageBody - stores a reference to the page's body element
scrollbar: 0, // scrollbar - stores the pixel width of scrollbars in the current browser display
socket: null, // socket - stores the primary application socket out of the browser
style: document.createElement("style"), // style - stores a reference to a custom created style element that stores user defined presentation data
testBrowser: null, // testBrowser - stores test automation data respective to a current test item
title: "", // title - stores the text of the application name
ui: uiDefault, // ui - the user interface state object
visible: true // visible - toggles visibility of the document, a performance hack because JavaScript executes faster than visual artifacts render to screen
};

export default browser;
8 changes: 5 additions & 3 deletions lib/browser/utilities/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,11 @@ const modal:module_modal = {
if (type === "invite-ask") {
const inviteBody:HTMLElement = box.getElementsByClassName("agentInvitation")[0] as HTMLElement,
invitation:service_invite = JSON.parse(inviteBody.dataset.invitation) as service_invite;
invitation.action = "invite-answer";
invitation.status = "ignored";
network.send(invitation, "invite");
if (invitation.status === "invited") {
invitation.action = "invite-answer";
invitation.status = "ignored";
network.send(invitation, "invite");
}
} else if (type === "media") {
media.tools.kill(browser.ui.modals[id]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/utilities/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const network:module_network = {
actions[type](socketData);
},

/* Performs the HTTP request */
/* Sends a network message to the terminal */
send: function browser_utilities_network_send(data:socketDataType, service:service_type):void {
const socketData:socketData = {
data: data,
Expand Down
12 changes: 12 additions & 0 deletions lib/browser/utilities/webSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
import browser from "./browser.js";
import network from "./network.js";

/**
* Module definition for browser-side websocket handling.
* ```typescript
* interface module_browserSocket {
* error: () => void; // An error handling method.
* hash : string; // Stores a hash value used to authenticate a client hash tunnel at the server.
* send : (data:socketData) => void; // Packages micro-service data for transmission in the application's micro-service format.
* sock : websocket_local; // Provides a web socket object in a way that allows for explicit type declarations, reuse, and without angering the TypeScript gods.
* start: (callback: () => void, hashDevice:string, type:string) => WebSocket; // Initiates a web socket client from the browser.
* type : string; // Stores the submitted type value.
* }
* ``` */
const webSocket:module_browserSocket = {
error: function browser_utilities_socketError():void {
setTimeout(function browser_utilities_socketError_delay():void {
Expand Down
2 changes: 1 addition & 1 deletion lib/terminal/commands/library/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ const build = function terminal_commands_library_build(config:config_command_bui
// gather the desired comment
{
const reg:RegExp = new RegExp(`\\n {4}interface ${name}`),
tsIndex:number = modules[type].replace(reg, `\ninterface ${name}`).indexOf(`\ninterface ${name}`);
tsIndex:number = modules[type].replace(reg, `\n ?interface ${name}`).indexOf(`\n ?interface ${name}`);
let c:number = tsIndex,
commentEnd:number = 0;
if (tsIndex > 0) {
Expand Down
6 changes: 1 addition & 5 deletions lib/terminal/server/services/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ const message = function terminal_server_services_message(socketData:socketData)
}, "browser");
broadcast("device");
} else {
if (vars.agents[data[0].agentType][data[0].agentTo].status === "offline") {
data.forEach(function terminal_server_services_message_offline(item:message_item):void {
item.offline = true;
});
} else {
if (vars.agents[data[0].agentType][data[0].agentTo].status !== "offline") {
sender.send({
data: data,
service: "message"
Expand Down
7 changes: 5 additions & 2 deletions lib/terminal/server/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const settings = function terminal_server_services_settings(dataPackage:socketDa
node.fs.rename(fileName, `${location}.json`, function terminal_server_services_settings_rename_renameNode(erName:node_error):void {
if (erName !== null) {
node.fs.unlink(fileName, function terminal_server_services_settings_rename_renameNode_unlink():void {
vars.terminal.tempCount = vars.terminal.tempCount - 1;
return;
});
}
Expand Down Expand Up @@ -44,14 +45,15 @@ const settings = function terminal_server_services_settings(dataPackage:socketDa
}
if (vars.test.type === "service") {
writeCallback(null);
} else {

} else if (vars.terminal.tempCount < 100) {
if (data.type !== "ui") {
node.fs.writeFile(fileName, JSON.stringify(data.settings), "utf8", writeCallback);
vars.terminal.tempCount = vars.terminal.tempCount + 1;
} else if (settingsData.storage === "" || settingsData.storage === undefined) {
settingsData.storage = `${vars.path.project}lib${vars.path.sep}storage${vars.path.sep}`;
vars.settings.ui.storage = settingsData.storage;
node.fs.writeFile(fileName, JSON.stringify(data.settings), "utf8", writeCallback);
vars.terminal.tempCount = vars.terminal.tempCount + 1;
} else {
node.fs.stat(settingsData.storage, function terminal_server_services_settings_storageStat(storageError:node_error):void {
if (storageError === null) {
Expand All @@ -63,6 +65,7 @@ const settings = function terminal_server_services_settings(dataPackage:socketDa
settingsData.storage = vars.settings.ui.storage;
}
node.fs.writeFile(fileName, JSON.stringify(data.settings), "utf8", writeCallback);
vars.terminal.tempCount = vars.terminal.tempCount + 1;
});
}
}
Expand Down
15 changes: 10 additions & 5 deletions lib/terminal/test/application/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ const defaultCommand:commands = vars.environment.command,
},
reset: function terminal_test_application_browser_reset():void {
const timeStore:[string, number] = time("Resetting Test Environment", false, 0),
launch = function terminal_test_application_browser_reset_start_launch():void {
const start = function terminal_test_application_browser_reset_readdir_browserLaunch():void {
launch = function terminal_test_application_browser_reset_launch():void {
const start = function terminal_test_application_browser_reset_launch_start():void {
const keyword:string = (process.platform === "darwin")
? "open"
: (process.platform === "win32")
Expand All @@ -402,7 +402,7 @@ const defaultCommand:commands = vars.environment.command,
path:string = `https://${vars.network.domain[0] + port}/?${verboseFlag}`,
// execute a browser by file path to the browser binary
browserCommand:string = (process.argv.length > 0 && (process.argv[0].indexOf("\\") > -1 || process.argv[0].indexOf("/") > -1))
? (function terminal_test_application_browser_reset_readdir_browserLaunch_browserCommand():string {
? (function terminal_test_application_browser_reset_launch_start_browserCommand():string {
if (process.platform === "win32") {
// yes, this is ugly. Windows old cmd shell doesn't play well with file paths
process.argv[0] = `${process.argv[0].replace(/\\/g, "\"\\\"").replace("\"\\", "\\") + "\""}`;
Expand All @@ -415,7 +415,7 @@ const defaultCommand:commands = vars.environment.command,
return `${keyword} ${process.argv[0]} ${path}`;
}())
: `${keyword} ${path}`,
child = function terminal_test_application_browser_reset_readdir_browserLaunch_child(errs:node_childProcess_ExecException, stdout:string, stderr:Buffer | string):void {
child = function terminal_test_application_browser_reset_launch_start_child(errs:node_childProcess_ExecException, stdout:string, stderr:Buffer | string):void {
if (errs !== null) {
error(["Error opening browser in test automation."], errs);
return;
Expand Down Expand Up @@ -867,7 +867,12 @@ const defaultCommand:commands = vars.environment.command,

// Once a reset test is sent it is necessary to eliminate the event portion of the test.
// This ensures the test available to the page upon page refresh for test unit evaluation without further executing the refresh event.
if (testItem.test !== null && testItem.test.interaction !== null && testItem.test.interaction[0].event === "refresh") {
if (
testItem.test !== null &&
testItem.test.interaction !== null &&
testItem.test.interaction.length > 0 &&
testItem.test.interaction[0].event === "refresh"
) {
vars.test.browser.test.interaction = null;
}
},
Expand Down
20 changes: 20 additions & 0 deletions lib/terminal/test/samples/browser_device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ const browserDevice:test_browserItem[] = [
inviteAccept("self", "VM3", "user"),
inviteConfirm("self", "VM3", "user"),

// verify no delay elements in agent management
{
interaction: [],
machine: "self",
name: "On self verify no delay elements within agent management modal",
unit: [
{
node: [
["getModalsByModalType", "agent-management", 0],
["getElementsByClassName", "body", 0],
["getElementsByClassName", "delay", null]
],
qualifier: "is",
target: ["length"],
type: "property",
value: 0
}
]
},

//open shares on self
{
delay: {
Expand Down
Loading

0 comments on commit e65c33a

Please sign in to comment.