- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathaccount.ts
155 lines (145 loc) · 5.24 KB
/
account.ts
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import{FrontendApplication}from'@theia/core/lib/browser/frontend-application';
import{SidebarMenu}from'@theia/core/lib/browser/shell/sidebar-menu-widget';
import{WindowService}from'@theia/core/lib/browser/window/window-service';
import{DisposableCollection}from'@theia/core/lib/common/disposable';
import{MenuPath}from'@theia/core/lib/common/menu';
import{nls}from'@theia/core/lib/common/nls';
import{inject,injectable}from'@theia/core/shared/inversify';
import{CloudUserCommands,LEARN_MORE_URL}from'../auth/cloud-user-commands';
import{CreateFeatures}from'../create/create-features';
import{ArduinoMenus}from'../menu/arduino-menus';
import{ApplicationConnectionStatusContribution}from'../theia/core/connection-status-service';
import{
Command,
CommandRegistry,
Contribution,
MenuModelRegistry,
}from'./contribution';
exportconstaccountMenu: SidebarMenu={
id: 'arduino-accounts-menu',
iconClass: 'codicon codicon-account',
title: nls.localize('arduino/account/menuTitle','Arduino Cloud'),
menuPath: ArduinoMenus.ARDUINO_ACCOUNT__CONTEXT,
order: 0,
};
@injectable()
exportclassAccountextendsContribution{
@inject(WindowService)
privatereadonlywindowService: WindowService;
@inject(CreateFeatures)
privatereadonlycreateFeatures: CreateFeatures;
@inject(ApplicationConnectionStatusContribution)
privatereadonlyconnectionStatus: ApplicationConnectionStatusContribution;
privatereadonlytoDispose=newDisposableCollection();
privateapp: FrontendApplication;
overrideonStart(app: FrontendApplication): void{
this.app=app;
this.updateSidebarCommand();
this.toDispose.push(
this.createFeatures.onDidChangeEnabled((enabled)=>
this.updateSidebarCommand(enabled)
)
);
}
onStop(): void{
this.toDispose.dispose();
}
overrideregisterCommands(registry: CommandRegistry): void{
constopenExternal=(url: string)=>
this.windowService.openNewWindow(url,{external: true});
constloggedIn=()=>Boolean(this.createFeatures.session);
constloggedInWithInternetConnection=()=>
loggedIn()&&this.connectionStatus.offlineStatus!=='internet';
registry.registerCommand(Account.Commands.LEARN_MORE,{
execute: ()=>openExternal(LEARN_MORE_URL),
isEnabled: ()=>!loggedIn(),
isVisible: ()=>!loggedIn(),
});
registry.registerCommand(Account.Commands.GO_TO_PROFILE,{
execute: ()=>openExternal('https://id.arduino.cc/'),
isEnabled: ()=>loggedInWithInternetConnection(),
isVisible: ()=>loggedIn(),
});
registry.registerCommand(Account.Commands.GO_TO_CLOUD_EDITOR,{
execute: ()=>openExternal('https://create.arduino.cc/editor'),
isEnabled: ()=>loggedInWithInternetConnection(),
isVisible: ()=>loggedIn(),
});
registry.registerCommand(Account.Commands.GO_TO_IOT_CLOUD,{
execute: ()=>openExternal('https://create.arduino.cc/iot/'),
isEnabled: ()=>loggedInWithInternetConnection(),
isVisible: ()=>loggedIn(),
});
}
overrideregisterMenus(registry: MenuModelRegistry): void{
constregister=(
menuPath: MenuPath,
...commands: (Command|[command: Command,menuLabel: string])[]
)=>
commands.forEach((command,index)=>{
constcommandId=Array.isArray(command) ? command[0].id : command.id;
constlabel=Array.isArray(command) ? command[1] : command.label;
registry.registerMenuAction(menuPath,{
label,
commandId,
order: String(index),
});
});
register(ArduinoMenus.ARDUINO_ACCOUNT__CONTEXT__SIGN_IN_GROUP,[
CloudUserCommands.LOGIN,
nls.localize('arduino/cloud/signInToCloud','Sign in to Arduino Cloud'),
]);
register(ArduinoMenus.ARDUINO_ACCOUNT__CONTEXT__LEARN_MORE_GROUP,[
Account.Commands.LEARN_MORE,
nls.localize('arduino/cloud/learnMore','Learn more'),
]);
register(
ArduinoMenus.ARDUINO_ACCOUNT__CONTEXT__GO_TO_GROUP,
[
Account.Commands.GO_TO_PROFILE,
nls.localize('arduino/account/goToProfile','Go to Profile'),
],
[
Account.Commands.GO_TO_CLOUD_EDITOR,
nls.localize('arduino/account/goToCloudEditor','Go to Cloud Editor'),
],
[
Account.Commands.GO_TO_IOT_CLOUD,
nls.localize('arduino/account/goToIoTCloud','Go to IoT Cloud'),
]
);
register(
ArduinoMenus.ARDUINO_ACCOUNT__CONTEXT__SIGN_OUT_GROUP,
CloudUserCommands.LOGOUT
);
}
privateupdateSidebarCommand(
visible: boolean=this.preferences['arduino.cloud.enabled']
): void{
if(!this.app){
return;
}
consthandler=this.app.shell.leftPanelHandler;
if(visible){
handler.addBottomMenu(accountMenu);
}else{
handler.removeBottomMenu(accountMenu.id);
}
}
}
exportnamespaceAccount{
exportnamespaceCommands{
exportconstGO_TO_PROFILE: Command={
id: 'arduino-go-to-profile',
};
exportconstGO_TO_CLOUD_EDITOR: Command={
id: 'arduino-go-to-cloud-editor',
};
exportconstGO_TO_IOT_CLOUD: Command={
id: 'arduino-go-to-iot-cloud',
};
exportconstLEARN_MORE: Command={
id: 'arduino-learn-more',
};
}
}