Skip to content

Commit

Permalink
Hopefully fixed app not starting correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ManeraKai committed May 20, 2023
1 parent d0b2095 commit 13db071
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 29 deletions.
15 changes: 12 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libredirect_frontends_manager",
"private": true,
"version": "0.0.8",
"version": "0.0.9",
"type": "module",
"scripts": {
"tauri": "tauri"
Expand All @@ -10,6 +10,7 @@
"@tauri-apps/cli": "^1.3.1"
},
"dependencies": {
"@tauri-apps/api": "^1.3.0"
"@tauri-apps/api": "^1.3.0",
"@tauri-apps/plugin-fs-watch": "github:tauri-apps/tauri-plugin-fs-watch#v1"
}
}
108 changes: 107 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libredirect_frontends_manager"
version = "0.0.8"
version = "0.0.9"
description = "Host privacy frontends locally on your computer rather than relying on 3rd party instances"
authors = ["you"]
license = ""
Expand All @@ -17,6 +17,7 @@ tauri = { version = "1.3", features = ["dialog-all", "fs-all", "http-all", "os-a
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
signal-hook = "0.3.15"
tauri-plugin-fs-watch = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tauri::{

fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_fs_watch::init())
.system_tray(
SystemTray::new().with_menu(
SystemTrayMenu::new()
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Libredirect Frontends Manager",
"version": "0.0.8"
"version": "0.0.9"
},
"tauri": {
"allowlist": {
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ let frontends_running = {};
const platform = await window.__TAURI__.os.platform()
const config = JSON.parse(await fs.readTextFile(await path.resolveResource('frontends.json')))
let isDockerInstalled = await docker_frontends.health()
const caddy_donloading = new Twindow.WebviewWindow('refreshWindow', { url: 'message.html#Downloading Caddy', height: 200, width: 400, center: true });
await binary_frontends.run_caddy()
await binary_frontends.download_stdin_parser()
caddy_donloading.close()
if (isDockerInstalled == 'running') {
await docker_frontends.download_frontend('redis')
await docker_frontends.run_frontend('redis')
Expand Down Expand Up @@ -243,7 +241,10 @@ async function quitApp() {
}

async function refreshApp() {
const webview = new Twindow.WebviewWindow('refreshWindow', { url: 'message.html#Refreshing', height: 200, width: 400, center: true, title: 'Refreshing' });
const webview = new Twindow.WebviewWindow(
'refreshWindow',
{ url: 'message.html#Refreshing', height: 200, width: 400, center: true, title: 'Refreshing' }
);
await binary_frontends.stop_all()
await docker_frontends.stop_all()
await webview.close()
Expand Down
13 changes: 5 additions & 8 deletions src/services/binary_frontends.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Twindow = window.__TAURI__.window
const shell = window.__TAURI__.shell;
const path = window.__TAURI__.path;
const fs = window.__TAURI__.fs;
const http = window.__TAURI__.http
const http = window.__TAURI__.http;
import { watch } from "tauri-plugin-fs-watch-api";

Object.values = function (obj) {
return Object.keys(obj).map(key => obj[key])
Expand Down Expand Up @@ -29,6 +31,7 @@ async function run_caddy() {
platform = await window.__TAURI__.os.platform()
const result = await check_downloaded('caddy')
if (result == 'not_downloaded') {
const caddy_donloading = new Twindow.WebviewWindow('refreshWindow', { url: 'message.html#Downloading Caddy', height: 200, width: 400, center: true });
let filename
let url
if (platform == 'linux') {
Expand All @@ -45,6 +48,7 @@ async function run_caddy() {
if (platform == 'linux') {
await new shell.Command('chmod', ['u+x', filename], { cwd: await path.appLocalDataDir() }).execute();
}
caddy_donloading.close()
}
let command
if (platform == 'win32') {
Expand Down Expand Up @@ -81,13 +85,6 @@ async function download_stdin_parser() {
await fs.copyFile(_path, await path.join(await path.homeDir(), '.mozilla', 'native-messaging-hosts', 'org.libredirect.stdin_parser.json'), { dir: fs.BaseDirectory.AppLocalData })
}
}
(async () => {
while (true) {
const data = await fs.readTextFile(await path.join('stdin_parser', 'settings.json'), { dir: fs.BaseDirectory.AppLocalData })
console.log(JSON.parse(data))
await new Promise(resolve => setTimeout(async () => resolve(), 1000))
}
})()
}

async function run_frontend(name) {
Expand Down
24 changes: 14 additions & 10 deletions src/services/docker_frontends.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,21 @@ async function remove_frontend(name) {

function health() {
return new Promise(async resolve => {
const cmd = new shell.Command('docker', ['compose', 'version'])
cmd.on('error', () => resolve('not_installed'));
cmd.stderr.on('data', () => resolve('not_installed'))
cmd.stdout.on('data', async () => {
const cmd = new shell.Command('docker', ['ps'])
cmd.on('error', () => resolve('not_running'));
cmd.stdout.on('data', () => resolve('running'))
cmd.stderr.on('data', () => resolve('not_running'))
try {
const cmd = new shell.Command('docker', ['compose', 'version'])
cmd.on('error', () => resolve('not_installed'));
cmd.stderr.on('data', () => resolve('not_installed'))
cmd.stdout.on('data', async () => {
const cmd = new shell.Command('docker', ['ps'])
cmd.on('error', () => resolve('not_running'));
cmd.stdout.on('data', () => resolve('running'))
cmd.stderr.on('data', () => resolve('not_running'))
await cmd.spawn();
})
await cmd.spawn();
})
await cmd.spawn();
} catch (error) {
resolve('not_installed')
}
})
}

Expand Down

0 comments on commit 13db071

Please sign in to comment.