Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FateNotAvailable committed Mar 28, 2024
1 parent d42be62 commit aeb96a0
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions database/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Database {
}

set(key, value) {
console.log(`Setting ${key} to ${value}`);
const rawData = fs.readFileSync(this.db_folder, 'utf-8');
const jsonData = JSON.parse(rawData);
jsonData[key] = value;
Expand All @@ -22,6 +23,7 @@ class Database {
}

get(key) {
console.log(`Getting ${key}`);
const rawData = fs.readFileSync(this.db_folder, 'utf-8');
const jsonData = JSON.parse(rawData);
const value = jsonData[key];
Expand Down
19 changes: 18 additions & 1 deletion games/Valorant.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,32 @@ class Valorant {
constructor() {
this.db = new Database();
this.game_path = this.db.get("valorant_path");
this.movies_folder = path.join(this.game_path, "live", "ShooterGame", "Content", "Movies", "Menu");
if (!!this.game_path){
this.movies_folder = path.join(this.game_path, "live", "ShooterGame", "Content", "Movies", "Menu");
}
}

setBackground(video_path) {
// Check if movies folder is set
if (!this.movies_folder) {return};

// Check if video exists
if (!fs.existsSync(video_path)) {return};

// If key does not exist in database, create it
if (!this.db.get("valorant_selected_video_path")) {
this.db.set("valorant_selected_video_path", "");
this.db.set("valorant_selected_video_hash", "");
}

// If path is set, but video was deleted remove it from database
if (!!this.db.get("valorant_selected_video_path") && !fs.existsSync(this.db.get("valorant_selected_video_path"))) {
this.db.set("valorant_selected_video_path", "");
this.db.set("valorant_selected_video_hash", "");
return;
}

// Check if movie folder exists
if (!fs.existsSync(this.movies_folder)) {
return;
}
Expand All @@ -28,6 +43,8 @@ class Valorant {

const filtered_files = files.filter(item => item.endsWith("mp4"));


// Replace all videos (mp4) in set folder
filtered_files.forEach(file => {
try {
fs.unlinkSync(path.join(this.movies_folder, file));
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<div class="list">
<input id="video_url" type="text" placeholder="MP4 Link">
<button id="download_btn" onclick="download_file();" class="green">Download</button>
<button onclick="window.bgEngine.openExplorer()">Open in file explorer</button>
<button onclick="addOwnDialog.style.display='none'">Close</button>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const grid_container = document.getElementsByClassName("grid-container")[0];

if (!window.bgEngine.getValorantPath()) {
location = "settings.html";
}

window.bgEngine.getBackgrounds()
.then((backgrounds) => {
if (!backgrounds) {
Expand Down
9 changes: 9 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,21 @@ ipcMain.handle('getDatabase', (event, key) => {
return db.get(key);
});

ipcMain.handle('getValorantPath', (event, key) => {
let db = new Database();
return db.get("valorant_path") || ""
});

ipcMain.handle('downloadFile', (event, url) => {
let dwn = new Downloader();
dwn.download(url);
return true;
});

ipcMain.handle('openExplorer', (event) => {
require("electron").shell.openPath(videosFolder());
});

ipcMain.handle('setGameBackground', (event, game, video_path) => {
if (game == 'valorant') {
let valorant = new Valorant();
Expand Down
8 changes: 8 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ contextBridge.exposeInMainWorld('bgEngine', {
}
},

getValorantPath: () => {
return ipcRenderer.invoke('getValorantPath');
},

getBackgroundEngineFolder: () => {
return ipcRenderer.invoke('backgroundEngineFolder');
},
Expand Down Expand Up @@ -40,5 +44,9 @@ contextBridge.exposeInMainWorld('bgEngine', {

downloadFile: (url) => {
return ipcRenderer.invoke('downloadFile', url);
},

openExplorer: () => {
return ipcRenderer.invoke('openExplorer');
}
});
Binary file modified resources/icon/icon.ico
Binary file not shown.
Binary file modified resources/icon/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


<div class="container">
<input type="text" class="input-field" id="valorant_folder" placeholder="Valorant Path">
<input type="text" class="input-field" id="valorant_folder" placeholder="Valorant Path (etc.: C:\Riot Games\VALORANT)">
<button class="save-button" id="valorant_folder_save">Save</button>
</div>

Expand Down

0 comments on commit aeb96a0

Please sign in to comment.