write to log file
This commit is contained in:
parent
e00685edcd
commit
3fbb8eb237
4 changed files with 41 additions and 36 deletions
|
@ -32,7 +32,7 @@ Configured in XML and themed using CSS, it is easy to customize and provides all
|
||||||
- [Something isn't styled correctly!](#something-isnt-styled-correctly)
|
- [Something isn't styled correctly!](#something-isnt-styled-correctly)
|
||||||
|
|
||||||
|
|
||||||
## How to install Eww
|
## How to install Eww
|
||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
|
@ -112,12 +112,12 @@ You can then reference it in your widgets by doing:
|
||||||
|
|
||||||
To change the value of the variable, and thus change the UI, you can run `eww update banana "I like apples"`
|
To change the value of the variable, and thus change the UI, you can run `eww update banana "I like apples"`
|
||||||
|
|
||||||
#### The `<script-var>` tag
|
#### The `<script-var>` tag
|
||||||
|
|
||||||
Allows you to create a script that eww runs.
|
Allows you to create a script that eww runs.
|
||||||
Useful for creating volume sliders or anything similar.
|
Useful for creating volume sliders or anything similar.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```xml
|
```xml
|
||||||
<variables>
|
<variables>
|
||||||
<script-var name="date" interval="5s">
|
<script-var name="date" interval="5s">
|
||||||
|
@ -135,12 +135,12 @@ and then reference it by doing:
|
||||||
|
|
||||||
The `interval="5s"` part says how long time it should take before Eww runs the command again.
|
The `interval="5s"` part says how long time it should take before Eww runs the command again.
|
||||||
Here are the available times you can set:
|
Here are the available times you can set:
|
||||||
| Shortened | Full name |
|
| Shortened | Full name |
|
||||||
| :------------- | :----------:|
|
| :------------- | :----------:|
|
||||||
| ms | Miliseconds |
|
| ms | Miliseconds |
|
||||||
| s | Seconds |
|
| s | Seconds |
|
||||||
| m | Minutes |
|
| m | Minutes |
|
||||||
| h | Hours |
|
| h | Hours |
|
||||||
|
|
||||||
#### Tail
|
#### Tail
|
||||||
If you don't want a set interval and instead want it to tail (run the script when it detects a change is present) you can simply remove the `interval="5s"` so it becomes:
|
If you don't want a set interval and instead want it to tail (run the script when it detects a change is present) you can simply remove the `interval="5s"` so it becomes:
|
||||||
|
@ -189,8 +189,8 @@ This part:
|
||||||
</box>
|
</box>
|
||||||
</def>
|
</def>
|
||||||
```
|
```
|
||||||
Is the custom widget. As we can see by the
|
Is the custom widget. As we can see by the
|
||||||
```xml
|
```xml
|
||||||
<def name="clock">
|
<def name="clock">
|
||||||
```
|
```
|
||||||
the widget is called `clock.`Or referenced `<clock>`
|
the widget is called `clock.`Or referenced `<clock>`
|
||||||
|
@ -204,7 +204,7 @@ So if we look at:
|
||||||
</box>
|
</box>
|
||||||
</def>
|
</def>
|
||||||
```
|
```
|
||||||
we can see that we assign `{{my_time}}` to be `{{date}}` and if we look at
|
we can see that we assign `{{my_time}}` to be `{{date}}` and if we look at
|
||||||
```xml
|
```xml
|
||||||
<script-var name="date">
|
<script-var name="date">
|
||||||
date
|
date
|
||||||
|
@ -309,7 +309,7 @@ we will see that eww will run `<def name="main">` and not `<def name="clock">`.
|
||||||
|
|
||||||
### Widgets made in Eww
|
### Widgets made in Eww
|
||||||
|
|
||||||
 
|
 
|
||||||
|
|
||||||
|
|
||||||
## GTK
|
## GTK
|
||||||
|
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
53
src/main.rs
53
src/main.rs
|
@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
os::unix::net,
|
os::unix::{io::AsRawFd, net},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
@ -57,6 +57,11 @@ lazy_static::lazy_static! {
|
||||||
.map(|v| PathBuf::from(v))
|
.map(|v| PathBuf::from(v))
|
||||||
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".config"))
|
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".config"))
|
||||||
.join("eww");
|
.join("eww");
|
||||||
|
|
||||||
|
static ref LOG_FILE: std::path::PathBuf = std::env::var("XDG_CACHE_HOME")
|
||||||
|
.map(|v| PathBuf::from(v))
|
||||||
|
.unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache"))
|
||||||
|
.join("eww.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -257,40 +262,40 @@ fn run_filewatch_thread<P: AsRef<Path>>(
|
||||||
Ok(hotwatch)
|
Ok(hotwatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// detach the process from the terminal, also closing stdout and redirecting
|
/// detach the process from the terminal, also redirecting stdout and stderr to
|
||||||
/// stderr into /dev/null
|
/// LOG_FILE
|
||||||
fn do_detach() {
|
fn do_detach() {
|
||||||
// detach from terminal
|
// detach from terminal
|
||||||
let pid = unsafe { libc::fork() };
|
let pid = unsafe { libc::fork() };
|
||||||
if dbg!(pid) < 0 {
|
if pid < 0 {
|
||||||
panic!("Phailed to Phork: {}", std::io::Error::last_os_error());
|
panic!("Phailed to Phork: {}", std::io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
if pid != 0 {
|
if pid != 0 {
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close stdout to not spam output
|
let file = std::fs::OpenOptions::new()
|
||||||
if unsafe { libc::isatty(1) } != 0 {
|
.create(true)
|
||||||
unsafe {
|
.append(true)
|
||||||
libc::close(1);
|
.open(&*LOG_FILE)
|
||||||
}
|
.expect(&format!(
|
||||||
}
|
"Error opening log file ({}), for writing",
|
||||||
// close stderr to not spam output
|
&*LOG_FILE.to_string_lossy()
|
||||||
if unsafe { libc::isatty(2) } != 0 {
|
));
|
||||||
unsafe {
|
let fd = file.as_raw_fd();
|
||||||
let fd = libc::open(std::ffi::CString::new("/dev/null").unwrap().as_ptr(), libc::O_RDWR);
|
|
||||||
if fd < 0 {
|
unsafe {
|
||||||
panic!("Phailed to open /dev/null?!: {}", std::io::Error::last_os_error());
|
if libc::isatty(1) != 0 {
|
||||||
} else {
|
if libc::dup2(fd, libc::STDOUT_FILENO) < 0 {
|
||||||
if libc::dup2(fd, libc::STDERR_FILENO) < 0 {
|
panic!("Phailed to dup stdout to log file: {:?}", std::io::Error::last_os_error());
|
||||||
panic!(
|
|
||||||
"Phailed to dup stderr phd to /dev/null: {:?}",
|
|
||||||
std::io::Error::last_os_error()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
libc::close(fd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if libc::isatty(2) != 0 {
|
||||||
|
if libc::dup2(fd, libc::STDERR_FILENO) < 0 {
|
||||||
|
panic!("Phailed to dup stderr to log file: {:?}", std::io::Error::last_os_error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
libc::close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue