Skip to content

Commit

Permalink
⚡ Implement force caching of instances by the daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
yamnikov-oleg committed Mar 19, 2017
1 parent c92cad3 commit 5365149
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ Here's annotation for every paramater of the default config:
# You can use modifier keys `shift` and `control`.
# To identify some complex keybind use `xbindkeys` tool.
keybind: mod4-q
# How often should projektor daemon run an instance in the background with
# '-dry' flag?
# The dry instances are run to force the kernel to cache all the data needed
# by projektor to run. By forcing the caching we can enable projektor instances
# to startup faster.
# The interval is specified in seconds. Set to 0 if you want to disable
# the force caching completely.
forcecacheinterval: 60
# Searching categories, enabled for use.
# Disable a category by settings its flag to `false` and projektor will no longer
# offer you entries of that category.
Expand Down
9 changes: 6 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package main

import (
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path"

"gopkg.in/yaml.v2"
)

type ProjektorConfig struct {
KeyBind string
EnabledCategories struct {
KeyBind string
ForceCacheInterval int64
EnabledCategories struct {
Calc bool
History bool
Apps bool
Expand Down Expand Up @@ -39,6 +41,7 @@ func DefaultConfig() *ProjektorConfig {
c := &ProjektorConfig{}

c.KeyBind = "mod4-q"
c.ForceCacheInterval = 60

c.EnabledCategories.Calc = true
c.EnabledCategories.History = true
Expand Down
4 changes: 4 additions & 0 deletions kill_running.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func KillIfOtherInstance(p ps.Process) bool {
return false
}

if strings.Contains(p.Cmdline(), "-dry") {
return false
}

osproc, err := os.FindProcess(p.Pid())
if err != nil {
return false
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"runtime/pprof"
"time"

"github.com/BurntSushi/xgbutil"
"github.com/BurntSushi/xgbutil/keybind"
Expand Down Expand Up @@ -51,6 +52,22 @@ func RunInstance(dry bool) {
func RunDaemon() {
logf("Running key binding daemon of projektor\n")

fci := Config.ForceCacheInterval
if fci > 0 {
go func() {
for {
logf("Running dry instance...\n")
cmd := exec.Command(os.Args[0], "-"+SIFlag, "-dry")
err := cmd.Start()
if err != nil {
errduring("dry instance creation", err, "")
}
go cmd.Wait()
time.Sleep(time.Duration(fci) * time.Second)
}
}()
}

xu, err := xgbutil.NewConn()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 5365149

Please sign in to comment.