mirror of
https://github.com/Gabi-Zar/Silk-Fly-Launcher.git
synced 2026-04-17 05:26:04 +02:00
add auto path detection
This commit is contained in:
14
main.js
14
main.js
@@ -1,6 +1,7 @@
|
|||||||
const { app, BrowserWindow , ipcMain} = require('electron/main');
|
const { app, BrowserWindow , ipcMain} = require('electron/main');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const Store = require('electron-store').default;
|
const Store = require('electron-store').default;
|
||||||
|
const fs = require('fs/promises');
|
||||||
|
|
||||||
const store = new Store();
|
const store = new Store();
|
||||||
|
|
||||||
@@ -38,4 +39,17 @@ ipcMain.handle('save-path', (event, path) => {
|
|||||||
|
|
||||||
ipcMain.handle('load-path', () => {
|
ipcMain.handle('load-path', () => {
|
||||||
return store.get('silksong-path');
|
return store.get('silksong-path');
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fileExists(filePath) {
|
||||||
|
try {
|
||||||
|
await fs.access(filePath);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMain.handle('file-exists', async (_, filePath) => {
|
||||||
|
return await fileExists(filePath);
|
||||||
});
|
});
|
||||||
@@ -11,4 +11,8 @@ contextBridge.exposeInMainWorld('save', {
|
|||||||
ipcRenderer.invoke('save-path', path),
|
ipcRenderer.invoke('save-path', path),
|
||||||
loadSilksongPath: () =>
|
loadSilksongPath: () =>
|
||||||
ipcRenderer.invoke('load-path')
|
ipcRenderer.invoke('load-path')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('files', {
|
||||||
|
fileExists: (path) => ipcRenderer.invoke('file-exists', path)
|
||||||
|
});
|
||||||
@@ -83,7 +83,7 @@
|
|||||||
<template id="settings-template">
|
<template id="settings-template">
|
||||||
<h2>General settings</h2>
|
<h2>General settings</h2>
|
||||||
<label for="silksong-path-label">Enter Silksong path: </label>
|
<label for="silksong-path-label">Enter Silksong path: </label>
|
||||||
<input type="text" id="silksong-path-input" name="silksong-path-input">
|
<input type="text" id="silksong-path-input" name="silksong-path-input"> <button class="default-button">Auto Dectect</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="renderer.js"></script>
|
<script src="renderer.js"></script>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const settingsTemplate = document.getElementById("settings-template");
|
|||||||
const versionText = HomeTemplate.content.getElementById("version-text")
|
const versionText = HomeTemplate.content.getElementById("version-text")
|
||||||
|
|
||||||
navigate("home")
|
navigate("home")
|
||||||
|
autoDetectGamePath()
|
||||||
|
|
||||||
async function navigate(page) {
|
async function navigate(page) {
|
||||||
view.replaceChildren()
|
view.replaceChildren()
|
||||||
@@ -37,13 +38,11 @@ async function navigate(page) {
|
|||||||
const settingsTemplateCopy = settingsTemplate.content.cloneNode(true)
|
const settingsTemplateCopy = settingsTemplate.content.cloneNode(true)
|
||||||
const silksongPathInput = settingsTemplateCopy.getElementById("silksong-path-input")
|
const silksongPathInput = settingsTemplateCopy.getElementById("silksong-path-input")
|
||||||
|
|
||||||
silksongPathInput.value = await window.save.loadSilksongPath()
|
silksongPathInput.value = await save.loadSilksongPath()
|
||||||
|
|
||||||
silksongPathInput.addEventListener('input', async function(event) {
|
silksongPathInput.addEventListener('input', async function(event) {
|
||||||
let silksongPath = silksongPathInput.value
|
let silksongPath = silksongPathInput.value
|
||||||
console.log(silksongPath)
|
await save.saveSilksongPath(silksongPath)
|
||||||
await window.save.saveSilksongPath(silksongPath)
|
|
||||||
console.log(await window.save.loadSilksongPath())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
view.appendChild(settingsTemplateCopy)
|
view.appendChild(settingsTemplateCopy)
|
||||||
@@ -52,4 +51,11 @@ async function navigate(page) {
|
|||||||
|
|
||||||
function launch(mode) {
|
function launch(mode) {
|
||||||
alert(`Launching the game in ${mode} mode.`);
|
alert(`Launching the game in ${mode} mode.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function autoDetectGamePath() {
|
||||||
|
const defaultSilksongPath = "C:/Program Files (x86)/Steam/steamapps/common/Hollow Knight Silksong/Hollow Knight Silksong.exe"
|
||||||
|
if (files.fileExists(defaultSilksongPath)) {
|
||||||
|
await save.saveSilksongPath(defaultSilksongPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -133,4 +133,12 @@ body {
|
|||||||
|
|
||||||
input[type="range"] {
|
input[type="range"] {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.default-button {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
.default-button:hover {
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user