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

Commit 272fb80

Browse files
committed
Cleans up appshell.gyp. Launching live browser works
1 parent 07ac9fe commit 272fb80

File tree

4 files changed

+108
-40
lines changed

4 files changed

+108
-40
lines changed

appshell.gyp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{
66
'variables': {
77
'appname': 'Brackets',
8+
'pkg-config': 'pkg-config',
89
'chromium_code': 1,
910
'conditions': [
1011
[ 'OS=="mac"', {
@@ -40,14 +41,6 @@
4041
],
4142
'include_dirs': [
4243
'.',
43-
'/usr/include/gtk-2.0/',
44-
'/usr/include/glib-2.0/',
45-
'/usr/include/gdk-pixbuf-2.0/',
46-
'/usr/include/atk-1.0/',
47-
'/usr/include/cairo/',
48-
'/usr/include/pango-1.0/',
49-
'/usr/lib/glib-2.0/include/',
50-
'/usr/lib/gtk-2.0/include/',
5144
],
5245
'sources': [
5346
'<@(includes_common)',
@@ -171,21 +164,21 @@
171164
'<@(appshell_sources_mac)',
172165
],
173166
}],
174-
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
167+
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
168+
'cflags': [
169+
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
170+
],
175171
'include_dirs': [
176172
'.',
177-
'/usr/include/gtk-2.0/',
178-
'/usr/include/glib-2.0/',
179-
'/usr/include/gdk-pixbuf-2.0/',
180-
'/usr/include/atk-1.0/',
181-
'/usr/include/cairo/',
182-
'/usr/include/pango-1.0/',
183-
'/usr/lib/glib-2.0/include/',
184-
'/usr/lib/gtk-2.0/include/',
185-
],
173+
],
174+
'default_configuration': 'Release',
175+
'configurations': {
176+
'Release': {},
177+
'Debug': {},
178+
},
186179
'copies': [
187180
{
188-
'destination': '<(PRODUCT_DIR)/files',
181+
'destination': '<(PRODUCT_DIR)',
189182
'files': [
190183
'<@(appshell_bundle_resources_linux)',
191184
],
@@ -195,6 +188,15 @@
195188
'<@(includes_linux)',
196189
'<@(appshell_sources_linux)',
197190
],
191+
'link_settings': {
192+
'ldflags': [
193+
'<!@(<(pkg-config) --libs-only-other gtk+-2.0 gthread-2.0)',
194+
'$(BUILDTYPE)/lib.target/libcef.so',
195+
],
196+
'libraries': [
197+
'<!@(<(pkg-config) --libs-only-l gtk+-2.0 gthread-2.0)',
198+
],
199+
},
198200
}],
199201
],
200202
},
@@ -214,14 +216,6 @@
214216
},
215217
'include_dirs': [
216218
'.',
217-
'/usr/include/gtk-2.0/',
218-
'/usr/include/glib-2.0/',
219-
'/usr/include/gdk-pixbuf-2.0/',
220-
'/usr/include/atk-1.0/',
221-
'/usr/include/cairo/',
222-
'/usr/include/pango-1.0/',
223-
'/usr/lib/glib-2.0/include/',
224-
'/usr/lib/gtk-2.0/include/',
225219
],
226220
'sources': [
227221
'<@(includes_common)',
@@ -235,6 +229,18 @@
235229
'GCC_TREAT_WARNINGS_AS_ERRORS': 'NO',
236230
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
237231
},
232+
'conditions': [
233+
['OS=="linux"', {
234+
'cflags': [
235+
'<!@(<(pkg-config) --cflags gtk+-2.0 gthread-2.0)',
236+
],
237+
'default_configuration': 'Release',
238+
'configurations': {
239+
'Release': {},
240+
'Debug': {},
241+
},
242+
}]
243+
]
238244
},
239245
],
240246
'conditions': [
@@ -306,7 +312,3 @@
306312
}], # OS=="mac"
307313
],
308314
}
309-
310-
311-
# Custom linker command:
312-
# 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

appshell/appshell_extensions_gtk.cpp

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,42 @@ LiveBrowserMgrLin* LiveBrowserMgrLin::s_instance = NULL;
220220
// return 0;
221221
// }
222222

223+
static const char* GetPathToLiveBrowser()
224+
{
225+
//#TODO Use execlp and be done with it! No need to reinvent the wheel; so badly that too!
226+
char *envPath = getenv( "PATH" ), *path, *dir, *currentPath;
227+
228+
//# copy PATH and not modify the original
229+
path=(char *)malloc(strlen(envPath)+1);
230+
strcpy(path, envPath);
231+
232+
// Prepend a forward-slash. For convenience
233+
const char* executable="/google-chrome";
234+
struct stat buf;
235+
int len;
236+
237+
for ( dir = strtok( path, ":" ); dir; dir = strtok( NULL, ":" ) )
238+
{
239+
len=strlen(dir)+strlen(executable);
240+
// if((strrchr(dir,'/')-dir)==strlen(dir))
241+
// {
242+
// currentPath = (char*)malloc(len);
243+
// strcpy(currentPath,dir);
244+
// } else
245+
// {
246+
// stat handles consecutive forward slashes automatically. No need for above
247+
currentPath = (char *)malloc(len+1);
248+
strncpy(currentPath,dir,len);
249+
//}
250+
strcat(currentPath,executable);
251+
252+
if(stat(currentPath,&buf)==0 && S_ISREG(buf.st_mode))
253+
return currentPath;
254+
}
255+
256+
return "";
257+
}
258+
223259
// static std::wstring GetPathToLiveBrowser()
224260
// {
225261
// HKEY hKey;
@@ -265,9 +301,36 @@ LiveBrowserMgrLin* LiveBrowserMgrLin::s_instance = NULL;
265301
// }
266302

267303
int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
268-
{
269-
printf("Gotta open Live Browser %s\n", argURL.c_str());
270-
//#TODO Duh!
304+
{
305+
//# COnsider using execlp and avoid all this path mess!
306+
const char *appPath = GetPathToLiveBrowser(),
307+
*arg1 = "--allow-file-access-from-files";
308+
std::string arg2(" ");
309+
310+
if(enableRemoteDebugging)
311+
arg2.assign("--remote-debugging-port=9222");
312+
313+
short int error=0;
314+
/* Using vfork() 'coz I need a shared variable for the error passing.
315+
* Do not replace with fork() unless you have a better way. */
316+
pid_t pid = vfork();
317+
switch(pid)
318+
{
319+
case -1: //# Something went wrong
320+
return ConvertLinuxErrorCode(errno);
321+
case 0: //# I'm the child. When I successfully exec, parent is resumed. Or when I _exec()
322+
execl(appPath, arg1, argURL.c_str(), arg2.c_str(),(char *)0);
323+
324+
error=errno;
325+
_exit(0);
326+
default:
327+
if(error!=0)
328+
{
329+
printf("Error!! %s\n", strerror(error));
330+
return ConvertLinuxErrorCode(error);
331+
}
332+
}
333+
271334
return NO_ERROR;
272335
}
273336

appshell/client_app_gtk.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ CefString ClientApp::GetCurrentLanguage()
4444
std::string ClientApp::GetExtensionJSSource()
4545
{
4646
//Another bloody TODO here.
47-
printf("in GetExtensionJSSource\n");
48-
FILE* file = fopen("appshell_extensions.js","r");
47+
std:: string extensionJSPath(AppGetSupportDirectory());
48+
extensionJSPath.append("/appshell_extensions.js");
49+
FILE* file = fopen(extensionJSPath.c_str(),"r");
4950
if(file == NULL)
5051
{
5152
return "";
@@ -69,16 +70,17 @@ double ClientApp::GetElapsedMilliseconds()
6970

7071
CefString ClientApp::AppGetSupportDirectory()
7172
{
72-
//Check environment variables first
73-
char* home_dir = getenv("HOME");
74-
if(home_dir == NULL)
73+
//Check environment variables first;
74+
std:: string home_dir(getenv("HOME"));
75+
76+
if(home_dir.length()==0)
7577
{
7678
//If no environment variable, use the system provided home directory
7779
struct passwd *pw = getpwuid(getuid());
7880
home_dir = pw->pw_dir;
7981
}
8082

8183
// ~/.config/Brackets? ~/.Brackets ?? We'll see, later.
82-
return strcat(home_dir,"/.Brackets");
84+
return home_dir.append("/.Brackets");
8385
}
8486

appshell_paths.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
'appshell/resource_util_linux.cpp',
155155
],
156156
'appshell_bundle_resources_linux': [
157+
'$(BUILDTYPE)/locales',
157158
],
158159
},
159160
}

0 commit comments

Comments
 (0)