Skip to content

Commit 33464fe

Browse files
committed
* #RIVS-258 - Change analytics page text for vscode
* #RIVS-245 - [Regression] Cli does not connect to the database when opened for the first time * #RIVS-247 - [Regression] Invalid database is displayed for some period of time after installing the extension
1 parent 0365f07 commit 33464fe

File tree

35 files changed

+217
-113
lines changed

35 files changed

+217
-113
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ RI_STDOUT_LOGGER=false
1414
RI_AUTO_BOOTSTRAP=false
1515
RI_MIGRATE_OLD_FOLDERS=false
1616
RI_BUILD_TYPE='VS_CODE'
17+
RI_ENCRYPTION_KEYTAR=false
18+
RI_AGREEMENTS_PATH='../../webviews/resources/agreements-spec.json'
1719
# RI_SEGMENT_WRITE_KEY='SEGMENT_WRITE_KEY'

l10n/bundle.l10n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"To optimize your experience, Redis for VS Code uses third-party tools.\n All data collected is anonymized and will not be used for any purpose without your consent.": "To optimize your experience, Redis for VS Code uses third-party tools.\n All data collected is anonymized and will not be used for any purpose without your consent.",
9292
"To use Redis for VS Code, please accept the terms and conditions: ": "To use Redis for VS Code, please accept the terms and conditions: ",
9393
"Server Side Public License": "Server Side Public License",
94-
"Notice: To avoid automatic execution of malicious code, when adding new Workbench plugins, use files from trusted authors only.": "Notice: To avoid automatic execution of malicious code, when adding new Workbench plugins, use files from trusted authors only.",
9594
"Add Redis database": "Add Redis database",
9695
"Edit Redis database": "Edit Redis database",
9796
"Members": "Members",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "redis-for-vscode",
33
"version": "0.0.3",
44
"displayName": "Redis for VS Code",
5-
"description": "Visually interact with data and build queries in Redi",
5+
"description": "Visually interact with data and build queries in Redis",
66
"license": "SEE LICENSE IN LICENSE",
77
"main": "dist/extension.js",
88
"l10n": "./l10n",

src/WebViewProvider.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { getNonce, handleMessage } from './utils'
3-
import { workspaceStateService } from './lib'
3+
import { getUIStorage } from './lib'
44

55
export class WebViewProvider implements vscode.WebviewViewProvider {
66
_doc?: vscode.TextDocument
@@ -52,8 +52,7 @@ export class WebViewProvider implements vscode.WebviewViewProvider {
5252
)
5353
const viewRoute = this._route
5454

55-
const appPort = workspaceStateService.get('appPort')
56-
const appInfo = workspaceStateService.get('appInfo')
55+
const uiStorage = getUIStorage()
5756

5857
// Use a nonce to only allow a specific script to be run.
5958
const nonce = getNonce()
@@ -79,8 +78,7 @@ export class WebViewProvider implements vscode.WebviewViewProvider {
7978
<meta http-equiv="Content-Security-Policy" content="${contentSecurity.join(';')}">
8079
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8180
<script nonce="${nonce}">
82-
window.appPort=${appPort};
83-
window.appInfo=${JSON.stringify(appInfo)};
81+
window.ri=${JSON.stringify(uiStorage)};
8482
</script>
8583
</head>
8684
<body>

src/Webview.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode'
22
import { getNonce, handleMessage } from './utils'
3-
import { workspaceStateService } from './lib'
3+
import { getUIStorage } from './lib'
44

55
type WebviewOptions = {
66
context?: vscode.ExtensionContext
@@ -35,11 +35,13 @@ abstract class Webview {
3535
}
3636
}
3737

38-
protected getWebviewOptions(): vscode.WebviewOptions {
38+
protected getWebviewOptions(): vscode.WebviewPanelOptions & vscode.WebviewOptions {
3939
return {
4040
// Enable javascript in the webview
4141
enableScripts: true,
4242

43+
retainContextWhenHidden: true,
44+
4345
// And restrict the webview to only loading content from our extension's `dist` directory.
4446
localResourceRoots: [vscode.Uri.joinPath(this._opts.context?.extensionUri as vscode.Uri, 'dist')],
4547
}
@@ -54,8 +56,7 @@ abstract class Webview {
5456
const scriptUri = webview.asWebviewUri(this._opts.scriptUri as vscode.Uri)
5557
const styleUri = webview.asWebviewUri(this._opts.styleUri as vscode.Uri)
5658

57-
const appInfo = workspaceStateService.get('appInfo')
58-
const appPort = workspaceStateService.get('appPort')
59+
const uiStorage = getUIStorage()
5960

6061
const contentSecurity = [
6162
`img-src ${webview.cspSource} 'self' data:`,
@@ -88,8 +89,7 @@ abstract class Webview {
8889
<link href="${styleUri}" rel="stylesheet" />
8990
<script nonce="${this._opts.nonce}">
9091
window.acquireVsCodeApi = acquireVsCodeApi;
91-
window.appPort=${appPort};
92-
window.appInfo=${JSON.stringify(appInfo)};
92+
window.ri=${JSON.stringify(uiStorage)};
9393
</script>
9494
9595
<title>Redis for VS Code Webview</title>
@@ -129,6 +129,9 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
129129
if (opts.message) {
130130
instance.panel.webview.postMessage(opts.message)
131131
}
132+
if (opts.title) {
133+
instance.panel.title = opts.title
134+
}
132135
} else {
133136
// Otherwise, create an instance
134137
instance = new WebviewPanel(options)
@@ -148,12 +151,8 @@ export class WebviewPanel extends Webview implements vscode.Disposable {
148151
this.getWebviewOptions(),
149152
)
150153

151-
// todo: connection between webviews
152-
if (opts.message) {
153-
await this.panel.webview.postMessage(opts.message)
154-
}
155154
// Update the content
156-
this.update()
155+
this.update(opts)
157156

158157
// Listen for when the panel is disposed
159158
// This happens when the user closes the panel or when the panel is closed programmatically

src/extension.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path'
44
import { WebviewPanel } from './Webview'
55
import { startBackend, getBackendGracefulShutdown } from './server/bootstrapBackend'
66
import { startBackendE2E } from './server/bootstrapBackendE2E'
7-
import { checkVersionUpdate, initWorkspaceState } from './lib'
7+
import { checkVersionUpdate, initWorkspaceState, setUIStorageField } from './lib'
88
import { WebViewProvider } from './WebViewProvider'
99
import { handleMessage, truncateText } from './utils'
1010
import { MAX_TITLE_KEY_LENGTH, ViewId } from './constants'
@@ -48,16 +48,21 @@ export async function activate(context: vscode.ExtensionContext) {
4848
vscode.window.registerWebviewViewProvider('ri-sidebar', sidebarProvider),
4949
vscode.window.registerWebviewViewProvider('ri-panel', panelProvider, { webviewOptions: { retainContextWhenHidden: true } }),
5050

51-
vscode.commands.registerCommand('RedisForVSCode.addCli', (args) => {
51+
vscode.commands.registerCommand('RedisForVSCode.addCli', async (args) => {
52+
await setUIStorageField('database', args.data?.database)
53+
5254
vscode.commands.executeCommand('setContext', 'RedisForVSCode.showCliPanel', true)
5355
vscode.commands.executeCommand('ri-panel.focus')
54-
setTimeout(() => {
55-
panelProvider.view?.webview.postMessage({ action: 'AddCli', data: args.data })
56-
}, 100)
56+
57+
panelProvider.view?.webview.postMessage({ action: 'AddCli', data: args.data })
5758
}),
5859

59-
vscode.commands.registerCommand('RedisForVSCode.openKey', (args) => {
60-
const title = `${args?.data?.displayedKeyType?.toLowerCase()}:${truncateText(args?.data?.keyString, MAX_TITLE_KEY_LENGTH)}`
60+
vscode.commands.registerCommand('RedisForVSCode.openKey', async (args) => {
61+
const keyInfo = args.data?.keyInfo
62+
const title = `${keyInfo?.displayedKeyType?.toLowerCase()}:${truncateText(keyInfo?.keyString, MAX_TITLE_KEY_LENGTH)}`
63+
64+
await setUIStorageField('keyInfo', keyInfo)
65+
await setUIStorageField('database', args.data?.database)
6166

6267
WebviewPanel.getInstance({
6368
context,
@@ -66,10 +71,12 @@ export async function activate(context: vscode.ExtensionContext) {
6671
viewId: ViewId.Key,
6772
// todo: connection between webviews
6873
message: args,
69-
})?.update({ title })
74+
})
7075
}),
7176

72-
vscode.commands.registerCommand('RedisForVSCode.addKeyOpen', (args) => {
77+
vscode.commands.registerCommand('RedisForVSCode.addKeyOpen', async (args) => {
78+
await setUIStorageField('database', args.data?.database)
79+
7380
WebviewPanel.getInstance({
7481
context,
7582
route: 'main/add_key',

src/lib/workspace/workspaceState.ts

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class WorkspaceStateService {
2525
}
2626

2727
async remove(key: string = '') {
28-
await this.context.workspaceState.update(key, null)
28+
await this.context.workspaceState.update(key, undefined)
2929
}
3030

3131
getAll() {
@@ -37,8 +37,49 @@ export const initWorkspaceState = async (context: vscode.ExtensionContext) => {
3737
workspaceStateService = new WorkspaceStateService(context)
3838

3939
// clear app cache
40-
await workspaceStateService.remove('appPort')
41-
await workspaceStateService.remove('appInfo')
40+
await workspaceStateService.set('ui', {})
41+
}
42+
43+
export const getObjectStorageField = (itemName = '', field = '') => {
44+
try {
45+
return (workspaceStateService?.get(itemName) as any)?.[field]
46+
} catch (e) {
47+
return null
48+
}
49+
}
50+
51+
export const setObjectStorageField = async (itemName = '', field = '', value?: any) => {
52+
try {
53+
const config: Config = workspaceStateService?.get(itemName) || {}
54+
55+
if (value === undefined) {
56+
delete config[field]
57+
58+
await workspaceStateService?.set(itemName, config)
59+
return
60+
}
61+
62+
await workspaceStateService?.set(itemName, {
63+
...config,
64+
[field]: value,
65+
})
66+
} catch (e) {
67+
console.error(e)
68+
}
69+
}
70+
71+
interface Config {
72+
[key: string]: any;
73+
}
74+
75+
export const getUIStorage = () =>
76+
workspaceStateService?.get('ui') || {}
77+
78+
export const getUIStorageField = (field: string = '') =>
79+
getObjectStorageField('ui', field)
80+
81+
export const setUIStorageField = async (field: string = '', value?: any) => {
82+
await setObjectStorageField('ui', field, value)
4283
}
4384

4485
// eslint-disable-next-line import/no-mutable-exports

src/resources/agreements-spec.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"version": "1.0.1",
3+
"agreements": {
4+
"analytics": {
5+
"defaultValue": false,
6+
"displayInSetting": true,
7+
"required": false,
8+
"editable": true,
9+
"disabled": false,
10+
"category": "privacy",
11+
"since": "1.0.1",
12+
"title": "Analytics",
13+
"label": "Enable Analytics",
14+
"description": "Select to help us make Redis for VS Code better. We aggregate anonymized user experience data and use it to fix bugs and improve experience for all users."
15+
},
16+
"notifications": {
17+
"defaultValue": false,
18+
"displayInSetting": true,
19+
"required": false,
20+
"editable": true,
21+
"disabled": false,
22+
"category": "notifications",
23+
"since": "1.0.1",
24+
"title": "Notification",
25+
"label": "Show notification",
26+
"description": "Select to display notification. Otherwise, notifications are shown in the Notification Center."
27+
},
28+
"eula": {
29+
"defaultValue": false,
30+
"displayInSetting": false,
31+
"required": true,
32+
"editable": false,
33+
"disabled": false,
34+
"since": "1.0.1",
35+
"title": "Server Side Public License",
36+
"label": "I have read and understood the Terms",
37+
"requiredText": "Accept the Server Side Public License"
38+
}
39+
}
40+
}

src/server/bootstrapBackend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as vscode from 'vscode'
22
import * as getPort from 'detect-port'
33
import * as path from 'path'
44
import * as fs from 'fs'
5-
import { workspaceStateService } from '../lib'
5+
import { setUIStorageField } from '../lib'
66
import { CustomLogger } from '../logger'
77
import { sleep } from '../utils'
88

@@ -17,7 +17,7 @@ export async function startBackend(logger: CustomLogger): Promise<any> {
1717
const port = await (await getPort.default(+appPort!)).toString()
1818
logger.log(`Starting at port: ${port}`)
1919

20-
workspaceStateService.set('appPort', port)
20+
await setUIStorageField('appPort', port)
2121

2222
if (!fs.existsSync(backendPath)) {
2323
const errorMessage = 'Can\'t find api folder. Please run "yarn download:backend" command'

src/server/bootstrapBackendE2E.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path'
55
import * as cp from 'child_process'
66
import * as fs from 'fs'
77
import { ChildProcessWithoutNullStreams } from 'child_process'
8-
import { workspaceStateService } from '../lib'
8+
import { setUIStorageField } from '../lib'
99
import { CustomLogger } from '../logger'
1010

1111
dotenv.config({ path: path.join(__dirname, '..', '..', '.env') })
@@ -25,7 +25,7 @@ export async function startBackendE2E(logger: CustomLogger): Promise<any> {
2525
const port = await (await getPort.default(+appPort!)).toString()
2626
logger.log(`Starting at port: ${port}`)
2727

28-
workspaceStateService.set('appPort', port)
28+
await setUIStorageField('appPort', port)
2929

3030
return new Promise((resolve) => {
3131
const backendSrcPath = path.join(backendPath, 'main.js')

0 commit comments

Comments
 (0)