Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Vleerapp/Vleer
Browse files Browse the repository at this point in the history
  • Loading branch information
0PandaDEV committed May 7, 2024
2 parents cc6d647 + 0914a57 commit 586d632
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 23 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ jobs:
with:
name: windows-build-exe
path: src-tauri/target/release/bundle/nsis/*.exe
- uses: actions/upload-artifact@v3
if: matrix.platform == 'windows-latest'
with:
name: windows-build-msi
path: src-tauri/target/release/bundle/msi/*.msi

- name: Publish Ubuntu Artifacts
if: matrix.platform == 'ubuntu-latest'
Expand All @@ -68,4 +73,4 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
with:
name: ubuntu-build-rpm
path: src-tauri/target/release/bundle/rpm/*.rpm
path: src-tauri/target/release/bundle/rpm/*.rpm
22 changes: 5 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
MIT License
Creative Commons Attribution-NonCommercial-ShareAlike (CC BY-NC-SA) License with Additional Clause:

Copyright (c) 2024 Vleer
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
In addition to the CC BY-NC-SA license terms, any derivative works based on this project must be contributed back to the original project and cannot be distributed as separate projects. All contributors must agree to this condition when making modifications to the original work.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Appropriate credit — If supplied, you must provide the name of the creator and attribution parties, a copyright notice, a license notice, a disclaimer notice, and a link to the material. CC licenses prior to Version 4.0 also require you to provide the title of the material if supplied, and may have other slight differences.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
For more details about the CC BY-NC-SA license, please visit: https://creativecommons.org/licenses/by-nc-sa/4.0/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,20 @@
This is a full rewrite of Vleer with the same stack but cleaned up. And with proper rust implementations.

![Alt](https://repobeats.axiom.co/api/embed/476c97ad30ff96e3217cf756e84c292836b8f44e.svg "Repobeats analytics image")

***

For signing on macOS builds:
```zsh
codesign -s - --force --deep --timestamp --options runtime src-tauri/target/release/bundle/macos/Vleer.app
```
or
```zsh
cargo tauri build
cd target/release/bundle/dmg/
hdiutil attach -nobrowse -mountpoint /Volumes/vleer ./Vleer*.dmg
cp -R /Volumes/vleer .
hdiutil detach /Volumes/vleer
codesign -s - ./vleer/Vleer.app/Contents/MacOS/vleer
hdiutil create -format UDZO -srcfolder ./vleer Vleer-signed.dmg
```
3 changes: 2 additions & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ window.addEventListener('error', (e) => {
}
}, true);
const { $music } = useNuxtApp();
const { $music, $settings } = useNuxtApp();
await $music.init();
Expand All @@ -43,6 +43,7 @@ onMounted(async () => {
document.addEventListener('keydown', handleKeyDown);
document.addEventListener('focusin', updateFocus);
document.addEventListener('focusout', updateFocus);
await $settings.searchApiURL()
});
onUnmounted(() => {
Expand Down
6 changes: 4 additions & 2 deletions pages/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { invoke } from '@tauri-apps/api/core';
import { BaseDirectory, writeFile } from '@tauri-apps/plugin-fs';
import axios from 'axios';
import type { MusicSearchResponseItem, MusicSearchResponse, Song } from '~/types/types';
const { $music } = useNuxtApp();
const { $music, $settings } = useNuxtApp();
const searchTerm = ref("");
const searchResults = ref<MusicSearchResponseItem[]>([]);
Expand All @@ -39,8 +39,10 @@ async function searchSongs() {
return;
}
const apiURL = $settings.getApiURL()
try {
const response = await fetch(`https://pipedapi.wireway.ch/search?q=${searchTerm.value}&filter=music_songs`);
const response = await fetch(`${apiURL}/search?q=${searchTerm.value}&filter=music_songs`);
const data = await response.json();
searchResults.value = data.items
.filter(item => item.type !== 'channel')
Expand Down
23 changes: 23 additions & 0 deletions plugins/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re from "~/dist/_nuxt/BJ90lMuY";
import { useSettingsStore } from "~/stores/settings";
import type { EQSettings } from "~/types/types";

Expand Down Expand Up @@ -34,6 +35,28 @@ export default defineNuxtPlugin(async (nuxtApp) => {
store.settings.playerSettings.currentSong = song;
store.saveSettings();
},
setApiURL(url: string) {
store.settings.apiURL = url;
store.saveSettings();
},
getApiURL() {
return store.settings.apiURL;
},
async searchApiURL() {
try {
const response = await fetch('https://piped-instances.kavin.rocks/');
const instances = await response.json();
const urls = instances.map((instance: { api_url: string }) => instance.api_url);

const results = await window.__TAURI__.core.invoke('ping_urls', { urls });
console.log(results[0][0]);
this.setApiURL(results[0][0])
return results;
} catch (error) {
console.error('Failed to fetch API URLs:', error);
return [];
}
}
};

return {
Expand Down
42 changes: 41 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use anyhow::{anyhow, Result};
use tokio::io::AsyncWriteExt;
use std::path::PathBuf;
use tauri::Error as TauriError;
use reqwest::Client;
use tokio::time::Instant;

mod discord_rpc;

Expand Down Expand Up @@ -62,6 +64,43 @@ async fn download(url: String) -> Result<(), TauriError> {
Ok(())
}

#[tauri::command]
async fn ping_urls(urls: Vec<String>) -> Result<Vec<(String, u128)>, TauriError> {
let client = Client::new();
let results = ping_urls_helper(&client, &urls).await?;
Ok(results)
}

async fn ping_urls_helper(client: &Client, urls: &[String]) -> Result<Vec<(String, u128)>, TauriError> {
let mut handles = vec![];

for url in urls.iter() {
let url_clone = url.clone();
let client_clone = client.clone();

let handle = tokio::spawn(async move {
let start = Instant::now();
let result = client_clone.head(&url_clone).send().await;
let latency = start.elapsed().as_millis();
match result {
Ok(_) => (url_clone, latency), // Use the cloned URL here
Err(_) => (url_clone, u128::MAX), // Use the cloned URL here
}
});
handles.push(handle);
}

let mut results = Vec::new();
for handle in handles {
if let Ok(result) = handle.await {
results.push(result);
}
}

results.sort_by(|a, b| a.1.cmp(&b.1));
Ok(results)
}

fn main() {
env_logger::init();
let _ = discord_rpc::connect_rpc();
Expand All @@ -74,7 +113,8 @@ fn main() {
.invoke_handler(tauri::generate_handler![
discord_rpc::update_activity,
discord_rpc::clear_activity,
download
download,
ping_urls
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
4 changes: 3 additions & 1 deletion stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useSettingsStore = defineStore("settingsStore", {
"16000": "0.0",
},
},
apiURL: ""
}
}),
actions: {
Expand All @@ -45,7 +46,7 @@ export const useSettingsStore = defineStore("settingsStore", {
}
},
async getSettings(): Promise<PlayerSettings> {
if (this.init) return this.settings.playerSettings
if (this.init) return this.settings.playerSettings;

await this.checkForDefaultFiles();

Expand All @@ -54,6 +55,7 @@ export const useSettingsStore = defineStore("settingsStore", {
) as UserSettings;

this.settings.playerSettings = settings.playerSettings;
this.settings.apiURL = settings.apiURL;

this.init = true;

Expand Down
2 changes: 2 additions & 0 deletions types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface PlayerSettings {

export interface UserSettings {
playerSettings: PlayerSettings;
apiURL: string;
}

export const defaultSettings: UserSettings = {
Expand All @@ -101,4 +102,5 @@ export const defaultSettings: UserSettings = {
"16000": "0.0",
},
},
apiURL: "",
};

0 comments on commit 586d632

Please sign in to comment.