Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
homebrew toBase64
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Dec 9, 2023
1 parent f4dcbac commit 9f09609
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Brightness Tray</title>
<script src="/src/devtools.js"></script>
<script type="module" src="/src/polyfill.js"></script>
<script type="module" src="/src/main.ts"></script>
</head>
<body><div id="root" role="application"></div></body>
Expand Down
11 changes: 0 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"dependencies": {
"@tauri-apps/api": "1.5.x",
"core-js": "^3.34.0",
"lodash-es": "4.x",
"vue": "3.x"
},
Expand Down
3 changes: 0 additions & 3 deletions src/polyfill.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/polyfill.js

This file was deleted.

28 changes: 28 additions & 0 deletions src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export function toBase64(array: Uint8Array | Uint8ClampedArray): string {
let base64 = "";
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const padding = array.length % 3;

for (let i = 0; i < array.length - padding; i += 3) {
const combined = (array[i] << 16) | (array[i + 1] << 8) | array[i + 2];
base64 +=
characters[(combined >> 18) & 63] +
characters[(combined >> 12) & 63] +
characters[(combined >> 6) & 63] +
characters[combined & 63];
}

if (padding === 2) {
const combined = (array[array.length - 2] << 8) | array[array.length - 1];
base64 +=
characters[(combined >> 10) & 63] +
characters[(combined >> 4) & 63] +
characters[(combined << 2) & 63] +
"=";
} else if (padding === 1) {
const combined = array[array.length - 1];
base64 += characters[(combined >> 2) & 63] + characters[(combined << 4) & 63] + "==";
}

return base64;
}
3 changes: 2 additions & 1 deletion src/wm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { listen, Event } from "@tauri-apps/api/event";
import { LogicalPosition, LogicalSize, PhysicalPosition, appWindow } from "@tauri-apps/api/window";
import { reactive, watch, watchEffect, ref, computed } from "vue";
import { watchDelayed, watchThrottled } from "./watchers";
import { toBase64 } from "./polyfill";
import settings from "./settings";

const panelState = reactive({
Expand Down Expand Up @@ -222,7 +223,7 @@ watchEffect(() => {
const imageData = ctx.getImageData(0, 0, scaledSize, scaledSize);
invoke("set_tray_icon", {
icon: {
rgba: new Uint8Array(imageData.data.buffer).toBase64(),
rgba: toBase64(imageData.data),
width: imageData.width,
height: imageData.height,
},
Expand Down

0 comments on commit 9f09609

Please sign in to comment.