Skip to content

Commit

Permalink
add menu item to show workspace size (#21)
Browse files Browse the repository at this point in the history
* add menu item to show workspace size

* bump version
  • Loading branch information
The0zzy authored Apr 27, 2024
1 parent 27669d6 commit 734d2fa
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
48 changes: 41 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,9 @@
.request(`GET ${apiEndPoint}`, { per_page: 100 })
.then((repoResult) => {
repoResult.data.forEach((repo) => {
let optGroups =
document.forms.githubSetup.repository.getElementsByTagName(
"optgroup"
);
let optGroups = document.forms.githubSetup.repository.getElementsByTagName(
"optgroup"
);
let optGroup = optGroups.namedItem(repo.owner.login);
let repoOption = document.createElement("option");
repoOption.setAttribute(
Expand Down Expand Up @@ -788,7 +787,9 @@
confirm(
"Do you really want to reset this workspace to the latest commit of '" +
pluginDataForPlayground.repository.name +
" / "+pluginDataForPlayground.workspacePath+"' on branch '" +
" / " +
pluginDataForPlayground.workspacePath +
"' on branch '" +
pluginDataForPlayground.repository.branch +
"'?"
)
Expand Down Expand Up @@ -970,8 +971,9 @@
plugin.getUrl(styleLink.getAttribute("href"))
);
document.head.appendChild(styleLink);
let existingBackdrop =
document.getElementById("dialogBackdrop");
let existingBackdrop = document.getElementById(
"dialogBackdrop"
);
if (existingBackdrop) {
document.body.removeChild(existingBackdrop);
}
Expand Down Expand Up @@ -1013,6 +1015,37 @@
console.error(getLogPrefix("ERROR") + message, data);
}

function getWorkspaceSize() {
return (
new Blob([
JSON.stringify(
_Blockly.serialization.workspaces.save(_Blockly.getMainWorkspace())
),
]).size / 1024
);
}

function showWorkspaceSize() {
let workspaceSize = getWorkspaceSize();
let message =
"The workspace has an upload size of about " +
getWorkspaceSize() +
" kilobyte.";
if (workspaceSize >= 1024) {
message += "\n\nThis might be too big to save the experience!";
}
alert(message);
}

const workspaceSizeItem = {
displayText: "Show Workspace Size",
preconditionFn: () => "enabled",
callback: showWorkspaceSize,
scopeType: _Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
id: "gitHubWorkspaceSizeItem",
weight: 180,
};

const gitHubExportItem = {
displayText: "Export Workspace",
preconditionFn: () => "enabled",
Expand Down Expand Up @@ -1086,6 +1119,7 @@
);
githubMenu.weight = 99;
githubMenu.options = [
"items.gitHubWorkspaceSizeItem",
"items.gitHubExportItem",
"items.gitHubImportItem",
"items.gitHubImportItemXML",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "bf2042-portal-github-plugin",
"name": "GitHub Integration",
"version": "1.1.0",
"version": "1.2.0",
"author": "TheOzzy",
"main": "index.js",
"homepage": "https://the0zzy.github.io/bf2042-portal-github-plugin/",
Expand Down

0 comments on commit 734d2fa

Please sign in to comment.