Skip to content

Commit

Permalink
dock:: fix intellij idea cannot run.(icon is still a problem)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosl90 committed Jun 11, 2014
1 parent f732056 commit fc2afa7
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
13 changes: 7 additions & 6 deletions dock/docked_app_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ StartupNotify=false
`
)

var scratchDir string = filepath.Join(os.Getenv("HOME"), ".config/dock/scratch")

type DockedAppManager struct {
core *gio.Settings
items *list.List
Expand Down Expand Up @@ -148,11 +150,8 @@ func (m *DockedAppManager) Undock(id string) bool {
logger.Info("Remove", m.items.Remove(removeItem))
m.core.SetStrv(DockedApps, m.toSlice())
gio.SettingsSync()
os.Remove(filepath.Join(
os.Getenv("HOME"),
".config/dock/scratch",
id+".desktop",
))
os.Remove(filepath.Join(scratchDir, id+".desktop"))
os.Remove(filepath.Join(scratchDir, id+".sh"))
m.Undocked(id)
return true
} else {
Expand Down Expand Up @@ -195,8 +194,10 @@ func createScratchFile(id, title, icon, cmd string) error {
path := ".config/dock/scratch"
configDir := filepath.Join(homeDir, path)
os.MkdirAll(configDir, 0775)
f, err := os.Create(filepath.Join(configDir, id+".desktop"))
f, err := os.OpenFile(filepath.Join(configDir, id+".desktop"),
os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0744)
if err != nil {
logger.Error(err)
return err
}
temp := template.Must(template.New("docked_item_temp").Parse(DockedItemTemp))
Expand Down
3 changes: 2 additions & 1 deletion dock/entry_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,15 @@ func (m *EntryManager) createNormalApp(id string) {
desktopId := id + ".desktop"
nApp := NewNormalApp(desktopId)
if nApp == nil {
logger.Info("create scratch file")
logger.Info("create from scratch file")
newId := filepath.Join(
os.Getenv("HOME"),
".config/dock/scratch",
desktopId,
)
nApp = NewNormalApp(newId)
if nApp == nil {
logger.Warning("create normal app failed:", id)
return
}
}
Expand Down
62 changes: 61 additions & 1 deletion dock/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,67 @@ char* find_app_id(const char* exec_name, const char* key, int filter)
return NULL;
}

char** get_exec_env(int pid)
{
char** envs = NULL;
char* row_env = NULL;
char* path = g_strdup_printf("/proc/%d/environ", pid);

gsize size=0;
if (g_file_get_contents(path, &row_env, &size, NULL) && size > 0) {
envs = g_new(char*, 1024);
gsize j = 0;
gsize i=0;
envs[j] = g_strdup(row_env);
for (; i<size && j<1024; i++) {
if (row_env[i] == 0) {
envs[++j] = g_strdup(row_env + i + 1);
}
}

g_free(row_env);
envs[j] = NULL;
}

return envs;
}

char* get_exe_name(int pid)
{
char* exec_name = NULL;
char* args = NULL;

get_pid_info(pid, &exec_name, &args);
g_warning("%s %s", exec_name, args);
char* exec = NULL;
if (g_strcmp0(exec_name, "java") == 0) {
char** envs = get_exec_env(pid);
char* env = NULL;
int i = 0;
for (; envs[i] != NULL; ++i) {
if (g_str_has_prefix(envs[i], "CLASSPATH")) {
env = g_strdup(envs[i]);
break;
}
}
for (i = 0; envs[i] != NULL; ++i) {
g_free(envs[i]);
}
if (env == NULL) {
exec = g_strconcat(exec_name, " ", args, NULL);
} else {
exec = g_strconcat(env, " ", exec_name, " ", args, NULL);
}
g_free(env);
} else {
exec = g_strconcat(exec_name, " ", args, NULL);
}
g_free(exec_name);
g_free(args);
return exec;
}

char* get_exe(int pid)
{
#define BUF_LEN 8095
char buf[BUF_LEN] = {0};
Expand Down Expand Up @@ -311,7 +371,7 @@ void get_pid_info(int pid, char** exec_name, char** exec_args)
g_free(name_args);

} else {
*exec_name = get_exe_name(pid);
*exec_name = get_exe(pid);
*exec_args = NULL;
}
g_free(path);
Expand Down
8 changes: 7 additions & 1 deletion dock/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package dock
//#include <stdlib.h>
// char* guess_app_id(long s_pid, const char* instance_name, const char* wmname, const char* wmclass, const char* icon_name);
// char* get_exe_name(int pid);
// char* get_exe(int pid);
// void get_pid_info(int pid, char** exec_name, char** exec_args);
//char* icon_name_to_path(const char* name, int size);
// void init_deepin();
// char* get_data_uri_by_path(const char* path);
Expand All @@ -32,7 +34,11 @@ func find_app_id(pid uint, instanceName, wmName, wmClass, iconName string) strin
}

func find_exec_name_by_pid(pid uint) string {
return C.GoString(C.get_exe_name(C.int(pid)))
e := C.GoString(C.get_exe_name(C.int(pid)))
if e {
return e
}
return C.GoString(C.get_exe(C.int(pid)))
}

func get_theme_icon(name string, size int) string {
Expand Down
3 changes: 2 additions & 1 deletion dock/normal_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ type NormalApp struct {

func NewNormalApp(id string) *NormalApp {
app := &NormalApp{Id: strings.ToLower(filepath.Base(id[:len(id)-8]))}
logger.Info(id)
logger.Info("NewNormalApp:", id)
if filepath.IsAbs(id) {
app.core = gio.NewDesktopAppInfoFromFilename(id)
} else {
app.core = gio.NewDesktopAppInfo(id)
if app.core == nil {
logger.Info("guess desktop")
if newId := guess_desktop_id(app.Id + ".desktop"); newId != "" {
app.core = gio.NewDesktopAppInfo(newId)
}
Expand Down
13 changes: 11 additions & 2 deletions dock/runtime_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/BurntSushi/xgbutil/xgraphics"
"github.com/BurntSushi/xgbutil/xprop"
"github.com/BurntSushi/xgbutil/xwindow"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -100,6 +103,7 @@ func (app *RuntimeApp) getExec(xid xproto.Window) {
}
logger.Debug(app.Id, " Get Exec from pid")
app.exec = find_exec_name_by_xid(xid)
logger.Warning("app get exec:", app.exec)
}
func (app *RuntimeApp) buildMenu() {
app.coreMenu = NewMenu()
Expand Down Expand Up @@ -184,8 +188,13 @@ func (app *RuntimeApp) buildMenu() {
if app.core == nil {
title = app.Id
// TODO:
icon = ""
exec = app.exec
icon = "application-default-icon"
execFile := filepath.Join(
scratchDir,
app.Id+".sh",
)
ioutil.WriteFile(execFile, []byte(app.exec), 0744)
exec = execFile
} else {
title = app.core.GetDisplayName()
icon =
Expand Down

0 comments on commit fc2afa7

Please sign in to comment.