feat: add server settings (toggle on/off, port selection, start on system start) to Settings UI and backend
This commit is contained in:
@@ -157,6 +157,25 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
int port = 18081;
|
||||
char cfg_path[2048];
|
||||
snprintf(cfg_path, sizeof(cfg_path), "%s/.config/pubscript/server.json", home);
|
||||
FILE *cfg_fp = fopen(cfg_path, "r");
|
||||
if (cfg_fp) {
|
||||
char buf[1024];
|
||||
size_t n = fread(buf, 1, sizeof(buf) - 1, cfg_fp);
|
||||
buf[n] = '\0';
|
||||
fclose(cfg_fp);
|
||||
const char *port_key = strstr(buf, "\"port\"");
|
||||
if (port_key) {
|
||||
const char *colon = strchr(port_key, ':');
|
||||
if (colon) {
|
||||
int cfg_port = atoi(colon + 1);
|
||||
if (cfg_port >= 1024 && cfg_port <= 65535) {
|
||||
port = cfg_port;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const char *env_port = getenv("PUBSCRIPT_DESKTOP_PORT");
|
||||
if (env_port && *env_port) {
|
||||
int p = atoi(env_port);
|
||||
|
||||
Reference in New Issue
Block a user