Skip to content

Commit df471d8

Browse files
authored
Merge pull request #419 from damongolding/feature/immichframe-sleep
Feature/immichframe-dim-screen
2 parents e043907 + 3eac1e6 commit df471d8

4 files changed

Lines changed: 87 additions & 6 deletions

File tree

frontend/src/ts/immichframe.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { triggerNewAsset } from "./polling";
2+
3+
class ImmichFrame {
4+
private static instance: ImmichFrame | null = null;
5+
6+
private readonly SCREENSAVER_DELAY_MS = 4 * 1000;
7+
8+
private readonly PORT = 53287 as const;
9+
private readonly BASE_URL = `http://localhost:${this.PORT}`;
10+
11+
private readonly endpoints = {
12+
DIM: "dim",
13+
UNDIM: "undim",
14+
NEXT: "next",
15+
PREVIOUS: "previous",
16+
PAUSE: "pause",
17+
SETTINGS: "settings",
18+
};
19+
20+
inSleepMode: boolean = false;
21+
22+
public static getInstance(): ImmichFrame {
23+
if (!ImmichFrame.instance) {
24+
ImmichFrame.instance = new ImmichFrame();
25+
}
26+
return ImmichFrame.instance;
27+
}
28+
29+
public dimScreen(): void {
30+
fetch(`${this.BASE_URL}/${this.endpoints.DIM}`).catch((error) =>
31+
console.error("Error dimming ImmichFrame screen:", error),
32+
);
33+
}
34+
35+
public undimScreen(): void {
36+
fetch(`${this.BASE_URL}/${this.endpoints.UNDIM}`).catch((error) =>
37+
console.error("Error undimming ImmichFrame screen:", error),
38+
);
39+
}
40+
41+
public setScreensaverState(enable: boolean): void {
42+
try {
43+
if (enable) {
44+
if (this.inSleepMode) return;
45+
46+
this.inSleepMode = true;
47+
48+
setTimeout(() => this.dimScreen(), this.SCREENSAVER_DELAY_MS);
49+
} else {
50+
if (!this.inSleepMode) return;
51+
52+
this.undimScreen();
53+
54+
this.inSleepMode = false;
55+
56+
triggerNewAsset();
57+
}
58+
} catch (error) {
59+
console.error("Error in ImmichFrame screen operations:", error);
60+
}
61+
}
62+
}
63+
64+
const immichFrame = ImmichFrame.getInstance();
65+
66+
export default immichFrame;

frontend/src/ts/sleep.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fullyKiosk from "./fullykiosk";
2+
import immichFrame from "./immichframe";
23

34
/**
45
* Toggles UI sleep mode and optionally controls the device screensaver via the Fully Kiosk API.
@@ -15,7 +16,10 @@ function sleepMode(turnOn: boolean, screensaver: boolean): void {
1516
document.body.classList.remove("sleep");
1617
}
1718

18-
if (screensaver) fullyKiosk.setScreensaverState(turnOn);
19+
if (screensaver) {
20+
fullyKiosk.setScreensaverState(turnOn);
21+
immichFrame.setScreensaverState(turnOn);
22+
}
1923
}
2024

2125
export { sleepMode };

internal/templates/partials/redirects.templ

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ import (
55
"net/url"
66
)
77

8+
func checkAuthParam(queries url.Values) (bool, string, string) {
9+
if queries.Has("password") {
10+
return true, queries.Get("password"), "password"
11+
}
12+
if queries.Has("authsecret") {
13+
return true, queries.Get("authsecret"), "authsecret"
14+
}
15+
return false, "", ""
16+
}
17+
818
templ Redirects(redirects []config.Redirect, queries url.Values) {
19+
{{ hasPassword, password, paramType := checkAuthParam(queries) }}
920
<div id="redirects-container">
1021
<div class="redirects">
1122
<div class="redirects--shadow">
12-
if queries.Has("password") {
13-
<a href={ templ.SafeURL("/?password=" + queries.Get("password")) }>Home</a>
23+
if hasPassword {
24+
<a href={ templ.SafeURL("/?" + paramType + "=" + password) }>Home</a>
1425
}
1526
for _ , redirect := range redirects {
16-
if queries.Has("password") {
17-
<a href={ templ.SafeURL(redirect.Name + "?password=" + queries.Get("password")) }>{ redirect.Name }</a>
27+
if hasPassword {
28+
<a href={ templ.SafeURL(redirect.Name + "?" + paramType + "=" + password) }>{ redirect.Name }</a>
1829
} else {
1930
<a href={ templ.SafeURL(redirect.Name) }>{ redirect.Name }</a>
2031
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func main() {
121121
// skip auth for assets
122122
return strings.HasPrefix(c.Request().URL.String(), "/assets")
123123
},
124-
KeyLookup: "query:password,form:password",
124+
KeyLookup: "query:authsecret,form:authsecret,query:password,form:password",
125125
Validator: func(queryPassword string, _ echo.Context) (bool, error) {
126126
return queryPassword == baseConfig.Kiosk.Password, nil
127127
},

0 commit comments

Comments
 (0)