Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
Cleans up appshell.gyp. Launching live browser works
Browse files Browse the repository at this point in the history
  • Loading branch information
pritambaral committed Oct 30, 2012
1 parent 07ac9fe commit 272fb80
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 40 deletions.
64 changes: 33 additions & 31 deletions appshell.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
'variables': {
'appname': 'Brackets',
'pkg-config': 'pkg-config',
'chromium_code': 1,
'conditions': [
[ 'OS=="mac"', {
Expand Down Expand Up @@ -40,14 +41,6 @@
],
'include_dirs': [
'.',
'/usr/include/gtk-2.0/',
'/usr/include/glib-2.0/',
'/usr/include/gdk-pixbuf-2.0/',
'/usr/include/atk-1.0/',
'/usr/include/cairo/',
'/usr/include/pango-1.0/',
'/usr/lib/glib-2.0/include/',
'/usr/lib/gtk-2.0/include/',
],
'sources': [
'<@(includes_common)',
Expand Down Expand Up @@ -171,21 +164,21 @@
'<@(appshell_sources_mac)',
],
}],
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'cflags': [
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
],
'include_dirs': [
'.',
'/usr/include/gtk-2.0/',
'/usr/include/glib-2.0/',
'/usr/include/gdk-pixbuf-2.0/',
'/usr/include/atk-1.0/',
'/usr/include/cairo/',
'/usr/include/pango-1.0/',
'/usr/lib/glib-2.0/include/',
'/usr/lib/gtk-2.0/include/',
],
],
'default_configuration': 'Release',
'configurations': {
'Release': {},
'Debug': {},
},
'copies': [
{
'destination': '<(PRODUCT_DIR)/files',
'destination': '<(PRODUCT_DIR)',
'files': [
'<@(appshell_bundle_resources_linux)',
],
Expand All @@ -195,6 +188,15 @@
'<@(includes_linux)',
'<@(appshell_sources_linux)',
],
'link_settings': {
'ldflags': [
'<!@(<(pkg-config) --libs-only-other gtk+-2.0 gthread-2.0)',
'$(BUILDTYPE)/lib.target/libcef.so',
],
'libraries': [
'<!@(<(pkg-config) --libs-only-l gtk+-2.0 gthread-2.0)',
],
},
}],
],
},
Expand All @@ -214,14 +216,6 @@
},
'include_dirs': [
'.',
'/usr/include/gtk-2.0/',
'/usr/include/glib-2.0/',
'/usr/include/gdk-pixbuf-2.0/',
'/usr/include/atk-1.0/',
'/usr/include/cairo/',
'/usr/include/pango-1.0/',
'/usr/lib/glib-2.0/include/',
'/usr/lib/gtk-2.0/include/',
],
'sources': [
'<@(includes_common)',
Expand All @@ -235,6 +229,18 @@
'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
},
'conditions': [
['OS=="linux"', {
'cflags': [
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
],
'default_configuration': 'Release',
'configurations': {
'Release': {},
'Debug': {},
},
}]
]
},
],
'conditions': [
Expand Down Expand Up @@ -306,7 +312,3 @@
}], # OS=="mac"
],
}


# Custom linker command:
# g++ -o out/Default/Brackets -Wl,--start-group out/Default/obj.target/Brackets/appshell/appshell_extensions.o out/Default/obj.target/Brackets/appshell/appshell_extensions_gtk.o out/Default/obj.target/Brackets/appshell/cefclient.o out/Default/obj.target/Brackets/appshell/client_app.o out/Default/obj.target/Brackets/appshell/client_app_delegates.o out/Default/obj.target/Brackets/appshell/client_handler.o out/Default/obj.target/Brackets/appshell/client_switches.o out/Default/obj.target/Brackets/appshell/string_util.o out/Default/obj.target/Brackets/appshell/cefclient_gtk.o out/Default/obj.target/Brackets/appshell/client_handler_gtk.o out/Default/obj.target/Brackets/appshell/client_app_gtk.o out/Default/obj.target/Brackets/appshell/resource_util_linux.o out/Default/obj.target/libcef_dll_wrapper.a deps/cef/Release/lib.target/libcef.so -lgtk-x11-2.0 -lgobject-2.0 -lpthread.so -lglib-2.0 -Wl,--end-group
69 changes: 66 additions & 3 deletions appshell/appshell_extensions_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,42 @@ LiveBrowserMgrLin* LiveBrowserMgrLin::s_instance = NULL;
// return 0;
// }

static const char* GetPathToLiveBrowser()
{
//#TODO Use execlp and be done with it! No need to reinvent the wheel; so badly that too!
char *envPath = getenv( "PATH" ), *path, *dir, *currentPath;

//# copy PATH and not modify the original
path=(char *)malloc(strlen(envPath)+1);
strcpy(path, envPath);

// Prepend a forward-slash. For convenience
const char* executable="/google-chrome";
struct stat buf;
int len;

for ( dir = strtok( path, ":" ); dir; dir = strtok( NULL, ":" ) )
{
len=strlen(dir)+strlen(executable);
// if((strrchr(dir,'/')-dir)==strlen(dir))
// {
// currentPath = (char*)malloc(len);
// strcpy(currentPath,dir);
// } else
// {
// stat handles consecutive forward slashes automatically. No need for above
currentPath = (char *)malloc(len+1);
strncpy(currentPath,dir,len);
//}
strcat(currentPath,executable);

if(stat(currentPath,&buf)==0 && S_ISREG(buf.st_mode))
return currentPath;
}

return "";
}

// static std::wstring GetPathToLiveBrowser()
// {
// HKEY hKey;
Expand Down Expand Up @@ -265,9 +301,36 @@ LiveBrowserMgrLin* LiveBrowserMgrLin::s_instance = NULL;
// }

int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
{
printf("Gotta open Live Browser %s\n", argURL.c_str());
//#TODO Duh!
{
//# COnsider using execlp and avoid all this path mess!
const char *appPath = GetPathToLiveBrowser(),
*arg1 = "--allow-file-access-from-files";
std::string arg2(" ");

if(enableRemoteDebugging)
arg2.assign("--remote-debugging-port=9222");

short int error=0;
/* Using vfork() 'coz I need a shared variable for the error passing.
* Do not replace with fork() unless you have a better way. */
pid_t pid = vfork();
switch(pid)
{
case -1: //# Something went wrong
return ConvertLinuxErrorCode(errno);
case 0: //# I'm the child. When I successfully exec, parent is resumed. Or when I _exec()
execl(appPath, arg1, argURL.c_str(), arg2.c_str(),(char *)0);

error=errno;
_exit(0);
default:
if(error!=0)
{
printf("Error!! %s\n", strerror(error));
return ConvertLinuxErrorCode(error);
}
}

return NO_ERROR;
}

Expand Down
14 changes: 8 additions & 6 deletions appshell/client_app_gtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ CefString ClientApp::GetCurrentLanguage()
std::string ClientApp::GetExtensionJSSource()
{
//Another bloody TODO here.
printf("in GetExtensionJSSource\n");
FILE* file = fopen("appshell_extensions.js","r");
std:: string extensionJSPath(AppGetSupportDirectory());
extensionJSPath.append("/appshell_extensions.js");
FILE* file = fopen(extensionJSPath.c_str(),"r");
if(file == NULL)
{
return "";
Expand All @@ -69,16 +70,17 @@ double ClientApp::GetElapsedMilliseconds()

CefString ClientApp::AppGetSupportDirectory()
{
//Check environment variables first
char* home_dir = getenv("HOME");
if(home_dir == NULL)
//Check environment variables first;
std:: string home_dir(getenv("HOME"));

if(home_dir.length()==0)
{
//If no environment variable, use the system provided home directory
struct passwd *pw = getpwuid(getuid());
home_dir = pw->pw_dir;
}

// ~/.config/Brackets? ~/.Brackets ?? We'll see, later.
return strcat(home_dir,"/.Brackets");
return home_dir.append("/.Brackets");
}

1 change: 1 addition & 0 deletions appshell_paths.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
'appshell/resource_util_linux.cpp',
],
'appshell_bundle_resources_linux': [
'$(BUILDTYPE)/locales',
],
},
}

0 comments on commit 272fb80

Please sign in to comment.