summaryrefslogtreecommitdiffhomepage
path: root/AutoStart.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-22 11:55:10 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-22 11:59:12 -0400
commit9eeb584342d1f29415065efc5ba34a7045b2259b (patch)
tree39ab33f724a7061fc6ebe9cf37917dd273b857d4 /AutoStart.hs
parent44c4f503ae4c79739c52c73fdfa35e754621011c (diff)
downloadkeysafe-9eeb584342d1f29415065efc5ba34a7045b2259b.tar.gz
Added --autostart mode and install FDO autostart file
--autostart mode currently only uploads queued keys, but it will later be expanded to do more. Including checking the BackupRecord for problems when necessary. The autostart file is installed by keysafe --backup, so that when keysafe is installed with stack, and used, it will make sure it autostarts in the future. The autostart file is installed by the Makefile too. This will later let --autostart check for keys that have not been backed up and prompt about backing them up. This way, the user won't need to remember to run keysafe to back things up. Reused Utility.FreeDesktop from git-annex, and had to add some stuff it depends on. This commit was sponsored by Fernando Jimenez on Patreon.
Diffstat (limited to 'AutoStart.hs')
-rw-r--r--AutoStart.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/AutoStart.hs b/AutoStart.hs
new file mode 100644
index 0000000..dc022df
--- /dev/null
+++ b/AutoStart.hs
@@ -0,0 +1,42 @@
+{- Copyright 2016 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU AGPL version 3 or higher.
+ -}
+
+module AutoStart where
+
+import Utility.FreeDesktop
+import System.Info
+import System.Environment
+import System.Directory
+
+installAutoStartFile :: IO ()
+installAutoStartFile = go =<< autoStartFile
+ where
+ go (Just f) = case os of
+ "linux" -> installFdoAutoStart f
+ "freebsd" -> installFdoAutoStart f
+ _ -> return ()
+ go Nothing = return ()
+
+isAutoStartFileInstalled :: IO Bool
+isAutoStartFileInstalled = maybe (pure False) doesFileExist =<< autoStartFile
+
+autoStartFile :: IO (Maybe FilePath)
+autoStartFile = case os of
+ "linux" -> Just . autoStartPath "keysafe" <$> userConfigDir
+ _ -> return Nothing
+
+installFdoAutoStart :: FilePath -> IO ()
+installFdoAutoStart f = do
+ command <- getExecutablePath
+ writeDesktopMenuFile (fdoAutostart command) f
+
+fdoAutostart :: FilePath -> DesktopEntry
+fdoAutostart command = genDesktopEntry
+ "Keysafe"
+ "Autostart"
+ False
+ (command ++ " --autostart")
+ Nothing
+ []