1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File usage tracking</title>
<script>
const { ipcRenderer, app } = require('electron');
const fs = require('fs');
window.list = [];
function fillList(dir) {
for (let file of fs.readdirSync(dir)) {
list.push(dir + "/" + file);
try {
fs.accessSync(dir + "/" + file, fs.constants.R_OK);
if (fs.lstatSync(dir + "/" + file).isDirectory()) {
fillList(dir + "/" + file);
}
} catch (e) {}
}
}
ipcRenderer.on('config', (event, data) => {
window.config = JSON.parse(data);
})
ipcRenderer.on('watchers', (event, data) => {
window.data = JSON.parse(data);
window.list = [];
fillList(window.config.directory);
window.list = [...new Set([...window.list, ...Object.keys(window.data.fileWatchers), ...window.data.fileWatchersPurgeable])].sort((a, b) => {
return a.localeCompare(b);
});
let dom = "";
for (let item of list) {
dom += `
<div class="list-item ${(item.substring(window.config.directory.length + 1).includes("/.") || item.substring(window.config.directory.length + 1).startsWith(".")) && !item.substring(window.config.directory.length + 1).startsWith(".Trashes/") && !item.substring(window.config.directory.length + 1).startsWith(".Trash/") && item.substring(window.config.directory.length + 1).startsWith(".Trash-") ? "list-item-system" : ""} ${(item.substring(window.config.directory.length + 1).includes("/.") || item.substring(window.config.directory.length + 1).startsWith(".")) && (item.substring(window.config.directory.length + 1).startsWith(".Trashes/") || item.substring(window.config.directory.length + 1).startsWith(".Trash/") || item.substring(window.config.directory.length + 1).startsWith(".Trash-")) ? "list-item-trash" : ""} ${window.data.fileWatchersFailed.includes(item) ? "list-item-failed" : !Object.keys(window.data.fileWatchers).includes(item) ? "list-item-untracked" : ""} ${window.data.fileWatchersPurgeable.includes(item) ? "list-item-purgeable" : ""}">
<div>${item.substring(window.config.directory.length + 1)}</div>
<div style="opacity: .5;">
${(item.substring(window.config.directory.length + 1).includes("/.") || item.substring(window.config.directory.length + 1).startsWith(".")) && !item.substring(window.config.directory.length + 1).startsWith(".Trashes/") && !item.substring(window.config.directory.length + 1).startsWith(".Trash/") && !item.substring(window.config.directory.length + 1).startsWith(".Trash-") ? "<span style='padding: 2px 5px;border-radius:5px;background:rgba(0, 0, 0, .3);'>System</span>" : ""}
${(item.substring(window.config.directory.length + 1).includes("/.") || item.substring(window.config.directory.length + 1).startsWith(".")) && (item.substring(window.config.directory.length + 1).startsWith(".Trashes/") || item.substring(window.config.directory.length + 1).startsWith(".Trash/") || item.substring(window.config.directory.length + 1).startsWith(".Trash-")) ? "<span style='padding: 2px 5px;border-radius:5px;background:rgba(0, 0, 0, .3);'>Trash</span>" : ""}
${window.data.fileWatchersFailed.includes(item) ? "<span style='padding: 2px 5px;border-radius:5px;background:rgba(0, 0, 0, .3);'>Failed</span>" : !Object.keys(window.data.fileWatchers).includes(item) ? "<span style='padding: 2px 5px;border-radius:5px;background:rgba(0, 0, 0, .3);'>Untracked</span>" : ""}
${window.data.fileWatchersPurgeable.includes(item) ? "<span style='padding: 2px 5px;border-radius:5px;background:rgba(0, 0, 0, .3);'>Purgeable</span>" : ""}
</div>
</div>
`;
}
document.getElementById("list").innerHTML = dom;
})
</script>
<style>
* {
cursor: default;
}
body {
background: #333;
margin: 0;
font-size: 14px;
color: white;
font-family: system-ui, -apple-system, sans-serif;
}
.list-item:hover {
background: rgba(0, 0, 0, .1);
}
.list-item {
border-top: 1px solid rgba(0, 0, 0, .25);
padding: 5px 10px;
display: grid;
grid-template-columns: 1fr max-content;
grid-gap: 10px;
}
.list-item > div {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.list-item.list-item-untracked {
background: rgba(213, 59, 59, 0.1);
}
.list-item.list-item-untracked:hover {
background: rgba(213, 59, 59, 0.25);
}
.list-item.list-item-purgeable {
background: rgba(213, 187, 59, 0.1);
}
.list-item.list-item-purgeable:hover {
background: rgba(213, 187, 59, 0.25);
}
.list-item.list-item-system {
background: rgba(59, 213, 190, 0.1);
}
.list-item.list-item-system:hover {
background: rgba(59, 213, 190, 0.25);
}
.list-item.list-item-trash {
background: rgba(110, 59, 213, 0.1);
}
.list-item.list-item-trash:hover {
background: rgba(110, 59, 213, 0.25);
}
.list-item.list-item-failed {
background: rgba(59, 213, 95, 0.1);
}
.list-item.list-item-failed:hover {
background: rgba(59, 213, 95, 0.25);
}
</style>
</head>
<body>
<div id="list"></div>
</body>
</html>
|