@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import { app , autoUpdater , desktopCapturer , ipcMain , powerSaveBlocker } from "electron" ;
17
+ import { app , autoUpdater , desktopCapturer , ipcMain , powerSaveBlocker , TouchBar , nativeImage } from "electron" ;
18
18
import { relaunchApp } from "electron-clear-data" ;
19
19
20
20
import IpcMainEvent = Electron . IpcMainEvent ;
@@ -194,6 +194,56 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
194
194
relaunchApp ( ) ;
195
195
break ;
196
196
197
+ case "breadcrumbs" : {
198
+ if ( process . platform === "darwin" ) {
199
+ const { TouchBarPopover, TouchBarButton } = TouchBar ;
200
+
201
+ const recentsBar = new TouchBar ( {
202
+ items : args [ 0 ] . map ( ( r : { roomId : string ; avatarUrl : string | null ; initial : string } ) => {
203
+ const defaultColors = [ "#0DBD8B" , "#368bd6" , "#ac3ba8" ] ;
204
+ let total = 0 ;
205
+ for ( let i = 0 ; i < r . roomId . length ; ++ i ) {
206
+ total += r . roomId . charCodeAt ( i ) ;
207
+ }
208
+
209
+ const button = new TouchBarButton ( {
210
+ label : r . initial ,
211
+ backgroundColor : defaultColors [ total % defaultColors . length ] ,
212
+ click : ( ) : void => {
213
+ global . mainWindow ?. loadURL ( `vector://vector/webapp/#/room/${ r . roomId } ` ) ;
214
+ } ,
215
+ } ) ;
216
+ if ( r . avatarUrl ) {
217
+ fetch ( r . avatarUrl )
218
+ . then ( ( resp ) => {
219
+ if ( ! resp . ok ) return ;
220
+ return resp . arrayBuffer ( ) ;
221
+ } )
222
+ . then ( ( arrayBuffer ) => {
223
+ const buffer = Buffer . from ( arrayBuffer ! ) ;
224
+ button . icon = nativeImage . createFromBuffer ( buffer ) ;
225
+ button . label = "" ;
226
+ button . backgroundColor = "" ;
227
+ } ) ;
228
+ }
229
+ return button ;
230
+ } ) ,
231
+ } ) ;
232
+
233
+ const touchBar = new TouchBar ( {
234
+ items : [
235
+ new TouchBarPopover ( {
236
+ label : "Recents" ,
237
+ showCloseButton : true ,
238
+ items : recentsBar ,
239
+ } ) ,
240
+ ] ,
241
+ } ) ;
242
+ global . mainWindow . setTouchBar ( touchBar ) ;
243
+ }
244
+ break ;
245
+ }
246
+
197
247
default :
198
248
global . mainWindow . webContents . send ( "ipcReply" , {
199
249
id : payload . id ,
0 commit comments