-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement session locking, unlocking
Send the LockSessions message and UnlockSessions message via DBus to Systemd Logind to lock/unlock the current user's desktop.
- Loading branch information
Géza Búza
committed
Apr 4, 2019
1 parent
6982788
commit 4a96a15
Showing
3 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/session-lock-manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package session | ||
|
||
import ( | ||
"log" | ||
"fmt" | ||
"github.com/godbus/dbus" | ||
) | ||
|
||
func Lock() { | ||
error := callDbusMethod("LockSessions") | ||
if error != nil { | ||
fmt.Println(fmt.Sprintf("Failed to lock session: %s", error)) | ||
return | ||
} | ||
|
||
log.Println("Locking session.") | ||
} | ||
|
||
func Unlock() { | ||
error := callDbusMethod("UnlockSessions") | ||
if error != nil { | ||
fmt.Println(fmt.Sprintf("Failed to lock session: %s", error)) | ||
return | ||
} | ||
|
||
log.Println("Unlocking session.") | ||
} | ||
|
||
func callDbusMethod(methodName string) (error) { | ||
connection, error := dbus.SystemBus() | ||
if error != nil { | ||
fmt.Println(fmt.Sprintf("Failed to connectionect to session bus: %s", error)) | ||
return nil | ||
} | ||
|
||
object := connection.Object("org.freedesktop.login1", "/org/freedesktop/login1") | ||
call := object.Call(fmt.Sprintf("org.freedesktop.login1.Manager.%s", methodName), 0) | ||
if call.Err != nil { | ||
return call.Err | ||
} | ||
return nil | ||
} |