├── .github └── workflows │ └── build-and-release.yaml ├── .gitignore ├── LICENSE ├── README.md ├── demo ├── BeatmapLists.gif ├── InstallLocation.gif ├── Library.gif ├── Search.gif ├── SongDownloading.gif ├── SongPreviewing.gif └── VisualPreview.gif ├── electron-builder.yml ├── package.json ├── public ├── dark-theme.css ├── favicon.png ├── global.css ├── icons │ ├── 360degree.svg │ ├── 90degree.svg │ ├── lawless.svg │ ├── lightshow.svg │ ├── noarrows.svg │ ├── offline-internet.svg │ ├── onesaber.svg │ └── standard.svg ├── index.html ├── light-theme.css ├── moderncraft.png └── tooltip.css ├── rollup.config.js ├── src ├── constants │ ├── api-endpoints.js │ ├── channelNames.js │ └── storageKeys.js ├── electron.ts ├── main.js ├── main │ ├── .eslintrc.json │ ├── db │ │ ├── connect.ts │ │ ├── knexfile.ts │ │ ├── migrations │ │ │ ├── 20211224212423_create_library_table.ts │ │ │ ├── 20211224214455_create_library_indexes.ts │ │ │ └── 20211230163255_create_user_settings_table.ts │ │ └── queries │ │ │ ├── library.ts │ │ │ └── userSettings.ts │ ├── downloading │ │ ├── beatmap_downloader.ts │ │ └── downloadManager.ts │ ├── library │ │ └── libraryManager.ts │ ├── previewing │ │ └── previewManager.ts │ ├── settings │ │ └── settingsManager.ts │ ├── updating │ │ └── autoUpdate.ts │ └── utils.ts ├── preload.ts └── render │ ├── App.svelte │ ├── actions │ ├── tooltip.css │ └── tooltip.js │ ├── components │ ├── AudioPlayer.svelte │ ├── Badge.svelte │ ├── BeatmapKey.svelte │ ├── BeatmapList.svelte │ ├── BeatmapListItem.svelte │ ├── BeatmapStat.svelte │ ├── BeatmapStats.svelte │ ├── CharacteristicChip.svelte │ ├── CompletedDownloadsList.svelte │ ├── Dialog.svelte │ ├── Downloads.svelte │ ├── DownloadsListItem.svelte │ ├── Downvotes.svelte │ ├── Drawer.svelte │ ├── DrawerItem.svelte │ ├── EasyChip.svelte │ ├── ErrorNotificationBar.svelte │ ├── ExpertChip.svelte │ ├── ExpertPlusChip.svelte │ ├── Fab.svelte │ ├── FullPageCenteredLayout.svelte │ ├── Grid.svelte │ ├── HardChip.svelte │ ├── InfiniteBeatmapList.svelte │ ├── LinkButton.svelte │ ├── List.svelte │ ├── ListDivider.svelte │ ├── LoadingScreen.svelte │ ├── LoadingSpinner.svelte │ ├── ModeChip.svelte │ ├── NetworkStatusBanner.svelte │ ├── NormalChip.svelte │ ├── OfflineIcon.svelte │ ├── PrimaryText.svelte │ ├── QueuedDownloadsList.svelte │ ├── Rating.svelte │ ├── Scrollbar.svelte │ ├── SecondaryText.svelte │ ├── TabGroup.svelte │ ├── TextButton.svelte │ ├── Toast.svelte │ ├── Tooltip.svelte │ ├── Upvotes.svelte │ └── VideoPreviewDialog.svelte │ ├── constants │ └── beatsaver-api.constants.js │ ├── pages │ ├── Downloads.svelte │ ├── Library │ │ ├── Artists │ │ │ ├── Artist.svelte │ │ │ └── Artists.svelte │ │ ├── Library.svelte │ │ ├── Songs │ │ │ └── Songs.svelte │ │ ├── Uploaders │ │ │ ├── Uploader.svelte │ │ │ └── Uploaders.svelte │ │ └── _shared │ │ │ ├── SongList.svelte │ │ │ └── SongListItem.svelte │ ├── NewSongs.svelte │ ├── Search.svelte │ ├── Settings.svelte │ ├── TopRatedSongs.svelte │ └── UpdateReadyDialog.svelte │ ├── services │ └── beatsaver-api.js │ └── stores │ ├── beatmap-preview.store.js │ ├── beatmap-video-preview.store.js │ ├── beatmap.store.js │ ├── downloads.store.js │ ├── errors.store.js │ ├── library.store.js │ ├── network.store.js │ ├── search.store.js │ ├── settings.store.js │ ├── theme.store.js │ ├── toast.store.js │ └── update-ready-dialog.store.js ├── tsconfig.json └── yarn.lock /.github/workflows/build-and-release.yaml: -------------------------------------------------------------------------------- 1 | name: Build/release 2 | 3 | on: 4 | push: 5 | tags: 6 | - "*" 7 | 8 | jobs: 9 | release: 10 | runs-on: ${{ matrix.os }} 11 | 12 | strategy: 13 | matrix: 14 | os: [windows-latest] 15 | 16 | steps: 17 | - name: Check out Git repository 18 | uses: actions/checkout@v1 19 | 20 | - name: Install Node.js, NPM and Yarn 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: 16 24 | 25 | - name: Build/release Electron app 26 | uses: samuelmeuli/action-electron-builder@v1 27 | with: 28 | # GitHub token, automatically provided to the action 29 | # (No need to define this secret in the repo settings) 30 | github_token: ${{ secrets.github_token }} 31 | build_script_name: "ci:build" 32 | 33 | # If the commit is tagged with a version (e.g. "v1.0.0"), 34 | # release the app after building 35 | release: ${{ startsWith(github.ref, 'refs/tags/v') }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | public/bundle.* 4 | dist 5 | *.sqlite 6 | yarn-error.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BeatHub 2 | 3 | ![BeatSaver Songs](https://img.shields.io/badge/dynamic/json.svg?color=brightgreen&label=BeatSaver&query=totalDocs&suffix=%20songs&url=https%3A%2F%2Fbeatsaver.com%2Fapi%2Fmaps%2Flatest) 4 | 5 | ## Description 6 | 7 | A tiny and fast song browser, downloader, and library manager for Beat Saber! 8 | 9 | --- 10 | 11 | ## Feature Overview 12 | - Discover Songs 13 | - [Search for songs](#search-for-songs) 14 | - [Browse song lists](#browse-song-lists) 15 | - Preview Songs 16 | - [Visual Preview](#visual-preview) 17 | - [Audio Preview](#audio-preview) 18 | - [Download Manager](#download-manager) 19 | - [Manage your library](#library-management) 20 | - [Change settings](#change-settings) 21 | 22 | 23 | --- 24 | 25 | ## Features 26 | 27 | ### Search for Songs 28 | - Search for beatmaps available through beatsaver.com 29 | - Search by artist, song name, or uploader name 30 | 31 | ![Search Demo](demo/Search.gif) 32 | 33 | ### Browse Song Lists 34 | - Browse the list of top-rated songs 35 | - Browse the list of newest songs 36 | 37 | ![Lists Demo](demo/BeatmapLists.gif) 38 | 39 | ### Visual Preview 40 | - Visually preview the songs before you download it 41 | - Scrub through the song 42 | - Change difficulty or mode and preview it 43 | 44 | ![Visual Preview Demo](demo/VisualPreview.gif) 45 | 46 | ### Audio Preview 47 | - Listen to a song before you download it or just to have some background music :) 48 | 49 | ![Audio Preview Demo](demo/SongPreviewing.gif) 50 | 51 | ### Download Manager 52 | - Quickly download custom beatmaps directly to your Beat Saber install directory 53 | - Check progress of your downloads 54 | - Get an alert when your download has finished 55 | 56 | ![Download Demo](demo/SongDownloading.gif) 57 | 58 | ### Library Management 59 | - Downloaded songs will have a green check by them when you browse 60 | - View songs in your library by artist, uploader, or song name 61 | - Preview songs in your library 62 | - Delete a song from your library 63 | 64 | ![Library Demo](demo/Library.gif) 65 | 66 | ### Change Settings 67 | - Change your Beat Saber install folder 68 | - Change theme (light or dark) 69 | 70 | ![Path Demo](demo/InstallLocation.gif) 71 | 72 | --- 73 | 74 | ## How to get 75 | 76 | 1. [Go to releases](https://github.com/doughtnerd/BeatHub/releases) and download the latest version. 77 | 2. If Windows tells you something like "running this isn't safe" run it anyway, it's just saying that because I haven't set up "signing" the executable (next security update hopefully) 78 | 79 | --- 80 | 81 | ## Background 82 | 83 | I was inspired by [BeatDrop](https://github.com/StarGazer1258/BeatDrop), most of the credit goes to the developers 84 | working on that project for ideas on how to make the client work. The rest of the credit goes to the BeatSaver.com devs for their API docs and their online site. 85 | 86 | I started working on this because I was having a bit of an unreliable experience with the BeatDrop (not to knock that project, it's still an excellent mod & map manager) software and felt a more simplified client for browsing & downloading songs would be nice. I also at the time was playing around with [Svelte 3](https://svelte.dev/) & [Electron](https://electronjs.org/) and reeeeally wanted to 87 | build a real world project to learn Svelte 3 with. 88 | 89 | --- 90 | 91 | ## Planned Features 92 | 93 | 1. Mod installation support 94 | 2. Signed binary, to avoid security/antivirus issues 95 | 96 | --- 97 | 98 | ## Contributing 99 | 100 | If anyone wants to, feel free to contribute to the project. 101 | -------------------------------------------------------------------------------- /demo/BeatmapLists.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/BeatmapLists.gif -------------------------------------------------------------------------------- /demo/InstallLocation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/InstallLocation.gif -------------------------------------------------------------------------------- /demo/Library.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/Library.gif -------------------------------------------------------------------------------- /demo/Search.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/Search.gif -------------------------------------------------------------------------------- /demo/SongDownloading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/SongDownloading.gif -------------------------------------------------------------------------------- /demo/SongPreviewing.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/SongPreviewing.gif -------------------------------------------------------------------------------- /demo/VisualPreview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/demo/VisualPreview.gif -------------------------------------------------------------------------------- /electron-builder.yml: -------------------------------------------------------------------------------- 1 | appId: "beathub" 2 | # Package app code into a asar archive. Set to false to debug issues. 3 | asar: true 4 | # Mac OS configuration 5 | mac: 6 | icon: "public/icons/my_app.icns" 7 | category: "public.app-category.utilities" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "beathub", 3 | "description": "Beat Saber custom song browser and downloader", 4 | "author": { 5 | "name": "Christopher Carlson", 6 | "email": "doughtnerd@gmail.com", 7 | "url": "https://github.com/Doughtnerd" 8 | }, 9 | "version": "2.7.8", 10 | "main": "./public/dist/electron.js", 11 | "license": "(MIT OR Apache-2.0)", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/doughtnerd/beathub.git" 15 | }, 16 | "devDependencies": { 17 | "@rollup/plugin-node-resolve": "^13.1.1", 18 | "chokidar": "^3.2.1", 19 | "electron": "^16.0.4", 20 | "electron-builder": "^22.14.5", 21 | "eslint": "^8.6.0", 22 | "npm-run-all": "^4.1.5", 23 | "rollup": "^2.62.0", 24 | "rollup-plugin-commonjs": "^10.1.0", 25 | "rollup-plugin-livereload": "^1.0.0", 26 | "rollup-plugin-postcss": "~2.0.3", 27 | "rollup-plugin-svelte": "^7.1.0", 28 | "rollup-plugin-terser": "^5.3.1", 29 | "sirv-cli": "^0.4.4", 30 | "svelte": "^3.44.3", 31 | "svelte-preprocess": "^4.10.1", 32 | "typescript": "^4.5.4" 33 | }, 34 | "dependencies": { 35 | "adm-zip": "~0.4.13", 36 | "electron-log": "^4.0.3", 37 | "electron-updater": "^4.2.0", 38 | "folder-hash": "^4.0.1", 39 | "knex": "^0.95.15", 40 | "request": "^2.88.0", 41 | "sanitize-filename": "^1.6.3", 42 | "sqlite3": "^5.0.2", 43 | "svelte-awesome": "~2.2.1", 44 | "svelte-infinite-scroll": "~0.1.0", 45 | "svelte-spa-router": "^3.2.0" 46 | }, 47 | "scripts": { 48 | "ts-build": "tsc --project tsconfig.json", 49 | "ci:build": "tsc --project tsconfig.json", 50 | "autobuild": "rollup -c -w", 51 | "build": "yarn ts-build", 52 | "build:full": "yarn ts-build && electron-builder build", 53 | "electron-dev": "yarn ts-build && run-p autobuild pure-electron-dev", 54 | "windows:electron-dev": "yarn ts-build && run-p autobuild windows:pure-electron-dev", 55 | "pure-electron-dev": "NODE_ENV=development electron --inspect=3000 .", 56 | "windows:pure-electron-dev": "set NODE_ENV=development&&set ROLLUP_WATCH=true&&electron --inspect=3000 .", 57 | "publish": "electron-builder --win -p always --projectDir=.", 58 | "postinstall": "install-app-deps", 59 | "knex:migrate:make": "knex --knexfile ./src/main/db/knexfile.js migrate:make", 60 | "knex:seed:make": "knex --knexfile ./src/main/db/knexfile.js seed:make", 61 | "knex:seed:run": "knex --knexfile ./src/main/db/knexfile.js seed:run", 62 | "knex:migrate:latest": "knex --knexfile ./src/main/db/knexfile.js migrate:latest", 63 | "knex": "knex --knexfile ./src/main/db/knexfile.js" 64 | }, 65 | "build": { 66 | "publish": [ 67 | { 68 | "provider": "github", 69 | "owner": "doughtnerd", 70 | "repo": "beathub" 71 | } 72 | ] 73 | } 74 | } -------------------------------------------------------------------------------- /public/dark-theme.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: var(--backgroundText); 3 | } 4 | 5 | button { 6 | color: #333; 7 | background-color: #f4f4f4; 8 | outline: none; 9 | } 10 | 11 | button:hover { 12 | background-color: #bebebe; 13 | } 14 | 15 | button:active { 16 | background-color: #ddd; 17 | } 18 | 19 | button:focus { 20 | border-color: #666; 21 | } 22 | 23 | button.primary { 24 | background-color: var(--primary); 25 | color: white; 26 | } 27 | 28 | :root { 29 | --background: #111111; 30 | --foreground: #252525; 31 | --backgroundText: #f0f0f0; 32 | --foregroundText: #b3b3b3; 33 | 34 | --primary: #1598ef; 35 | --secondary: #ff6347; 36 | --error: #d42d44; 37 | 38 | --listDividerColor: rgba(255, 255, 255, 0.75); 39 | 40 | --tooltipBackgroundColor: var(--background); 41 | 42 | --modeChipBackgroundColor: #d8d8d8; 43 | --modeChipTextColor: rgb(0, 0, 0); 44 | 45 | --easyChipBackgroundColor: #2cc973; 46 | --easyChipTextColor: white; 47 | 48 | --normalChipBackgroundColor: #1598ef; 49 | --normalChipTextColor: white; 50 | 51 | --hardChipBackgroundColor: #ff6347; 52 | --hardChipTextColor: white; 53 | 54 | --expertChipBackgroundColor: #d42d44; 55 | --expertChipTextColor: white; 56 | 57 | --expertPlusChipBackgroundColor: #8f47db; 58 | --expertPlusChipTextColor: white; 59 | 60 | --scrollbarPrimaryColor: var(--primary); 61 | --scrollbarSecondaryColor: var(--secondary); 62 | 63 | --beatmapKeyIconColor: gold; 64 | --beatmapUpvotesIconColor: #2cc973; 65 | --beatmapDownvotesIconColor: #d42d44; 66 | --beatmapDownloadsIconColor: #1598ef; 67 | --beatmapRatingIconColor: #ff6347; 68 | 69 | --beatmapListItemCoverImgSize: 158px; 70 | 71 | --toastBackgroundColor: var(--primary); 72 | --toastTextColor: white; 73 | 74 | --buttonHoverColor: #1598ef6c; 75 | } 76 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/public/favicon.png -------------------------------------------------------------------------------- /public/global.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | position: relative; 4 | } 5 | 6 | body { 7 | margin: 0; 8 | padding: 0; 9 | box-sizing: border-box; 10 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, 11 | Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; 12 | overflow: hidden; 13 | font-size: 16px; 14 | } 15 | 16 | body::-webkit-scrollbar { 17 | display: none; 18 | } 19 | 20 | a { 21 | color: rgb(0, 100, 200); 22 | text-decoration: none; 23 | } 24 | 25 | a:hover { 26 | text-decoration: underline; 27 | } 28 | 29 | a:visited { 30 | color: rgb(0, 80, 160); 31 | } 32 | 33 | label { 34 | display: block; 35 | } 36 | 37 | input, 38 | button, 39 | select, 40 | textarea { 41 | font-family: inherit; 42 | font-size: inherit; 43 | padding: 0.4em; 44 | margin: 0 0 0.5em 0; 45 | box-sizing: border-box; 46 | border: 1px solid #ccc; 47 | border-radius: 2px; 48 | } 49 | 50 | input:disabled { 51 | color: #ccc; 52 | } 53 | 54 | input[type="range"] { 55 | height: 0; 56 | } 57 | 58 | button { 59 | box-shadow: 0 0 2px rgba(0, 0, 0, 0.75); 60 | } 61 | 62 | button:hover { 63 | cursor: pointer; 64 | } 65 | -------------------------------------------------------------------------------- /public/icons/360degree.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/icons/90degree.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /public/icons/lawless.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /public/icons/lightshow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 19 | 20 | -------------------------------------------------------------------------------- /public/icons/noarrows.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /public/icons/offline-internet.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/icons/onesaber.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | -------------------------------------------------------------------------------- /public/icons/standard.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | 12 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | BeatHub 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /public/light-theme.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: var(--backgroundText); 3 | } 4 | 5 | button { 6 | color: var(--backgroundText); 7 | background-color: var(--background); 8 | } 9 | 10 | button:active { 11 | background-color: #ddd; 12 | } 13 | 14 | button:focus { 15 | border-color: #666; 16 | } 17 | 18 | button:hover { 19 | background-color: #8d8d8d; 20 | } 21 | 22 | button.primary { 23 | background-color: var(--primary); 24 | color: white; 25 | } 26 | 27 | :root { 28 | --background: #c5c5c5; 29 | --foreground: #ffffff; 30 | --backgroundText: #000000; 31 | --foregroundText: #555555; 32 | 33 | --primary: #2757a0; 34 | --secondary: #e62200; 35 | --error: #be2942; 36 | 37 | --listDividerColor: rgba(0, 0, 0, 0.75); 38 | 39 | --tooltipBackgroundColor: var(--background); 40 | 41 | --modeChipBackgroundColor: #37363a; 42 | --modeChipTextColor: white; 43 | 44 | --easyChipBackgroundColor: #239557; 45 | --easyChipTextColor: white; 46 | 47 | --normalChipBackgroundColor: #2757a0; 48 | --normalChipTextColor: white; 49 | 50 | --hardChipBackgroundColor: #e62200; 51 | --hardChipTextColor: white; 52 | 53 | --expertChipBackgroundColor: #be2942; 54 | --expertChipTextColor: white; 55 | 56 | --expertPlusChipBackgroundColor: #8f47db; 57 | --expertPlusChipTextColor: white; 58 | 59 | --scrollbarPrimaryColor: #c5c5c5; 60 | --scrollbarSecondaryColor: #c5c5c5; 61 | 62 | --beatmapKeyIconColor: rgb(195, 166, 0); 63 | --beatmapUpvotesIconColor: #239557; 64 | --beatmapDownvotesIconColor: #be2942; 65 | --beatmapDownloadsIconColor: #2755a0; 66 | --beatmapRatingIconColor: #e62200; 67 | 68 | --beatmapListItemCoverImgSize: 158px; 69 | 70 | --toastBackgroundColor: var(--primary); 71 | --toastTextColor: white; 72 | 73 | --buttonHoverColor: #2757a063; 74 | } 75 | -------------------------------------------------------------------------------- /public/moderncraft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/public/moderncraft.png -------------------------------------------------------------------------------- /public/tooltip.css: -------------------------------------------------------------------------------- 1 | .tooltip { 2 | position: absolute; 3 | color: var(--backgroundText); 4 | background-color: var(--tooltipBackgroundColor); 5 | box-shadow: 0 0 1px 1px var(--primary); 6 | border-radius: 8px; 7 | padding: 8px; 8 | width: 120px; 9 | text-align: center; 10 | transition: opacity .5s; 11 | transform: translate(5px, -50%); 12 | } 13 | 14 | .tooltip.left::after { 15 | content: ""; 16 | position: absolute; 17 | top: 50%; 18 | left: 100%; 19 | margin-top: -5px; 20 | border-width: 5px; 21 | border-style: solid; 22 | border-color: transparent transparent transparent var(--tooltipBackgroundColor) ; 23 | } 24 | 25 | .tooltip.right::after { 26 | content: ""; 27 | position: absolute; 28 | top: 50%; 29 | right: 100%; 30 | margin-top: -5px; 31 | border-width: 5px; 32 | border-style: solid; 33 | border-color: transparent var(--tooltipBackgroundColor) transparent transparent; 34 | } -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import svelte from "rollup-plugin-svelte"; 2 | import commonjs from "rollup-plugin-commonjs"; 3 | import livereload from "rollup-plugin-livereload"; 4 | import { terser } from "rollup-plugin-terser"; 5 | import resolve from "@rollup/plugin-node-resolve"; 6 | import sveltePreprocess from 'svelte-preprocess'; 7 | import postcss from 'rollup-plugin-postcss'; 8 | 9 | const production = !process.env.ROLLUP_WATCH; 10 | 11 | export default { 12 | input: "src/main.js", 13 | output: { 14 | sourcemap: true, 15 | format: "umd", 16 | name: "beathub", 17 | file: "public/bundle.js" 18 | }, 19 | plugins: [ 20 | svelte({ 21 | preprocess: sveltePreprocess(), 22 | compilerOptions: { 23 | dev: !production, 24 | css: css => { 25 | css.write("public/bundle.css"); 26 | }, 27 | }, 28 | emitCss: true 29 | }), 30 | resolve({ 31 | browser: true, 32 | dedupe: importee => 33 | importee === "svelte" || importee.startsWith("svelte/") 34 | }), 35 | commonjs(), 36 | postcss({ 37 | extract: true, 38 | minimize: true 39 | }), 40 | !production && livereload("public"), 41 | production && terser() 42 | ], 43 | watch: { 44 | clearScreen: false 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /src/constants/api-endpoints.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doughtnerd/BeatHub/5e525efc50aa78faac38bc0faee820a0b98b7444/src/constants/api-endpoints.js -------------------------------------------------------------------------------- /src/constants/channelNames.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | GET_CURRENT_THEME: "getCurrentTheme", 3 | SET_CURRENT_THEME: "setCurrentTheme", 4 | RESTART_AND_UPDATE: "restartAndUpdate", 5 | UPDATE_DOWNLOADED: "updateDownloaded", 6 | UPDATE_PROGRESS: "updateProgress", 7 | UPDATE_ERROR: "updateError", 8 | UPDATE_NOT_AVAILABLE: "updateNotAvailable", 9 | UPDATE_AVAILABLE: "updateAvailable", 10 | CHECKING_FOR_UPDATE: "checkingForUpdate", 11 | DOWNLOAD_BEATMAP: "downloadBeatmap", 12 | DOWNLOAD_PROGRESS: "downloadProgress", 13 | DOWNLOAD_COMPLETE: "downloadComplete", 14 | DOWNLOAD_ERROR: "downloadError", 15 | CHANGE_DOWNLOAD_DIRECTORY: "changeDownloadDirectory", 16 | GET_BEATSABER_DIRECTORY: "getBeatSaberDirectory", 17 | BEATMAP_DOWNLOAD_ERROR: "beatmapDownloadError", 18 | PREVIEW_BEATMAP: "previewBeatmap", 19 | PREVIEW_LOADED: "previewLoaded", 20 | PREVIEW_ERROR: "previewError", 21 | LOAD_LIBRARY: "loadLibrary", 22 | }; 23 | -------------------------------------------------------------------------------- /src/constants/storageKeys.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | CURRENT_THEME_NAME: "currentThemeName", 3 | BEATSABER_DIRECTORY: "beatSaberDirectory", 4 | }; 5 | -------------------------------------------------------------------------------- /src/electron.ts: -------------------------------------------------------------------------------- 1 | import { app, BrowserWindow, ipcMain, session } from "electron"; 2 | import path from "path"; 3 | import * as downloadManager from "./main/downloading/downloadManager"; 4 | import * as libraryManager from "./main/library/libraryManager"; 5 | import * as previewManager from "./main/previewing/previewManager"; 6 | import * as settingsManager from "./main/settings/settingsManager"; 7 | import * as autoUpdater from './main/updating/autoUpdate' 8 | import url from 'url'; 9 | 10 | import dbConnectionConfig from "./main/db/knexfile"; 11 | import { connectDB } from "./main/db/connect" 12 | 13 | let mainWindow; 14 | 15 | 16 | 17 | ipcMain.handle("getAppVersion", () => { 18 | return app.getVersion(); 19 | }); 20 | 21 | function createWindow() { 22 | const mode = process.env.NODE_ENV; 23 | mainWindow = new BrowserWindow({ 24 | width: 1024, 25 | height: 720, 26 | frame: true, 27 | webPreferences: { 28 | nodeIntegration: false, 29 | contextIsolation: true, 30 | sandbox: true, 31 | // enableRemoteModule: false, 32 | allowRunningInsecureContent: false, 33 | preload: path.join(__dirname, "preload.js"), 34 | }, 35 | }); 36 | 37 | mainWindow.setMenu(null); 38 | 39 | let watcher; 40 | if (mode == "development") { 41 | mainWindow.openDevTools(); 42 | watcher = require("chokidar").watch([path.join(__dirname, "..", "bundle.js"), path.join(__dirname)], { ignoreInitial: true }); 43 | watcher.on("change", () => { 44 | mainWindow.reload(); 45 | }); 46 | } 47 | 48 | mainWindow.loadURL( 49 | url.format({ 50 | pathname: path.join(__dirname, "..", "index.html"), 51 | protocol: "file:", 52 | slashes: true, 53 | }) 54 | ); 55 | mainWindow.on("closed", () => { 56 | if (watcher) { 57 | watcher.close(); 58 | } 59 | mainWindow = null; 60 | }); 61 | 62 | return mainWindow; 63 | } 64 | 65 | 66 | 67 | app.on("ready", async () => { 68 | session.defaultSession.webRequest.onHeadersReceived((details, callback) => { 69 | callback({ 70 | responseHeaders: { 71 | ...details.responseHeaders, 72 | "Content-Security-Policy": [ 73 | "default-src 'self'", 74 | "script-src 'self' 'unsafe-inline' https://kit.fontawesome.com https://skystudioapps.com", 75 | "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", 76 | "connect-src 'self' https://r2cdn.beatsaver.com https://na.cdn.beatsaver.com https://beatsaver.com https://api.beatsaver.com https://ka-f.fontawesome.com", //may need to add data: 77 | "img-src 'self' https://na.cdn.beatsaver.com blob: skystudioapps.com data:", 78 | "media-src 'self' file: blob: skystudioapps.com data:", 79 | "font-src 'self' https://fonts.gstatic.com https://fonts.googleapis.com https://ka-f.fontawesome.com", 80 | "frame-src 'self' https://skystudioapps.com" 81 | ].join("; "), 82 | } 83 | }) 84 | }) 85 | 86 | session 87 | .defaultSession 88 | .setPermissionRequestHandler((webContents, permission, callback) => { 89 | callback(false) 90 | }) 91 | 92 | const dbConnection = await connectDB(dbConnectionConfig) 93 | 94 | const mainWindow = createWindow(); 95 | 96 | downloadManager.register(mainWindow, dbConnection); 97 | previewManager.register(mainWindow); 98 | libraryManager.register(mainWindow, dbConnection); 99 | settingsManager.register(mainWindow, dbConnection); 100 | 101 | const updater = autoUpdater.register(mainWindow); 102 | updater.checkForUpdatesAndNotify(); 103 | }); 104 | 105 | app.on("window-all-closed", () => { 106 | if (process.platform !== "darwin") { 107 | app.quit(); 108 | } 109 | }); 110 | 111 | app.on("activate", () => { 112 | if (mainWindow === null) { 113 | createWindow(); 114 | } 115 | }); 116 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import App from "./render/App.svelte"; 2 | 3 | const app = new App({ 4 | target: document.body, 5 | props: {} 6 | }); 7 | 8 | export default app; 9 | -------------------------------------------------------------------------------- /src/main/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parserOptions": { 8 | "ecmaVersion": 13, 9 | "sourceType": "module" 10 | }, 11 | "rules": { 12 | "indent": [ 13 | "error", 14 | "tab" 15 | ], 16 | "linebreak-style": [ 17 | "error", 18 | "unix" 19 | ], 20 | "quotes": [ 21 | "error", 22 | "double" 23 | ], 24 | "semi": [ 25 | "error", 26 | "always" 27 | ] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/db/connect.ts: -------------------------------------------------------------------------------- 1 | import { app } from "electron"; 2 | import * as fs from 'fs/promises'; 3 | import { knex } from "knex"; 4 | import path from 'path'; 5 | 6 | 7 | /** 8 | * @description This function is explicitly for copying the sqlite file from the app directory to the userData directory. 9 | * This is necessary because the original release of the library manager mistakenly put the sqlite file in the app directory. 10 | * When the user installs an update, that directory is wiped, along with the DB. 11 | */ 12 | function moveExistingDB(): Promise { 13 | const userDataPath = app.getPath('userData'); 14 | const sqliteDBPath = path.join(userDataPath, 'beathubdb.sqlite'); 15 | const oldDbPath = path.join(__dirname, 'beathubdb.sqlite'); 16 | return fs.rename(oldDbPath, sqliteDBPath).then(() => { 17 | console.log('Moved existing database to userData directory'); 18 | }).catch(err => { 19 | console.log('Could not move existing database to userData directory. It likely has already been moved or didnt exist in the first place.'); 20 | console.log(err); 21 | }); 22 | } 23 | 24 | export async function connectDB(config) { 25 | 26 | // The check here is to ensure that the 'dev DB' is not copied over. 27 | if (process.env.NODE_ENV !== 'development'){ 28 | await moveExistingDB(); 29 | } 30 | 31 | const instance = knex(config); 32 | 33 | try { 34 | const migrations = await instance.migrate.latest(); 35 | console.log("Ran Migrations ", migrations); 36 | 37 | // if (process.NODE_ENV === 'development') { 38 | // const seeds = await instance.seed.run() 39 | // console.log('Ran Seeds ', seeds) 40 | // } 41 | } catch(e) { 42 | console.error(`Failed to start db connection: ${e.message}`); 43 | throw e; 44 | } 45 | 46 | return instance; 47 | } 48 | 49 | // module.exports = { 50 | // connectDB 51 | // }; -------------------------------------------------------------------------------- /src/main/db/knexfile.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import {app} from 'electron'; 3 | 4 | const userDataPath = app.getPath('userData'); 5 | console.log(userDataPath) 6 | 7 | const sqliteDBPath = process.env.NODE_ENV === 'development' ? 8 | path.join(__dirname, 'beathubdb.sqlite') : 9 | path.join(userDataPath, 'beathubdb.sqlite'); 10 | 11 | const dbConnectionConfig = { 12 | client: "sqlite", 13 | connection: { 14 | filename: sqliteDBPath 15 | }, 16 | migrations: { 17 | extension: "js", 18 | tableName: "beathub_migrations", 19 | directory: path.join(__dirname, "./", "migrations"), 20 | }, 21 | seeds: { 22 | directory: path.join(__dirname, "./", "seeds", "dev"), 23 | } 24 | }; 25 | 26 | export default dbConnectionConfig; -------------------------------------------------------------------------------- /src/main/db/migrations/20211224212423_create_library_table.ts: -------------------------------------------------------------------------------- 1 | 2 | export function up(knex) { 3 | return knex.schema.createTable("library", table => { 4 | table.text("folder_hash").notNullable().primary(); 5 | table.text("key").notNullable(); 6 | table.text("song_title").notNullable(); 7 | table.text("song_author").notNullable(); 8 | table.text("uploader").notNullable(); 9 | table.text("disk_location").notNullable(); 10 | table.text("cover_filename").notNullable(); 11 | table.text("song_filename").notNullable(); 12 | table.text("added_at").notNullable(); 13 | }); 14 | } 15 | 16 | export function down(knex) { 17 | return knex.schema.hasTable("library").then(exists => { 18 | if (exists) { 19 | return knex.schema.dropTable("library"); 20 | } 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/db/migrations/20211224214455_create_library_indexes.ts: -------------------------------------------------------------------------------- 1 | export function up(knex) { 2 | return knex.table("library", (table) => { 3 | table.index("key", "library_key_index"), 4 | table.index("song_title", "library_song_title_index"), 5 | table.index("song_author", "library_song_author_index"), 6 | table.index("uploader", "library_uploader_index"); 7 | }); 8 | } 9 | 10 | export function down(knex) { 11 | return knex.table("library", (table) => { 12 | table.dropIndex("library_key_index"), 13 | table.dropIndex("library_song_title_index"), 14 | table.dropIndex("library_song_author_index"), 15 | table.dropIndex("library_uploader_index"); 16 | }); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/db/migrations/20211230163255_create_user_settings_table.ts: -------------------------------------------------------------------------------- 1 | 2 | export function up(knex) { 3 | return knex.schema.hasTable("user_settings").then(function(exists) { 4 | if (!exists) { 5 | return knex.schema.createTable("user_settings", function(table) { 6 | table.text("setting_key").primary(); 7 | table.text("setting_value").notNull(); 8 | }); 9 | } 10 | }); 11 | } 12 | 13 | export function down(knex) { 14 | return knex.schema.hasTable("user_settings").then(function(exists) { 15 | if (exists) { 16 | return knex.schema.dropTable("user_settings"); 17 | } 18 | }); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/db/queries/library.ts: -------------------------------------------------------------------------------- 1 | import { Knex } from 'knex'; 2 | 3 | export function getAllSongs(knex: Knex) { 4 | return knex("library").select().orderBy("song_title"); 5 | } 6 | 7 | export function getSongByFolderHash(knex: Knex, hash) { 8 | return knex("library").select().where("folder_hash", hash).first(); 9 | } 10 | 11 | export function getSongsByHash(knex: Knex, hashes) { 12 | return knex("library").select("folder_hash").whereIn("hash", hashes); 13 | } 14 | 15 | export function getSongsByKeys(knex: Knex, keys) { 16 | return knex("library").whereIn("key", keys); 17 | } 18 | 19 | export function getAllDiskLocations(knex: Knex) { 20 | return knex("library").select("disk_location").distinct(); 21 | } 22 | 23 | export function getSongByHash(knex: Knex, hash) { 24 | return knex("library").where({folder_hash: hash}).first(); 25 | } 26 | 27 | export function getSongsPage(knex: Knex, pageNumber, pageSize) { 28 | const offset = (pageNumber - 1) * pageSize; 29 | return knex("library").select().orderBy("added_at", "desc").offset(offset).limit(pageSize); 30 | } 31 | 32 | export function getSongsByUploader(knex: Knex, uploader) { 33 | return knex("library").select().where({uploader: uploader}).orderBy("song_title"); 34 | } 35 | 36 | export function getSongsByAuthor(knex: Knex, author) { 37 | return knex("library").select().where({song_author: author}).orderBy("song_title"); 38 | } 39 | 40 | export function getUploaders(knex: Knex) { 41 | return knex("library").select("uploader").distinct().orderBy("uploader"); 42 | } 43 | 44 | export function getSongAuthors(knex: Knex) { 45 | return knex("library").select("song_author").distinct().orderBy("song_author"); 46 | } 47 | 48 | export function getSongByKey(knex: Knex, key) { 49 | return knex("library").where({key}).first(); 50 | } 51 | 52 | export function getSongByKeyAndName(knex: Knex, key, name) { 53 | return knex("library").where({key, song_title: name}).first(); 54 | } 55 | 56 | export function insertSong(knex: Knex, song) { 57 | return knex("library").insert(song); 58 | } 59 | 60 | export function insertSongs(knex: Knex, songs) { 61 | return knex("library").insert(songs); 62 | } 63 | 64 | export function deleteSongByKeyAndName(knex: Knex, key, name) { 65 | return knex("library").where({key, song_title: name}).del(); 66 | } 67 | 68 | export function deleteSongByFolderHash(knex: Knex, hash) { 69 | return knex("library").where({folder_hash: hash}).del(); 70 | } 71 | 72 | export function deleteSongsByFilesLocations(knex: Knex, locations) { 73 | return knex("library").whereIn("disk_location", locations).del(); 74 | } 75 | 76 | export function findSongByKeyAndName(knex: Knex, key, name) { 77 | return knex("library").where({key, song_title: name}).first(); 78 | } 79 | 80 | export function querySongByText(knex: Knex, text) { 81 | return knex("library") 82 | .where("song_title", "like", `%${text}%`) 83 | .orWhere("song_author", "like", `%${text}%`) 84 | .orWhere("uploader", "like", `%${text}%`) 85 | .orWhere("key", "like", `%${text}%`); 86 | } 87 | 88 | export function insertAllSongsWithTransaction(knex: Knex, songs) { 89 | return knex.transaction(trx => { 90 | const inserts = songs.map(e => { 91 | return knex('library').transacting(trx).insert(e).onConflict("folder_hash").ignore() 92 | }) 93 | 94 | return Promise.all(inserts).then(() => trx.commit()).catch(err => trx.rollback()); 95 | }) 96 | } 97 | -------------------------------------------------------------------------------- /src/main/db/queries/userSettings.ts: -------------------------------------------------------------------------------- 1 | export function hasSetting(knex, settingKey) { 2 | return knex("user_settings").where("setting_key", settingKey).first().then(function(result) { 3 | return result !== undefined; 4 | }); 5 | } 6 | 7 | export function getSetting(knex, settingKey) { 8 | return knex("user_settings").where("setting_key", settingKey).first().then(function(result) { 9 | return result?.setting_value ?? ""; 10 | }); 11 | } 12 | 13 | export function setSetting(knex, settingKey, settingValue) { 14 | return knex("user_settings").insert({setting_key: settingKey, setting_value: settingValue}).onConflict("setting_key").merge(); 15 | } 16 | 17 | // module.exports = { 18 | // hasSetting, 19 | // getSetting, 20 | // setSetting 21 | // } -------------------------------------------------------------------------------- /src/main/downloading/beatmap_downloader.ts: -------------------------------------------------------------------------------- 1 | import AdmZip from "adm-zip"; 2 | import { download } from "../utils"; 3 | import { 4 | DOWNLOAD_COMPLETE, 5 | DOWNLOAD_PROGRESS, 6 | DOWNLOAD_ERROR 7 | } from "../../constants/channelNames"; 8 | 9 | async function extractBeatmap(buffer, rootFolder, songFolderName) { 10 | const zip = new AdmZip(buffer); 11 | zip.extractAllTo( 12 | `${rootFolder}/Beat Saber_Data/CustomLevels/${songFolderName}`, 13 | true 14 | ); 15 | } 16 | 17 | process.on("message", (message: any, sendHandle) => { 18 | const { beatmap, downloadsFolder, songFolderName } = message; 19 | 20 | download( 21 | beatmap.versions[0].downloadURL, 22 | (bytesReceived, totalBytes) => { 23 | process.send({ 24 | messageType: DOWNLOAD_PROGRESS, 25 | beatmap, 26 | bytesReceived, 27 | totalBytes 28 | }); 29 | }, 30 | buffer => { 31 | extractBeatmap(buffer, downloadsFolder, songFolderName); 32 | process.send({ messageType: DOWNLOAD_COMPLETE, beatmap }); 33 | }, 34 | error => { 35 | console.error(error); 36 | process.send({ messageType: DOWNLOAD_ERROR, beatmap, error }); 37 | } 38 | ); 39 | }); 40 | -------------------------------------------------------------------------------- /src/main/downloading/downloadManager.ts: -------------------------------------------------------------------------------- 1 | import { ipcMain } from "electron"; 2 | import { fork } from "child_process"; 3 | import { hashElement } from "folder-hash"; 4 | import { getFileNames, getBeatSaberDirectory, formatFolderName } from "../utils"; 5 | import { insertSong } from "../db/queries/library"; 6 | import path from "path"; 7 | import {readFile} from 'fs/promises' 8 | 9 | 10 | export function register(mainWindow, dbConnection) { 11 | const sendStatusToWindow = (channel, payload) => { 12 | mainWindow.webContents.send(channel, payload); 13 | }; 14 | 15 | const childProcess = fork(`${__dirname}/beatmap_downloader.js`); 16 | 17 | childProcess.on("close", () => { 18 | console.log("Download manager child process quit..."); 19 | }); 20 | childProcess.on("error", error => { 21 | sendStatusToWindow("downloadError", { error }); 22 | }); 23 | childProcess.on("message", async (message: any) => { 24 | if(message.messageType === "downloadComplete") { 25 | const {beatmap} = message; 26 | //Get download folder location 27 | const downloadsFolder = await getBeatSaberDirectory(dbConnection); 28 | 29 | //Get beatmap folder name 30 | const songFolderName = formatFolderName(beatmap.id, beatmap.metadata.songName, beatmap.metadata.songAuthorName); 31 | 32 | const directory = path.join(downloadsFolder, "Beat Saber_Data", "CustomLevels", songFolderName); 33 | const hash = await hashElement(directory, {algo: "md5"}); 34 | 35 | const infoFilePath = (await getFileNames(directory)).find(fName => fName.includes("info.dat") || fName.includes("Info.dat")); 36 | const infoFileContents = await readFile(infoFilePath, {encoding: "utf8"}); 37 | const infoFileJSON = JSON.parse(infoFileContents); 38 | 39 | const songData = { 40 | key: beatmap.id, 41 | folder_hash: hash.hash, 42 | song_title: infoFileJSON._songName || "Unknown", 43 | song_author: infoFileJSON._songAuthorName || "Unknown", 44 | uploader: infoFileJSON._levelAuthorName || "Unknown", 45 | disk_location: directory, 46 | cover_filename: infoFileJSON._coverImageFilename, 47 | song_filename: infoFileJSON._songFilename, 48 | added_at: new Date().toISOString(), 49 | }; 50 | await insertSong(dbConnection, songData).onConflict("folder_hash").merge(); 51 | } 52 | 53 | sendStatusToWindow(message.messageType, message); 54 | }); 55 | 56 | ipcMain.handle("downloadBeatmap", async (event, beatmap) => { 57 | //Get download folder location 58 | const downloadsFolder = await getBeatSaberDirectory(dbConnection); 59 | 60 | //Get beatmap folder name 61 | const songFolderName = formatFolderName(beatmap.id, beatmap.metadata.songName, beatmap.metadata.songAuthorName); 62 | 63 | //Download & extract to location 64 | childProcess.send({ beatmap, downloadsFolder, songFolderName }); 65 | }); 66 | } 67 | 68 | // module.exports = { register }; 69 | -------------------------------------------------------------------------------- /src/main/library/libraryManager.ts: -------------------------------------------------------------------------------- 1 | 2 | import {ipcMain} from "electron"; 3 | import {hashElement} from "folder-hash"; 4 | import { getDirectoryNames, getFileNames, getBeatSaberDirectory } from "../utils"; 5 | import { readFile, access, rm } from "fs/promises"; 6 | import { constants } from "fs"; 7 | import { insertSongs, getSongByHash, getUploaders, getSongsByUploader, getSongsByAuthor, getSongAuthors, getAllSongs, getSongByKey, getAllDiskLocations, deleteSongsByFilesLocations, getSongByFolderHash, deleteSongByFolderHash, insertSong, insertAllSongsWithTransaction } from "../db/queries/library" 8 | import * as path from "path"; 9 | import { Knex } from "knex"; 10 | 11 | type Nothing = null; 12 | type Maybe = T | Nothing 13 | 14 | async function generateEntry(directory): Promise<[string, string]> { 15 | const hash = await hashElement(directory, {algo: "md5"}); 16 | return [hash.hash, directory]; 17 | } 18 | 19 | async function genDirHashMap(rootDir): Promise> { 20 | const beatMapDirectories = await getDirectoryNames(rootDir); 21 | return Promise.all(beatMapDirectories.map(directory => generateEntry(directory))); 22 | } 23 | 24 | async function calcNewSongDirs(dbConnection, rootDir): Promise> { 25 | const entries: Array<[string, string]>= await genDirHashMap(rootDir); 26 | const newSongs = entries.filter(async ([hash, ]) => (await getSongByHash(dbConnection, hash)) == null); 27 | return newSongs; 28 | } 29 | 30 | async function mapInfoFilePaths(data: [string, string][]): Promise<[string, string, Maybe][]> { 31 | const result: [string, string, Maybe][] = []; 32 | for (const [hash, directory] of data) { 33 | const infoFilePath = (await getFileNames(directory)).find(fName => fName.includes("info.dat") || fName.includes("Info.dat")); 34 | if(infoFilePath) { 35 | result.push([hash, directory, infoFilePath]); 36 | } 37 | else { 38 | result.push([hash, directory, null]); 39 | } 40 | } 41 | return result; 42 | } 43 | 44 | async function mapToDbEntries(data: [string, string, Maybe][]): Promise[]> { 45 | const mapped = data.map(async ([hash, directory, maybeInfoFilePath]) => { 46 | if(maybeInfoFilePath === null) { 47 | console.error('Failed to load info data for song: ' + directory); 48 | return null; 49 | } else { 50 | const infoFileContents = await readFile(maybeInfoFilePath, {encoding: "utf8"}); 51 | const infoFileJSON = JSON.parse(infoFileContents); 52 | return { 53 | folder_hash: hash, 54 | key: "", 55 | song_title: infoFileJSON._songName || "Unknown", 56 | song_author: infoFileJSON._songAuthorName || "Unknown", 57 | uploader: infoFileJSON._levelAuthorName || "Unknown", 58 | disk_location: directory, 59 | cover_filename: infoFileJSON._coverImageFilename, 60 | song_filename: infoFileJSON._songFilename, 61 | added_at: new Date().toISOString(), 62 | }; 63 | } 64 | }) 65 | 66 | return Promise.all(mapped); 67 | } 68 | 69 | 70 | 71 | async function scanForNewSongs(rootDir, dbConnection) { 72 | const newSongTuples: Array<[string, string]> = await calcNewSongDirs(dbConnection, rootDir); 73 | const infoFiles: [string, string, Maybe][] = await mapInfoFilePaths(newSongTuples); 74 | const dbEntries: Maybe[] = await mapToDbEntries(infoFiles); 75 | const filtereEntries = dbEntries.filter(e => e !== null); 76 | return insertAllSongsWithTransaction(dbConnection, filtereEntries); 77 | } 78 | 79 | async function deleteMissingSongs(dbConnection) { 80 | const allSongLocations = (await getAllDiskLocations(dbConnection)).map(entry => entry.disk_location); 81 | 82 | const missingSongs = (await Promise.all(allSongLocations.map(async (directory) => { 83 | try { 84 | await access(directory, constants.R_OK | constants.W_OK); 85 | return null; 86 | } catch(e) { 87 | return directory; 88 | } 89 | }))).filter(entry => entry != null); 90 | 91 | await deleteSongsByFilesLocations(dbConnection, missingSongs); 92 | } 93 | 94 | function deleteSong(dbConnection, folder_hash) { 95 | return getSongByFolderHash(dbConnection, folder_hash) 96 | .then(async song => { 97 | const diskLocation = song.disk_location; 98 | await rm(diskLocation, {recursive: true, force: true}); 99 | return song; 100 | }) 101 | .then(() => { 102 | return deleteSongByFolderHash(dbConnection, folder_hash); 103 | }) 104 | .catch(err => { 105 | console.error(err); 106 | }); 107 | } 108 | 109 | async function syncSongLibrary (dbConnection) { 110 | const rootDir = await getBeatSaberDirectory(dbConnection); 111 | const songDir = path.join(rootDir, "Beat Saber_Data", "CustomLevels"); 112 | return Promise.all([ 113 | scanForNewSongs(songDir, dbConnection), 114 | deleteMissingSongs(dbConnection) 115 | ]); 116 | } 117 | 118 | export function register(mainWindow, dbConnection) { 119 | ipcMain.handle("syncSongLibrary", () => syncSongLibrary(dbConnection)); 120 | 121 | ipcMain.handle("getUploaders", () => getUploaders(dbConnection)); 122 | 123 | ipcMain.handle("getSongsByKey", (key) => getSongByKey(dbConnection, key)); 124 | 125 | ipcMain.handle("getSongByKey", (event, {key}) => getSongByKey(dbConnection, key)); 126 | 127 | ipcMain.handle("getAllSongs", () => getAllSongs(dbConnection)); 128 | 129 | ipcMain.handle("getSongsByUploader", (event, {uploader}) => getSongsByUploader(dbConnection, uploader)); 130 | 131 | ipcMain.handle("getArtists", (event) => getSongAuthors(dbConnection)); 132 | 133 | ipcMain.handle("getSongsByArtist", (event, {artist}) => getSongsByAuthor(dbConnection, artist)); 134 | 135 | ipcMain.handle("loadLibrary", () => getAllSongs(dbConnection)); 136 | 137 | ipcMain.handle("deleteSong", async (event, {folder_hash}) => deleteSong(dbConnection, folder_hash)); 138 | } 139 | -------------------------------------------------------------------------------- /src/main/previewing/previewManager.ts: -------------------------------------------------------------------------------- 1 | import { ipcMain } from "electron"; 2 | import { PREVIEW_BEATMAP, PREVIEW_LOADED, PREVIEW_ERROR } from "../../constants/channelNames"; 3 | import AdmZip from "adm-zip"; 4 | import { download } from "../utils"; 5 | 6 | export function register(mainWindow) { 7 | const sendStatusToWindow = (channel, payload) => { 8 | mainWindow.webContents.send(channel, payload); 9 | }; 10 | 11 | ipcMain.handle(PREVIEW_BEATMAP, (event, { beatmap }) => { 12 | download( 13 | beatmap.versions[0].downloadURL, 14 | () => {}, 15 | async (buffer) => { 16 | try { 17 | const zip = new AdmZip(buffer); 18 | 19 | let infoEntry = zip.getEntry("info.dat"); 20 | 21 | if (!infoEntry) { 22 | infoEntry = zip.getEntry("Info.dat"); 23 | } 24 | 25 | if (!infoEntry) { 26 | sendStatusToWindow(PREVIEW_ERROR, { beatmap, error: new Error("Could not find info.dat file.") }); 27 | } 28 | 29 | const infoJSON = JSON.parse(zip.readAsText(infoEntry)); 30 | 31 | const songFilename = infoJSON._songFilename; 32 | 33 | const audioFileEntry = zip.getEntry(songFilename); 34 | 35 | const audioBuffer = await new Promise((resolve, reject) => { 36 | audioFileEntry.getDataAsync((data) => { 37 | resolve(data); 38 | }); 39 | }); 40 | sendStatusToWindow(PREVIEW_LOADED, { buffer: audioBuffer, beatmap }); 41 | } catch (error) { 42 | console.log(error.message); 43 | sendStatusToWindow(PREVIEW_ERROR, { beatmap, error }); 44 | } 45 | }, 46 | (error) => { 47 | console.log(error.message); 48 | sendStatusToWindow(PREVIEW_ERROR, { beatmap, error }); 49 | } 50 | ); 51 | }); 52 | } 53 | 54 | // module.exports = { register }; 55 | -------------------------------------------------------------------------------- /src/main/settings/settingsManager.ts: -------------------------------------------------------------------------------- 1 | import {ipcMain, dialog} from "electron"; 2 | import {getSetting, setSetting, hasSetting} from "../db/queries/userSettings"; 3 | import { getBeatSaberDirectory } from "../utils"; 4 | import { CURRENT_THEME_NAME } from "../../constants/storageKeys"; 5 | 6 | function openFolderBrowser(startingDirectory) { 7 | return dialog.showOpenDialog( 8 | { 9 | title: "Select Beat Saber install directory", 10 | message: "Select the directory where Beat Saber is installed", 11 | defaultPath: startingDirectory, 12 | buttonLabel: "Choose folder", 13 | properties: ["openDirectory"] 14 | } 15 | ); 16 | } 17 | 18 | async function changeBeatSaberDirectory(dbConnection) { 19 | const currentDirectory = await getBeatSaberDirectory(dbConnection); 20 | const selection = await openFolderBrowser(currentDirectory); 21 | 22 | if (!selection.canceled) { 23 | const newDir = selection.filePaths[0]; 24 | await setSetting(dbConnection, "beatSaberDirectory", newDir); 25 | return newDir; 26 | } else { 27 | return currentDirectory; 28 | } 29 | } 30 | 31 | export async function register(mainWindow, dbConnection) { 32 | ipcMain.handle("hasSetting", (event, {settingKey}) => hasSetting(dbConnection, settingKey)); 33 | 34 | ipcMain.handle("getSetting", (event, {settingKey}) => getSetting(dbConnection, settingKey)); 35 | 36 | ipcMain.handle("setSetting", (event, {settingKey, settingValue}) => setSetting(dbConnection, settingKey, settingValue)); 37 | 38 | ipcMain.handle("getCurrentTheme", () => getSetting(dbConnection, CURRENT_THEME_NAME)); 39 | 40 | ipcMain.handle("setCurrentTheme", (event, { currentThemeName }) => setSetting(dbConnection, CURRENT_THEME_NAME, currentThemeName)); 41 | 42 | ipcMain.handle("changeBeatSaberDirectory", () => changeBeatSaberDirectory(dbConnection)); 43 | 44 | ipcMain.handle("getBeatSaberDirectory", () => getBeatSaberDirectory(dbConnection)); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/updating/autoUpdate.ts: -------------------------------------------------------------------------------- 1 | import log from "electron-log"; 2 | import { autoUpdater } from "electron-updater"; 3 | import { ipcMain } from "electron"; 4 | 5 | 6 | export function register(mainWindow) { 7 | autoUpdater.logger = log; 8 | 9 | const sendStatusToWindow = (channel, text) => { 10 | log.info(`${channel}: ${text}`); 11 | 12 | mainWindow.webContents.send(channel, text); 13 | }; 14 | 15 | autoUpdater.on("checking-for-update", () => { 16 | sendStatusToWindow("checkingForUpdate", "Checking for update..."); 17 | }); 18 | 19 | autoUpdater.on("update-available", info => { 20 | sendStatusToWindow("updateAvailable", "Update available."); 21 | }); 22 | 23 | autoUpdater.on("update-not-available", info => { 24 | sendStatusToWindow("updateNotAvailable", "Update not available."); 25 | }); 26 | 27 | autoUpdater.on("error", err => { 28 | sendStatusToWindow("updateError", "Error in auto-updater. " + err); 29 | }); 30 | 31 | autoUpdater.on("download-progress", progressObj => { 32 | let log_message = "Download speed: " + progressObj.bytesPerSecond; 33 | log_message = log_message + " - Downloaded " + progressObj.percent + "%"; 34 | log_message = 35 | log_message + 36 | " (" + 37 | progressObj.transferred + 38 | "/" + 39 | progressObj.total + 40 | ")"; 41 | sendStatusToWindow("updateProgress", log_message); 42 | }); 43 | 44 | autoUpdater.on("update-downloaded", info => { 45 | sendStatusToWindow("updateDownloaded", "Update downloaded"); 46 | }); 47 | 48 | ipcMain.handle("restartAndUpdate", () => { 49 | autoUpdater.quitAndInstall(true, true); 50 | }); 51 | 52 | return autoUpdater; 53 | } 54 | -------------------------------------------------------------------------------- /src/main/utils.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import { readdir } from "fs/promises"; 3 | import path from "path"; 4 | import request from "request"; 5 | import sanitize from "sanitize-filename"; 6 | import { getSetting } from "./db/queries/userSettings"; 7 | 8 | const DEFAULT_WINDOWS_STEAM_LOCATION = 9 | "C:/Program Files (x86)/Steam/steamapps/common/Beat Saber"; 10 | const DEFAULT_WINDOWS_OCULUS_LOCATION = 11 | "C:/Program Files/Oculus/Software/Software/hyperbolic-magnetism-beat-saber"; 12 | 13 | export function download(url, onProgress, onEnd, onErr = (err) => {}) { 14 | const options = { 15 | url, 16 | encoding: null, 17 | headers: { 18 | Accept: "application/zip", 19 | "Accept-Charset": "utf-8", 20 | "User-Agent": "beathub-client" 21 | } 22 | }; 23 | 24 | let totalBytes = 0; 25 | let bytesReceived = 0; 26 | 27 | const req = request.get(options, (err, resp, body) => { 28 | if (err) { 29 | onErr(err); 30 | return; 31 | } 32 | 33 | if (resp.statusCode !== 200) { 34 | onErr(new Error(`Status was ${resp.statusCode} for ${url}`)); 35 | return; 36 | } 37 | 38 | onEnd(body); 39 | }); 40 | 41 | req.on("response", data => { 42 | totalBytes = data.headers["content-length"]; 43 | }); 44 | 45 | req.on("data", chunk => { 46 | bytesReceived += chunk.length; 47 | onProgress(bytesReceived, totalBytes); 48 | }); 49 | 50 | return req; 51 | } 52 | 53 | export function formatFolderName(key, songName, levelAuthorName) { 54 | const formattedFolderName = `${key} (${songName} - ${levelAuthorName})`; 55 | return sanitize(formattedFolderName); 56 | } 57 | 58 | export async function getDirectoryNames (source) { 59 | return (await readdir(source, { withFileTypes: true })) 60 | .filter(direct => direct.isDirectory()) 61 | .map(direct => path.join(source, direct.name)); 62 | } 63 | 64 | export async function getFileNames (source) { 65 | const dirs = await readdir(source, {withFileTypes: true}); 66 | return dirs.filter(direct => direct.isFile()) 67 | .map(direct => path.join(source, direct.name)); 68 | } 69 | 70 | 71 | 72 | export function existsAsync(path) { 73 | return new Promise((resolve, reject) => { 74 | fs.exists(path, exists => { 75 | resolve(exists); 76 | }); 77 | }); 78 | } 79 | 80 | export async function getBeatSaberDirectory(dbConnection) { 81 | const beatSaberDirectory = await getSetting(dbConnection, "beatSaberDirectory"); 82 | 83 | if (beatSaberDirectory) { 84 | return beatSaberDirectory; 85 | } else { 86 | if (await existsAsync(DEFAULT_WINDOWS_OCULUS_LOCATION)) { 87 | return DEFAULT_WINDOWS_OCULUS_LOCATION; 88 | } else if (await existsAsync(DEFAULT_WINDOWS_STEAM_LOCATION)) { 89 | return DEFAULT_WINDOWS_STEAM_LOCATION; 90 | } 91 | return ""; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/preload.ts: -------------------------------------------------------------------------------- 1 | import { contextBridge, ipcRenderer } from 'electron'; 2 | 3 | contextBridge.exposeInMainWorld("api", { 4 | send: (channel, data) => { 5 | let validChannels = ["downloadBeatmap", "previewBeatmap"]; 6 | if (validChannels.includes(channel)) { 7 | ipcRenderer.send(channel, data); 8 | } else { 9 | throw new Error("Invalid channel for send"); 10 | } 11 | }, 12 | invoke: (channel, args) => { 13 | let validChannels = [ 14 | "changeBeatSaberDirectory", 15 | "restartAndUpdate", 16 | "getBeatSaberDirectory", 17 | "getAppVersion", 18 | "downloadBeatmap", 19 | "getCurrentTheme", 20 | "setCurrentTheme", 21 | "previewBeatmap", 22 | "loadLibrary", 23 | "deleteSong", 24 | "syncSongLibrary", 25 | "getAllSongs", 26 | "getUploaders", 27 | "getSongsByKey", 28 | "getSongByKey", 29 | "getSongsByUploader", 30 | "getArtists", 31 | "getSongsByArtist" 32 | ]; 33 | if (validChannels.includes(channel)) { 34 | return ipcRenderer.invoke(channel, args); 35 | } else { 36 | throw new Error("Invalid channel for invoke: " + channel); 37 | } 38 | }, 39 | receive: (channel, func) => { 40 | let validChannels = [ 41 | "downloadProgress", 42 | "downloadComplete", 43 | "downloadError", 44 | "updateDownloaded", 45 | "previewLoaded", 46 | "previewError" 47 | ]; 48 | if (validChannels.includes(channel)) { 49 | ipcRenderer.on(channel, (event, args) => func(args)); 50 | } else { 51 | throw new Error("Invalid channel for receive"); 52 | } 53 | } 54 | }); 55 | -------------------------------------------------------------------------------- /src/render/App.svelte: -------------------------------------------------------------------------------- 1 | 37 | 38 |
39 | 40 |
41 | 42 | 43 | 99 | 100 | 101 | 102 | 103 |
104 |
105 | 106 |
107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 167 | -------------------------------------------------------------------------------- /src/render/actions/tooltip.css: -------------------------------------------------------------------------------- 1 | .tooltip { 2 | position: absolute; 3 | color: var(--backgroundText); 4 | background-color: var(--tooltipBackgroundColor); 5 | box-shadow: 0 0 1px 1px var(--primary); 6 | border-radius: 8px; 7 | padding: 8px; 8 | width: 120px; 9 | text-align: center; 10 | transition: opacity .5s; 11 | transform: translate(5px, -50%); 12 | } 13 | 14 | .tooltip.left::after { 15 | content: ""; 16 | position: absolute; 17 | top: 50%; 18 | left: 100%; 19 | margin-top: -5px; 20 | border-width: 5px; 21 | border-style: solid; 22 | border-color: transparent transparent transparent var(--tooltipBackgroundColor) ; 23 | } 24 | 25 | .tooltip.right::after { 26 | content: ""; 27 | position: absolute; 28 | top: 50%; 29 | right: 100%; 30 | margin-top: -5px; 31 | border-width: 5px; 32 | border-style: solid; 33 | border-color: transparent var(--tooltipBackgroundColor) transparent transparent; 34 | } -------------------------------------------------------------------------------- /src/render/actions/tooltip.js: -------------------------------------------------------------------------------- 1 | import { listen } from "svelte/internal"; 2 | 3 | export function tooltip(node, { text, position = "right" }) { 4 | if (!text) return; 5 | const tooltip = document.createElement("div"); 6 | const linkEl = document.createElement('link'); 7 | linkEl.type = 'text/css'; 8 | linkEl.rel = 'stylesheet'; 9 | linkEl.href = './tooltip.css'; 10 | tooltip.textContent = text; 11 | tooltip.className = "tooltip"; 12 | 13 | tooltip.classList.add(`${position}`); 14 | 15 | function positionTooltip() { 16 | const { top, right, bottom, left, width } = node.getBoundingClientRect(); 17 | tooltip.style.top = `${(top + bottom) / 2}px`; 18 | switch (position) { 19 | case "right": { 20 | tooltip.style.left = `${right}px`; 21 | break; 22 | } 23 | case "left": { 24 | tooltip.style.left = `${left - 8}px`; 25 | break; 26 | } 27 | } 28 | } 29 | 30 | function append() { 31 | document.body.appendChild(tooltip); 32 | tooltip.prepend(linkEl); 33 | tooltip.style.opacity = "0"; 34 | setTimeout(() => (tooltip.style.opacity = "1")); 35 | positionTooltip(); 36 | } 37 | 38 | function remove() { 39 | tooltip.remove(); 40 | } 41 | 42 | const cancelMouseenter = listen(node, "mouseenter", append); 43 | const cancelMouseleave = listen(node, "mouseleave", remove); 44 | 45 | return { 46 | destroy() { 47 | remove(); 48 | cancelMouseenter(); 49 | cancelMouseleave(); 50 | }, 51 | 52 | update({ text, position }) { 53 | tooltip.textContent = text; 54 | }, 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /src/render/components/AudioPlayer.svelte: -------------------------------------------------------------------------------- 1 | 56 | 57 |