|
21 | 21 | * |
22 | 22 | */ |
23 | 23 |
|
24 | | -#include "client_app.h" |
| 24 | +#include "appshell/appshell_helpers.h" |
25 | 25 |
|
26 | 26 | #include "include/cef_base.h" |
| 27 | +#include "include/cef_version.h" |
27 | 28 | #include "config.h" |
28 | 29 | #include <Cocoa/Cocoa.h> |
29 | 30 |
|
30 | | -#include <string> |
31 | | - |
32 | 31 | extern CFTimeInterval g_appStartupTime; |
33 | 32 |
|
34 | | -double ClientApp::GetElapsedMilliseconds() |
| 33 | +namespace appshell { |
| 34 | + |
| 35 | +double GetElapsedMilliseconds() |
35 | 36 | { |
36 | 37 | CFAbsoluteTime elapsed = CFAbsoluteTimeGetCurrent() - g_appStartupTime; |
37 | | - |
| 38 | + |
38 | 39 | return round(elapsed * 1000); |
39 | 40 | } |
40 | 41 |
|
41 | | -CefString ClientApp::GetCurrentLanguage() |
| 42 | +CefString GetCurrentLanguage() |
42 | 43 | { |
43 | 44 | // Do not confuse preferredLanguages with currentLocale. |
44 | 45 | // preferredLanguages specifies to UI language. currentLocale |
|
49 | 50 | // default on US systems. |
50 | 51 | // NSLog(@"localeIdentifier: %@", [[NSLocale currentLocale] localeIdentifier]); |
51 | 52 | // NSLog(@"%@", language); |
52 | | - |
| 53 | + |
53 | 54 | NSString* language = [[NSLocale preferredLanguages] objectAtIndex:0]; |
54 | | - |
| 55 | + |
55 | 56 | CefString result = [language UTF8String]; |
56 | 57 | return result; |
57 | 58 | } |
58 | 59 |
|
59 | | -std::string ClientApp::GetExtensionJSSource() |
| 60 | +std::string GetExtensionJSSource() |
60 | 61 | { |
61 | 62 | std::string result; |
62 | | - |
| 63 | + |
63 | 64 | // This is a hack to grab the extension file from the main app resource bundle. |
64 | 65 | // This code may be run in a sub process in an app that is bundled inside the main app. |
65 | 66 | #if 1 |
66 | 67 | NSString* bundlePath = [[NSBundle mainBundle] bundlePath]; |
67 | 68 | NSString* sourcePath; |
68 | 69 | NSRange range = [bundlePath rangeOfString: @"/Frameworks/"]; |
69 | | - |
| 70 | + |
70 | 71 | if (range.location == NSNotFound) { |
71 | 72 | sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"]; |
72 | 73 | } else { |
|
76 | 77 | #else |
77 | 78 | NSString* sourcePath = [[NSBundle mainBundle] pathForResource: @"appshell_extensions" ofType: @"js"]; |
78 | 79 | #endif |
79 | | - |
| 80 | + |
80 | 81 | NSString* jsSource = [[NSString alloc] initWithContentsOfFile:sourcePath encoding:NSUTF8StringEncoding error:nil]; |
81 | 82 | result = [jsSource UTF8String]; |
82 | 83 | [jsSource release]; |
83 | | - |
| 84 | + |
84 | 85 | return result; |
85 | 86 | } |
86 | 87 |
|
| 88 | +CefString AppGetSupportDirectory() { |
| 89 | + NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; |
| 90 | + NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME]; |
87 | 91 |
|
88 | | -CefString ClientApp::AppGetSupportDirectory() { |
89 | | - NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; |
90 | | - NSString *supportDirectory = [NSString stringWithFormat:@"%@/%@%@", libraryDirectory, GROUP_NAME, APP_NAME]; |
91 | | - |
92 | | - return CefString([supportDirectory UTF8String]); |
| 92 | + return CefString([supportDirectory UTF8String]); |
93 | 93 | } |
94 | 94 |
|
95 | | -CefString ClientApp::AppGetDocumentsDirectory() { |
| 95 | +CefString AppGetDocumentsDirectory() { |
96 | 96 | NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; |
97 | 97 | return CefString([documentsDirectory UTF8String]); |
98 | 98 | } |
| 99 | + |
| 100 | +CefString AppGetCachePath() { |
| 101 | + std::string cachePath = std::string(AppGetSupportDirectory()) + "/cef_data"; |
| 102 | + |
| 103 | + return CefString(cachePath); |
| 104 | +} |
| 105 | + |
| 106 | +CefString AppGetProductVersionString() { |
| 107 | + NSMutableString *s = [NSMutableString stringWithString:APP_NAME]; |
| 108 | + [s replaceOccurrencesOfString:@" " |
| 109 | + withString:@"" |
| 110 | + options:NSLiteralSearch |
| 111 | + range:NSMakeRange(0, [s length])]; |
| 112 | + [s appendString:@"/"]; |
| 113 | + [s appendString:(NSString*)[[NSBundle mainBundle] |
| 114 | + objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]]; |
| 115 | + CefString result = CefString([s UTF8String]); |
| 116 | + return result; |
| 117 | +} |
| 118 | + |
| 119 | +CefString AppGetChromiumVersionString() { |
| 120 | + NSMutableString *s = [NSMutableString stringWithFormat:@"Chrome/%d.%d.%d.%d", |
| 121 | + cef_version_info(2), cef_version_info(3), |
| 122 | + cef_version_info(4), cef_version_info(5)]; |
| 123 | + CefString result = CefString([s UTF8String]); |
| 124 | + return result; |
| 125 | +} |
| 126 | + |
| 127 | +} // namespace appshell |
0 commit comments