Skip to content

Commit ecfe4e1

Browse files
author
Zuoyuan Huang
committed
Add warning message on auto update being turned off
1 parent b8c7f35 commit ecfe4e1

File tree

5 files changed

+138
-37
lines changed

5 files changed

+138
-37
lines changed

patched-vscode/extensions/sagemaker-extension/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727
"contributes": {
2828
"configuration": {
2929
"type": "object",
30-
"title": "Sagemaker Extension",
31-
"properties": {}
30+
"title": "SageMaker Extension",
31+
"properties": {
32+
"sagemaker-extension.notification.extensionAutoUpdateDisabled": {
33+
"type": "boolean",
34+
"default": true,
35+
"markdownDescription": "Show notification if extension auto update is disabled"
36+
}
37+
}
3238
},
3339
"commands": [
3440
]

patched-vscode/extensions/sagemaker-extension/src/extension.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import * as console from "console";
1717

1818

1919
const PARSE_SAGEMAKER_COOKIE_COMMAND = 'sagemaker.parseCookies';
20+
const ENABLE_AUTO_UPDATE_COMMAND = 'workbench.extensions.action.enableAutoUpdate';
2021

2122
function showWarningDialog() {
2223
vscode.commands.executeCommand(PARSE_SAGEMAKER_COOKIE_COMMAND).then(response => {
@@ -121,6 +122,37 @@ function updateStatusItemWithMetadata(context: vscode.ExtensionContext) {
121122
});
122123
}
123124

125+
// Render warning message regarding auto upgrade disabled
126+
function renderExtensionAutoUpgradeDisabledNotification() {
127+
// Get current extension auto disabled config
128+
const autoUpdateEnabled = vscode.workspace.getConfiguration('extensions').get('autoUpdate');
129+
130+
// Check if customer has choose to disable this notification
131+
const extensionConfig = vscode.workspace.getConfiguration('sagemaker-extension');
132+
const showNotificationEnabled = extensionConfig.get('notification.extensionAutoUpdateDisabled', true);
133+
134+
// Only show notification, if auto update is disabled, and customer hasn't opt-out the notification
135+
if (showNotificationEnabled && autoUpdateEnabled == false) {
136+
const enableAutoUpdate = 'Enable Auto Update Extensions';
137+
const doNotShowAgain = 'Do not show again';
138+
vscode.window.showInformationMessage(
139+
'Extension auto-update is disabled. This can be changed in Code Editor settings.',
140+
enableAutoUpdate,
141+
doNotShowAgain,
142+
).then(response => {
143+
if (response === enableAutoUpdate) {
144+
vscode.commands.executeCommand(ENABLE_AUTO_UPDATE_COMMAND)
145+
} else if (response == doNotShowAgain) {
146+
extensionConfig.update(
147+
'notification.extensionAutoUpdateDisabled',
148+
false,
149+
vscode.ConfigurationTarget.Global
150+
);
151+
}
152+
})
153+
}
154+
}
155+
124156
export function activate(context: vscode.ExtensionContext) {
125157

126158
// TODO: log activation of extension
@@ -134,4 +166,7 @@ export function activate(context: vscode.ExtensionContext) {
134166
initialize(sagemakerCookie);
135167
updateStatusItemWithMetadata(context);
136168
});
169+
170+
// render warning message regarding auto upgrade disabled
171+
renderExtensionAutoUpgradeDisabledNotification();
137172
}

patches/sagemaker-extension.diff

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
22
===================================================================
33
--- /dev/null
44
+++ sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension.ts
5-
@@ -0,0 +1,137 @@
5+
@@ -0,0 +1,172 @@
66
+import * as vscode from 'vscode';
77
+import * as fs from 'fs';
88
+import { SessionWarning } from "./sessionWarning";
@@ -22,6 +22,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
2222
+
2323
+
2424
+const PARSE_SAGEMAKER_COOKIE_COMMAND = 'sagemaker.parseCookies';
25+
+const ENABLE_AUTO_UPDATE_COMMAND = 'workbench.extensions.action.enableAutoUpdate';
2526
+
2627
+function showWarningDialog() {
2728
+ vscode.commands.executeCommand(PARSE_SAGEMAKER_COOKIE_COMMAND).then(response => {
@@ -126,6 +127,37 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
126127
+ });
127128
+}
128129
+
130+
+// Render warning message regarding auto upgrade disabled
131+
+function renderExtensionAutoUpgradeDisabledNotification() {
132+
+ // Get current extension auto disabled config
133+
+ const autoUpdateEnabled = vscode.workspace.getConfiguration('extensions').get('autoUpdate');
134+
+
135+
+ // Check if customer has choose to disable this notification
136+
+ const extensionConfig = vscode.workspace.getConfiguration('sagemaker-extension');
137+
+ const showNotificationEnabled = extensionConfig.get('notification.extensionAutoUpdateDisabled', true);
138+
+
139+
+ // Only show notification, if auto update is disabled, and customer hasn't opt-out the notification
140+
+ if (showNotificationEnabled && autoUpdateEnabled == false) {
141+
+ const enableAutoUpdate = 'Enable Auto Update Extensions';
142+
+ const doNotShowAgain = 'Do not show again';
143+
+ vscode.window.showInformationMessage(
144+
+ 'Extension auto-update is disabled. This can be changed in Code Editor settings.',
145+
+ enableAutoUpdate,
146+
+ doNotShowAgain,
147+
+ ).then(response => {
148+
+ if (response === enableAutoUpdate) {
149+
+ vscode.commands.executeCommand(ENABLE_AUTO_UPDATE_COMMAND)
150+
+ } else if (response == doNotShowAgain) {
151+
+ extensionConfig.update(
152+
+ 'notification.extensionAutoUpdateDisabled',
153+
+ false,
154+
+ vscode.ConfigurationTarget.Global
155+
+ );
156+
+ }
157+
+ })
158+
+ }
159+
+}
160+
+
129161
+export function activate(context: vscode.ExtensionContext) {
130162
+
131163
+ // TODO: log activation of extension
@@ -139,6 +171,9 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/extension
139171
+ initialize(sagemakerCookie);
140172
+ updateStatusItemWithMetadata(context);
141173
+ });
174+
+
175+
+ // render warning message regarding auto upgrade disabled
176+
+ renderExtensionAutoUpgradeDisabledNotification();
142177
+}
143178
Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/src/sessionWarning.ts
144179
===================================================================
@@ -211,7 +246,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
211246
===================================================================
212247
--- /dev/null
213248
+++ sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
214-
@@ -0,0 +1,46 @@
249+
@@ -0,0 +1,52 @@
215250
+{
216251
+ "name": "sagemaker-extension",
217252
+ "displayName": "Sagemaker Extension",
@@ -241,8 +276,14 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-extension/package.json
241276
+ "contributes": {
242277
+ "configuration": {
243278
+ "type": "object",
244-
+ "title": "Sagemaker Extension",
245-
+ "properties": {}
279+
+ "title": "SageMaker Extension",
280+
+ "properties": {
281+
+ "sagemaker-extension.notification.extensionAutoUpdateDisabled": {
282+
+ "type": "boolean",
283+
+ "default": true,
284+
+ "markdownDescription": "Show notification if extension auto update is disabled"
285+
+ }
286+
+ }
246287
+ },
247288
+ "commands": [
248289
+ ]

scripts/install.sh

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/bin/bash
22

3-
while getopts "v:" opt; do
4-
case $opt in
5-
v) version="$OPTARG"
6-
;;
7-
\?) echo "Invalid option -$OPTARG" >&2
8-
exit 1
9-
;;
10-
esac
3+
usage() {
4+
printf """
5+
Usage: $0 [-t <VERSION>] [-v] [-h]
6+
7+
Otions:
8+
-t <VERSION> Create a tarball with the specified version
9+
-v Enable verbose output
10+
-h Show this help message
11+
"""
12+
}
1113

12-
case $OPTARG in
13-
-*) echo "Option $opt needs a valid argument"
14-
exit 1
15-
;;
14+
while getopts "t:hv" opt; do
15+
case $opt in
16+
t) version="$OPTARG"
17+
CREATE_TARBALL=true ;;
18+
v) VERBOSE_ARG="--verbose" ;;
19+
h) usage; exit 0 ;;
20+
:) printf "Error: -${OPTARG} requires an argument.\n" >&2; exit 1 ;;
21+
?) usage; exit 1 ;;
1622
esac
1723
done
1824

19-
if [[ -z $version ]]; then
20-
echo "Please provide version using '-v'";
21-
exit 1
22-
fi
23-
2425
VERSION=$version
2526

2627
# set +e to prevent quilt from exiting when no patches popped
@@ -48,11 +49,11 @@ git submodule update --init
4849
# Apply patches
4950
printf "\n======== Applying patches ========\n"
5051
{
51-
quilt push -a --leave-rejects --color=auto
52+
quilt push -a --leave-rejects --color=auto
5253
} || {
53-
printf "\nPatching error, review logs!\n"
54-
find ./vscode -name "*.rej"
55-
exit 1
54+
printf "\nPatching error, review logs!\n"
55+
find ./vscode -name "*.rej"
56+
exit 1
5657
}
5758

5859

@@ -68,19 +69,25 @@ cd ${PROJ_ROOT}
6869
printf "\n======== Comment out breaking git config lines in postinstall.js ========\n"
6970
sh ${PROJ_ROOT}/scripts/postinstall.sh
7071

71-
# Build tarball for conda feedstock from vscode dir
72-
printf "\n======== Build Tarball for Conda Feedstock ========\n"
73-
bash ${PROJ_ROOT}/scripts/create_code_editor_tarball.sh -v ${VERSION}
72+
# Delete node_modules to prevent node-gyp build error and reduce tarball size
73+
printf "\n======== Deleting vscode/node_modules ========\n"
74+
find "${PROJ_ROOT}/vscode" -name "node_modules" -type d -prune -exec rm -rf '{}' +
75+
76+
# Create tarball
77+
if [ "$CREATE_TARBALL" = true ]; then
78+
# Build tarball for conda feedstock from vscode dir
79+
printf "\n======== Build Tarball for Conda Feedstock ========\n"
80+
bash ${PROJ_ROOT}/scripts/create_code_editor_tarball.sh -v ${VERSION}
81+
fi
7482

7583
# Copy resources
7684
printf "\n======== Copy resources ========\n"
77-
sh ${PROJ_ROOT}/scripts/copy-resources.sh
85+
${PROJ_ROOT}/scripts/copy-resources.sh
7886

79-
# Delete node_modules to prevent node-gyp build error
80-
printf "\n======== Deleting vscode/node_modules ========\n"
81-
rm -rf "${PROJ_ROOT}/vscode/node_modules"
87+
# Copy patched files to patches-vscode
88+
cp -R vscode/* patched-vscode/
8289

8390
# Build the project
8491
printf "\n======== Building project in ${PROJ_ROOT}/vscode ========\n"
85-
yarn --cwd "${PROJ_ROOT}/vscode" install --pure-lockfile --verbose
92+
yarn --cwd "${PROJ_ROOT}/vscode" install --pure-lockfile ${VERBOSE_ARG}
8693
yarn --cwd "${PROJ_ROOT}/vscode" download-builtin-extensions

scripts/postinstall.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ if [ ! -f "$POSTINSTALL_JS_PATH" ]; then
1515
exit 1
1616
fi
1717

18-
# Use sed to comment out the specific lines
19-
sed -i '' '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
18+
# set +e to prevent script from exiting when not on macOS
19+
set +e
20+
21+
# Check if on macOS
22+
system_profiler SPSoftwareDataType
23+
24+
# Run with different arguments depending on the OS
25+
if [ $? -eq 0 ]; then
26+
# Use sed to comment out the specific lines
27+
sed -i '' '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
28+
else
29+
# Use sed to comment out the specific lines
30+
sed -i '/cp\.execSync('"'"'git config .*);/s/^/\/\/ /' "$POSTINSTALL_JS_PATH"
31+
fi
2032

2133
echo "Specified git config lines have been commented out in $POSTINSTALL_JS_PATH."

0 commit comments

Comments
 (0)