Skip to content

Commit

Permalink
Merge pull request #48 from AstroDogeDX/added-config-management
Browse files Browse the repository at this point in the history
Implemented an exposed config managing to the frontend
  • Loading branch information
AstroDogeDX authored Oct 15, 2023
2 parents c4251c2 + 5afa330 commit 160b4bd
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 191 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"comma-dangle": ["error", "always-multiline"],
"dot-notation": "error",
"eqeqeq": "error",
"no-alert": "error"
"no-alert": "error",
"indent": ["error", 4, { "SwitchCase": 1 }]
}
}
36 changes: 18 additions & 18 deletions server/api_cvr_ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@ const MAP_WORLD = Object.freeze({
});

const MAP_INVITE = Object.freeze({
'Id': 'id',
'User': {
root: 'user',
mapping: MAP_USER,
},
'World': {
root: 'world',
mapping: MAP_WORLD,
},
'InstanceId': 'instanceId',
'InstanceName': 'instanceName',
'ReceiverId': 'receiverId',
'Id': 'id',
'User': {
root: 'user',
mapping: MAP_USER,
},
'World': {
root: 'world',
mapping: MAP_WORLD,
},
'InstanceId': 'instanceId',
'InstanceName': 'instanceName',
'ReceiverId': 'receiverId',
});

const MAP_REQUEST_INVITE = Object.freeze({
'Id': 'id',
'Sender': {
root: 'sender',
mapping: MAP_USER,
},
'ReceiverId': 'receiverId',
'Id': 'id',
'Sender': {
root: 'sender',
mapping: MAP_USER,
},
'ReceiverId': 'receiverId',
});


Expand Down
43 changes: 41 additions & 2 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const CVRExecutableName = 'ChilloutVR.exe';
const CVRDataFolderName = 'ChilloutVR_Data';

const FileType = Object.freeze({
CONFIG: 'CONFIG',
CREDENTIALS: 'CREDENTIALS',
CONFIG: 'CONFIG',
CREDENTIALS: 'CREDENTIALS',
});


Expand Down Expand Up @@ -59,6 +59,7 @@ exports.Load = async () => {
ActiveUsername: null,
ActiveUserID: null,
CacheMaxSizeInMegabytes: 1000,
CloseToSystemTray: false,
CVRExecutable: path.join(CVRExecutableDefaultFolderPath, CVRExecutableName),
UpdaterIgnoreVersion: null,
};
Expand Down Expand Up @@ -240,8 +241,46 @@ exports.ClearCredentials = async (username) => {
await UpdateJsonFile(FileType.CREDENTIALS);
};

exports.UpdateConfig = async (newConfigSettings) => {

log.info('[UpdateConfig] Attempting to update the config', newConfigSettings);

if (Object.prototype.hasOwnProperty.call(newConfigSettings, 'CacheMaxSizeInMegabytes')) {
const cacheSize = newConfigSettings.CacheMaxSizeInMegabytes;

if (!Number.isInteger(cacheSize) || cacheSize < 500 || cacheSize > 2000) {
throw new Error('[UpdateConfig] CacheMaxSizeInMegabytes should be an integer between 500 and 2000.');
}

config.CacheMaxSizeInMegabytes = cacheSize;
}

if (Object.prototype.hasOwnProperty.call(newConfigSettings, 'CloseToSystemTray')) {
const closeToTray = newConfigSettings.CloseToSystemTray;

if (typeof closeToTray !== 'boolean') {
throw new Error('[UpdateConfig] CloseToSystemTray should be a boolean value.');
}

config.CloseToSystemTray = closeToTray;
}

await UpdateJsonFile(FileType.CONFIG);

return exports.GetConfig();
};


exports.GetConfig = () => ({
CacheMaxSizeInMegabytes: config.CacheMaxSizeInMegabytes,
CloseToSystemTray: config.CloseToSystemTray,
});


exports.GetMaxCacheSize = () => config.CacheMaxSizeInMegabytes;

exports.GetCloseToSystemTray = () => config.CloseToSystemTray;

exports.GetUpdaterIgnoreVersion = () => config.UpdaterIgnoreVersion;
exports.SetUpdaterIgnoreVersion = async (versionToIgnore) => {
config.UpdaterIgnoreVersion = versionToIgnore;
Expand Down
24 changes: 14 additions & 10 deletions server/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class Core {
ipcMain.handle('block-user', (_event, userId) => CVRWebsocket.BlockUser(userId));
ipcMain.handle('unblock-user', (_event, userId) => CVRWebsocket.UnblockUser(userId));

// Config
ipcMain.handle('config-get', () => Config.GetConfig());
ipcMain.handle('config-update', (_event, newConfigSettings) => Config.UpdateConfig(newConfigSettings));

// Socket Events
CVRWebsocket.EventEmitter.on(CVRWebsocket.SocketEvents.CONNECTED, () => this.recentActivityInitialFriends = true);
CVRWebsocket.EventEmitter.on(CVRWebsocket.SocketEvents.DEAD, () => this.SendToRenderer('socket-died'));
Expand Down Expand Up @@ -329,16 +333,16 @@ class Core {
await Config.ClearActiveCredentials();
this.app.quit();
}
// const authentication = {
// username: 'XXXXXXXXX',
// accessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// userId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentAvatar: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentHomeWorld: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// videoUrlResolverExecutable: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe',
// videoUrlResolverHashes: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/SHA2-256SUMS',
// blockedUsers: [],
// }
// const authentication = {
// username: 'XXXXXXXXX',
// accessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
// userId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentAvatar: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// currentHomeWorld: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
// videoUrlResolverExecutable: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe',
// videoUrlResolverHashes: 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/SHA2-256SUMS',
// blockedUsers: [],
// }
}

async SendToLoginPage() {
Expand Down
Loading

0 comments on commit 160b4bd

Please sign in to comment.