forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
112 lines (102 loc) · 3.2 KB
/
utils.ts
File metadata and controls
112 lines (102 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import _debug from '../../utils/debug';
import hash from '../hash';
export const ANONYMOUS_UID_KEY = 'codesandbox-anonymous-uid';
export const debug = _debug('cs:analytics');
export const global = (typeof window !== 'undefined' ? window : {}) as any;
export function getHashedUserId(userId: string) {
return hash(userId);
}
export const WHITELISTED_VSCODE_EVENTS = [
'codesandbox.preview.toggle',
'workbench.action.splitEditor',
'workbench.action.toggleSidebarVisibility',
'codesandbox.sandbox.new',
'workbench.action.files.saveAs',
'editor.action.addCommentLine',
'codesandbox.sandbox.exportZip',
'codesandbox.preferences',
'codesandbox.sandbox.fork',
'codesandbox.help.documentation',
'codesandbox.help.github',
'view.preview.flip',
'codesandbox.search',
'workbench.action.splitEditorLeft',
'codesandbox.dashboard',
'workbench.action.toggleCenteredLayout',
'workbench.action.toggleMenuBar',
'codesandbox.explore',
'editor.action.toggleTabFocusMode',
'workbench.action.splitEditorUp',
'workbench.action.toggleSidebarPosition',
'workbench.action.toggleActivityBarVisibility',
'workbench.action.toggleStatusbarVisibility',
'codesandbox.dependencies.add',
'codesandbox.help.open-issue',
'codesandbox.action.search',
'workbench.action.editorLayoutThreeColumns',
'breadcrumbs.toggleToOn',
'workbench.action.openSettings2',
'workbench.action.globalSettings',
'workbench.action.editorLayoutTwoRows',
'workbench.action.editorLayoutTwoByTwoGrid',
'editor.action.showContextMenu',
'toggleVim',
'codesandbox.help.spectrum',
'codesandbox.help.feedback',
'workbench.action.webview.openDeveloperTools',
'workbench.action.editorLayoutThreeRows',
'codesandbox.help.twitter',
'workbench.action.editorLayoutTwo',
'codesandbox.preview.external',
'notifications.showList',
'workbench.action.editor.changeEncoding',
'editor.action.indentationToTabs',
'workbench.action.maximizeEditor',
'editor.action.indentationToSpaces',
'revealFilesInOS',
'keybindings.editor.searchKeyBindings',
'notifications.hideList',
'workbench.action.terminal.focus',
'workbench.action.console.focus',
'workbench.action.openRecent',
'code-runner.run',
];
const isDoNotTrackEnabled = () => {
try {
if (typeof window !== 'undefined') {
let localStorageValue = true;
try {
localStorageValue =
typeof localStorage !== 'undefined' &&
localStorage.getItem('DO_NOT_TRACK_ENABLED') === 'true';
} catch (e) {
/* ignore */
}
return Boolean(
// @ts-ignore
global.doNotTrack === '1' ||
// @ts-ignore
global.navigator.doNotTrack === '1' ||
// @ts-ignore
global.navigator.msDoNotTrack === '1' ||
localStorageValue ||
process.env.NODE_ENV === 'development' ||
process.env.STAGING
);
}
return true;
} catch (e) {
return false;
}
};
export const DO_NOT_TRACK_ENABLED = isDoNotTrackEnabled();
export const isAllowedEvent = (eventName, secondArg) => {
try {
if (eventName === 'VSCode - workbenchActionExecuted') {
return WHITELISTED_VSCODE_EVENTS.includes(secondArg.id);
}
return true;
} catch (e) {
return true;
}
};