parent
5f0c1ec70a
commit
c980c70798
@ -0,0 +1,27 @@
|
||||
import { join } from "path";
|
||||
import { createHash } from "crypto";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
import checkAndCopyConfig from "utils/config/config";
|
||||
|
||||
const configs = ["docker.yaml", "settings.yaml", "services.yaml", "bookmarks.yaml"];
|
||||
|
||||
function hash(buffer) {
|
||||
const hashSum = createHash("sha256");
|
||||
hashSum.update(buffer);
|
||||
return hashSum.digest("hex");
|
||||
}
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const hashes = configs.map((config) => {
|
||||
checkAndCopyConfig(config);
|
||||
const configYaml = join(process.cwd(), "config", config);
|
||||
return hash(readFileSync(configYaml, "utf8"));
|
||||
});
|
||||
|
||||
const combinedHash = hash(hashes.join(""));
|
||||
|
||||
res.send({
|
||||
hash: combinedHash,
|
||||
});
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const hasFocus = () => typeof document !== "undefined" && document.hasFocus();
|
||||
|
||||
const useWindowFocus = () => {
|
||||
const [focused, setFocused] = useState(hasFocus);
|
||||
|
||||
useEffect(() => {
|
||||
setFocused(hasFocus());
|
||||
|
||||
const onFocus = () => setFocused(true);
|
||||
const onBlur = () => setFocused(false);
|
||||
|
||||
window.addEventListener("focus", onFocus);
|
||||
window.addEventListener("blur", onBlur);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("focus", onFocus);
|
||||
window.removeEventListener("blur", onBlur);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return focused;
|
||||
};
|
||||
|
||||
export default useWindowFocus;
|
Loading…
Reference in new issue