From 27a4a172cb1871fcd5615e5cdce6b0aae218f88c Mon Sep 17 00:00:00 2001 From: Angelo Trotta Date: Fri, 19 Jun 2026 09:29:51 +0200 Subject: [PATCH] refactor macos support into single file --- README.md | 31 ++++++++++++++++++++++++------- deno.json | 8 ++++---- unlock-mac.ts | 37 ------------------------------------- unlock.ts | 29 ++++++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 51 deletions(-) delete mode 100644 unlock-mac.ts diff --git a/README.md b/README.md index bbba01d..1152b3f 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ This tool modifies the Brave Origin browser's local state configuration to unloc - ✅ Unlocks Brave Origin features - ✅ Modifies purchase validation state - ✅ Updates SKU credentials -- ✅ Windows and macOS path compatibility -- ✅ Easy execution via Deno tasks +- ✅ Windows and macOS auto-detection & compatibility +- ✅ Easy execution and cross-compilation via Deno tasks ## Requirements @@ -32,18 +32,35 @@ This tool modifies the Brave Origin browser's local state configuration to unloc ## How to Run 🚀 -You can run the unlocker directly using the pre-configured Deno tasks: +The script automatically detects whether you are running on Windows or macOS. You can run the unlocker directly with: -### For Windows 🪟 ```bash -deno task unlock-win +deno task unlock ``` -### For macOS 🍎 +--- + +## How to Compile / Cross-Compile 📦 + +You can build standalone binaries for different operating systems and architectures using the pre-configured compilation tasks: + +### Compile for Windows (x64) ```bash -deno task unlock-mac +deno task compile-win ``` +### Compile for macOS Apple Silicon (ARM64) +```bash +deno task compile-mac-arm +``` + +### Compile for macOS Intel (x64) +```bash +deno task compile-mac-x64 +``` + +These tasks will output the built binaries into the `dist/` directory. + --- ## Pre-Bundled Deno Binaries 🎉 diff --git a/deno.json b/deno.json index ce23f61..d72c1db 100644 --- a/deno.json +++ b/deno.json @@ -1,8 +1,8 @@ { "tasks": { - "unlock-win": "deno run --allow-env --allow-read --allow-write unlock.ts", - "unlock-mac": "deno run --allow-env --allow-read --allow-write unlock-mac.ts", - "compile-win": "deno compile --allow-env --allow-read --allow-write --output dist/unlock-win.exe unlock.ts", - "compile-mac": "deno compile --allow-env --allow-read --allow-write --output dist/unlock-mac unlock-mac.ts" + "unlock": "deno run --allow-env --allow-read --allow-write unlock.ts", + "compile-win": "deno compile --allow-env --allow-read --allow-write --target x86_64-pc-windows-msvc --output dist/unlock-win.exe unlock.ts", + "compile-mac-arm": "deno compile --allow-env --allow-read --allow-write --target aarch64-apple-darwin --output dist/unlock-mac-arm unlock.ts", + "compile-mac-x64": "deno compile --allow-env --allow-read --allow-write --target x86_64-apple-darwin --output dist/unlock-mac-x64 unlock.ts" } } \ No newline at end of file diff --git a/unlock-mac.ts b/unlock-mac.ts deleted file mode 100644 index 2aa6735..0000000 --- a/unlock-mac.ts +++ /dev/null @@ -1,37 +0,0 @@ -const homeDir = Deno.env.get("HOME"); -const versions = ["Brave-Origin", "Brave-Origin-Beta", "Brave-Origin-Nightly"]; -let foundAny = false; - -for (const version of versions) { - const localStatePath = `${homeDir}/Library/Application Support/BraveSoftware/${version}/Local State`; - - try { - const localState = JSON.parse(await Deno.readTextFile(localStatePath)); - - localState.brave = localState.brave || {}; - localState.brave.origin = { purchase_validated: true }; - - localState.skus = { - state: { - "67": JSON.stringify({ - credentials: { - items: { "6": "7" }, - }, - }), - }, - }; - - await Deno.writeTextFile(localStatePath, JSON.stringify(localState)); - console.log(version.replace(/-/g, " ") + " unlocked successfully!"); - foundAny = true; - } catch (error) { - if (error instanceof Deno.errors.NotFound) { - continue; - } - throw error; - } -} - -if (!foundAny) { - console.log("Brave Origin not found."); -} \ No newline at end of file diff --git a/unlock.ts b/unlock.ts index 494e2cd..043acfa 100644 --- a/unlock.ts +++ b/unlock.ts @@ -1,15 +1,38 @@ -const localAppData = Deno.env.get("LOCALAPPDATA"); +const os = Deno.build.os; + +let localStatePathPattern: (version: string) => string; + +if (os === "windows") { + const localAppData = Deno.env.get("LOCALAPPDATA"); + if (!localAppData) { + console.error("Error: LOCALAPPDATA environment variable not found."); + Deno.exit(1); + } + localStatePathPattern = (version) => + `${localAppData}\\BraveSoftware\\${version}\\User Data\\Local State`; +} else if (os === "darwin") { + const homeDir = Deno.env.get("HOME"); + if (!homeDir) { + console.error("Error: HOME environment variable not found."); + Deno.exit(1); + } + localStatePathPattern = (version) => + `${homeDir}/Library/Application Support/BraveSoftware/${version}/Local State`; +} else { + console.error(`Error: Unsupported operating system: ${os}`); + Deno.exit(1); +} const versions = ["Brave-Origin", "Brave-Origin-Beta", "Brave-Origin-Nightly"]; let foundAny = false; for (const version of versions) { - const localStatePath = - `${localAppData}\\BraveSoftware\\${version}\\User Data\\Local State`; + const localStatePath = localStatePathPattern(version); try { const localState = JSON.parse(await Deno.readTextFile(localStatePath)); + localState.brave = localState.brave || {}; localState.brave.origin = { purchase_validated: true }; localState.skus = {