aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Vijay A <avijayr@protonmail.com>2021-08-16 23:13:06 +0530
committerLibravatar Vijay A <avijayr@protonmail.com>2021-08-16 23:13:06 +0530
commitbbed06e2ba255199703343625129712ef7707697 (patch)
tree19a525fbd1d621a6e561b1a687195269e54f43d5 /src
parentchore: update outdated node_modules (#1807) (diff)
downloadferdium-app-bbed06e2ba255199703343625129712ef7707697.tar.gz
ferdium-app-bbed06e2ba255199703343625129712ef7707697.tar.zst
ferdium-app-bbed06e2ba255199703343625129712ef7707697.zip
Revert "chore: update outdated node_modules (#1807)"
Diffstat (limited to 'src')
-rw-r--r--src/electron/macOSPermissions.js9
-rw-r--r--src/helpers/userAgent-helpers.ts11
-rw-r--r--src/internal-server/app/Controllers/Http/ServiceController.js6
-rw-r--r--src/internal-server/app/Controllers/Http/UserController.js178
-rw-r--r--src/internal-server/app/Controllers/Http/WorkspaceController.js57
-rw-r--r--src/lib/Tray.js55
-rw-r--r--src/webview/notifications.js19
7 files changed, 145 insertions, 190 deletions
diff --git a/src/electron/macOSPermissions.js b/src/electron/macOSPermissions.js
index fc2f9b72d..887af2903 100644
--- a/src/electron/macOSPermissions.js
+++ b/src/electron/macOSPermissions.js
@@ -1,17 +1,14 @@
1import { systemPreferences, dialog } from 'electron'; 1import { systemPreferences, dialog } from 'electron';
2import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra'; 2import { pathExistsSync, mkdirSync, writeFileSync } from 'fs-extra';
3import { isMacOSVersionGreaterThanOrEqualTo } from 'macos-version'; 3import macosVersion from 'macos-version';
4import { dirname } from 'path'; 4import { dirname } from 'path';
5import { askForScreenCaptureAccess } from 'node-mac-permissions'; 5import { askForScreenCaptureAccess } from 'node-mac-permissions';
6import { userDataPath } from '../environment'; 6import { userDataPath } from '../environment';
7 7
8const debug = require('debug')('Ferdi:macOSPermissions'); 8const debug = require('debug')('Ferdi:macOSPermissions');
9 9
10const isExplicitScreenCapturePermissionReqd = 10const isExplicitScreenCapturePermissionReqd = macosVersion.isGreaterThanOrEqualTo('10.15');
11 isMacOSVersionGreaterThanOrEqualTo('10.15'); 11debug(`Should check explicitly for screen-capture permissions: ${isExplicitScreenCapturePermissionReqd}`);
12debug(
13 `Should check explicitly for screen-capture permissions: ${isExplicitScreenCapturePermissionReqd}`,
14);
15 12
16const filePath = userDataPath('.has-app-requested-screen-capture-permissions'); 13const filePath = userDataPath('.has-app-requested-screen-capture-permissions');
17 14
diff --git a/src/helpers/userAgent-helpers.ts b/src/helpers/userAgent-helpers.ts
index dea49ad7e..73c8bfd03 100644
--- a/src/helpers/userAgent-helpers.ts
+++ b/src/helpers/userAgent-helpers.ts
@@ -1,17 +1,12 @@
1import os from 'os'; 1import os from 'os';
2import { macOSVersion } from 'macos-version'; 2import macosVersion from 'macos-version';
3import { chrome } from 'useragent-generator'; 3import { chrome } from 'useragent-generator';
4import { 4import {
5 chromeVersion, 5 chromeVersion, isMac, isWindows, is64Bit, osArch, osRelease,
6 isMac,
7 isWindows,
8 is64Bit,
9 osArch,
10 osRelease,
11} from '../environment'; 6} from '../environment';
12 7
13function macOS() { 8function macOS() {
14 const version = macOSVersion() || ''; 9 const version = macosVersion() || '';
15 let cpuName = os.cpus()[0].model.split(' ')[0]; 10 let cpuName = os.cpus()[0].model.split(' ')[0];
16 if (cpuName && cpuName.match(/\(/)) { 11 if (cpuName && cpuName.match(/\(/)) {
17 cpuName = cpuName.split('(')[0]; 12 cpuName = cpuName.split('(')[0];
diff --git a/src/internal-server/app/Controllers/Http/ServiceController.js b/src/internal-server/app/Controllers/Http/ServiceController.js
index dea5a888e..c76a287f7 100644
--- a/src/internal-server/app/Controllers/Http/ServiceController.js
+++ b/src/internal-server/app/Controllers/Http/ServiceController.js
@@ -2,7 +2,7 @@ const Service = use('App/Models/Service');
2const { validateAll } = use('Validator'); 2const { validateAll } = use('Validator');
3const Env = use('Env'); 3const Env = use('Env');
4 4
5const { v4: uuid } = require('uuid'); 5const uuid = require('uuid/v4');
6const path = require('path'); 6const path = require('path');
7const fs = require('fs-extra'); 7const fs = require('fs-extra');
8const { LOCAL_HOSTNAME } = require('../../../../config'); 8const { LOCAL_HOSTNAME } = require('../../../../config');
@@ -156,7 +156,9 @@ class ServiceController {
156 id, 156 id,
157 name: service.name, 157 name: service.name,
158 ...newSettings, 158 ...newSettings,
159 iconUrl: `http://${hostname}:${port}/v1/icon/${newSettings.iconId}`, 159 iconUrl: `http://${hostname}:${port}/v1/icon/${
160 newSettings.iconId
161 }`,
160 userId: 1, 162 userId: 1,
161 }, 163 },
162 status: ['updated'], 164 status: ['updated'],
diff --git a/src/internal-server/app/Controllers/Http/UserController.js b/src/internal-server/app/Controllers/Http/UserController.js
index e387e39c4..a3ad736fa 100644
--- a/src/internal-server/app/Controllers/Http/UserController.js
+++ b/src/internal-server/app/Controllers/Http/UserController.js
@@ -1,38 +1,41 @@
1const User = use('App/Models/User'); 1const User = use('App/Models/User');
2const Service = use('App/Models/Service'); 2const Service = use('App/Models/Service');
3const Workspace = use('App/Models/Workspace'); 3const Workspace = use('App/Models/Workspace');
4const { validateAll } = use('Validator'); 4const {
5 validateAll,
6} = use('Validator');
5 7
6const btoa = require('btoa'); 8const btoa = require('btoa');
7const fetch = require('node-fetch'); 9const fetch = require('node-fetch');
8const { v4: uuid } = require('uuid'); 10const uuid = require('uuid/v4');
9const crypto = require('crypto'); 11const crypto = require('crypto');
10const { DEFAULT_APP_SETTINGS } = require('../../../../environment'); 12const { DEFAULT_APP_SETTINGS } = require('../../../../environment');
11 13
12const apiRequest = (url, route, method, auth) => 14const apiRequest = (url, route, method, auth) => new Promise((resolve, reject) => {
13 new Promise((resolve, reject) => { 15 const base = `${url}/v1/`;
14 const base = `${url}/v1/`; 16 const user = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36';
15 const user =
16 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36';
17 17
18 try { 18 try {
19 fetch(base + route, { 19 fetch(base + route, {
20 method, 20 method,
21 headers: { 21 headers: {
22 Authorization: `Bearer ${auth}`, 22 Authorization: `Bearer ${auth}`,
23 'User-Agent': user, 23 'User-Agent': user,
24 }, 24 },
25 }) 25 })
26 .then(data => data.json()) 26 .then(data => data.json())
27 .then(json => resolve(json)); 27 .then(json => resolve(json));
28 } catch (e) { 28 } catch (e) {
29 reject(); 29 reject();
30 } 30 }
31 }); 31});
32 32
33class UserController { 33class UserController {
34 // Register a new user 34 // Register a new user
35 async signup({ request, response }) { 35 async signup({
36 request,
37 response,
38 }) {
36 // Validate user input 39 // Validate user input
37 const validation = await validateAll(request.all(), { 40 const validation = await validateAll(request.all(), {
38 firstname: 'required', 41 firstname: 'required',
@@ -49,13 +52,15 @@ class UserController {
49 52
50 return response.send({ 53 return response.send({
51 message: 'Successfully created account', 54 message: 'Successfully created account',
52 token: 55 token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M',
53 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M',
54 }); 56 });
55 } 57 }
56 58
57 // Login using an existing user 59 // Login using an existing user
58 async login({ request, response }) { 60 async login({
61 request,
62 response,
63 }) {
59 if (!request.header('Authorization')) { 64 if (!request.header('Authorization')) {
60 return response.status(401).send({ 65 return response.status(401).send({
61 message: 'Please provide authorization', 66 message: 'Please provide authorization',
@@ -65,19 +70,17 @@ class UserController {
65 70
66 return response.send({ 71 return response.send({
67 message: 'Successfully logged in', 72 message: 'Successfully logged in',
68 token: 73 token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M',
69 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJGZXJkaSBJbnRlcm5hbCBTZXJ2ZXIiLCJpYXQiOjE1NzEwNDAyMTUsImV4cCI6MjUzMzk1NDE3ODQ0LCJhdWQiOiJnZXRmZXJkaS5jb20iLCJzdWIiOiJmZXJkaUBsb2NhbGhvc3QiLCJ1c2VySWQiOiIxIn0.9_TWFGp6HROv8Yg82Rt6i1-95jqWym40a-HmgrdMC6M',
70 }); 74 });
71 } 75 }
72 76
73 // Return information about the current user 77 // Return information about the current user
74 async me({ response }) { 78 async me({
79 response,
80 }) {
75 const user = await User.find(1); 81 const user = await User.find(1);
76 82
77 const settings = 83 const settings = typeof user.settings === 'string' ? JSON.parse(user.settings) : user.settings;
78 typeof user.settings === 'string'
79 ? JSON.parse(user.settings)
80 : user.settings;
81 84
82 return response.send({ 85 return response.send({
83 accountType: 'individual', 86 accountType: 'individual',
@@ -91,11 +94,14 @@ class UserController {
91 isSubscriptionOwner: true, 94 isSubscriptionOwner: true,
92 lastname: 'Application', 95 lastname: 'Application',
93 locale: DEFAULT_APP_SETTINGS.fallbackLocale, 96 locale: DEFAULT_APP_SETTINGS.fallbackLocale,
94 ...(settings || {}), 97 ...settings || {},
95 }); 98 });
96 } 99 }
97 100
98 async updateMe({ request, response }) { 101 async updateMe({
102 request,
103 response,
104 }) {
99 const user = await User.find(1); 105 const user = await User.find(1);
100 106
101 let settings = user.settings || {}; 107 let settings = user.settings || {};
@@ -126,11 +132,16 @@ class UserController {
126 locale: DEFAULT_APP_SETTINGS.fallbackLocale, 132 locale: DEFAULT_APP_SETTINGS.fallbackLocale,
127 ...newSettings, 133 ...newSettings,
128 }, 134 },
129 status: ['data-updated'], 135 status: [
136 'data-updated',
137 ],
130 }); 138 });
131 } 139 }
132 140
133 async import({ request, response }) { 141 async import({
142 request,
143 response,
144 }) {
134 // Validate user input 145 // Validate user input
135 const validation = await validateAll(request.all(), { 146 const validation = await validateAll(request.all(), {
136 email: 'required|email', 147 email: 'required|email',
@@ -138,8 +149,7 @@ class UserController {
138 server: 'required', 149 server: 'required',
139 }); 150 });
140 if (validation.fails()) { 151 if (validation.fails()) {
141 let errorMessage = 152 let errorMessage = 'There was an error while trying to import your account:\n';
142 'There was an error while trying to import your account:\n';
143 for (const message of validation.messages()) { 153 for (const message of validation.messages()) {
144 if (message.validation === 'required') { 154 if (message.validation === 'required') {
145 errorMessage += `- Please make sure to supply your ${message.field}\n`; 155 errorMessage += `- Please make sure to supply your ${message.field}\n`;
@@ -152,16 +162,16 @@ class UserController {
152 return response.status(401).send(errorMessage); 162 return response.status(401).send(errorMessage);
153 } 163 }
154 164
155 const { email, password, server } = request.all(); 165 const {
166 email,
167 password,
168 server,
169 } = request.all();
156 170
157 const hashedPassword = crypto 171 const hashedPassword = crypto.createHash('sha256').update(password).digest('base64');
158 .createHash('sha256')
159 .update(password)
160 .digest('base64');
161 172
162 const base = `${server}/v1/`; 173 const base = `${server}/v1/`;
163 const userAgent = 174 const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36';
164 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Ferdi/5.3.0-beta.1 Chrome/69.0.3497.128 Electron/4.2.4 Safari/537.36';
165 175
166 // Try to get an authentication token 176 // Try to get an authentication token
167 let token; 177 let token;
@@ -178,8 +188,7 @@ class UserController {
178 const content = await rawResponse.json(); 188 const content = await rawResponse.json();
179 189
180 if (!content.message || content.message !== 'Successfully logged in') { 190 if (!content.message || content.message !== 'Successfully logged in') {
181 const errorMessage = 191 const errorMessage = 'Could not login into Franz with your supplied credentials. Please check and try again';
182 'Could not login into Franz with your supplied credentials. Please check and try again';
183 return response.status(401).send(errorMessage); 192 return response.status(401).send(errorMessage);
184 } 193 }
185 194
@@ -201,8 +210,7 @@ class UserController {
201 return response.status(401).send(errorMessage); 210 return response.status(401).send(errorMessage);
202 } 211 }
203 if (!userInf) { 212 if (!userInf) {
204 const errorMessage = 213 const errorMessage = 'Could not get your user info from Franz. Please check your credentials or try again later';
205 'Could not get your user info from Franz. Please check your credentials or try again later';
206 return response.status(401).send(errorMessage); 214 return response.status(401).send(errorMessage);
207 } 215 }
208 216
@@ -217,14 +225,9 @@ class UserController {
217 let serviceId; 225 let serviceId;
218 do { 226 do {
219 serviceId = uuid(); 227 serviceId = uuid();
220 } while ( 228 } while ((await Service.query().where('serviceId', serviceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop
221 // eslint-disable-next-line no-await-in-loop 229
222 (await Service.query().where('serviceId', serviceId).fetch()).rows 230 await Service.create({ // eslint-disable-line no-await-in-loop
223 .length > 0
224 );
225
226 // eslint-disable-next-line no-await-in-loop
227 await Service.create({
228 serviceId, 231 serviceId,
229 name: service.name, 232 name: service.name,
230 recipeId: service.recipeId, 233 recipeId: service.recipeId,
@@ -246,18 +249,11 @@ class UserController {
246 let workspaceId; 249 let workspaceId;
247 do { 250 do {
248 workspaceId = uuid(); 251 workspaceId = uuid();
249 } while ( 252 } while ((await Workspace.query().where('workspaceId', workspaceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop
250 // eslint-disable-next-line no-await-in-loop 253
251 (await Workspace.query().where('workspaceId', workspaceId).fetch()) 254 const services = workspace.services.map(service => serviceIdTranslation[service]);
252 .rows.length > 0 255
253 ); 256 await Workspace.create({ // eslint-disable-line no-await-in-loop
254
255 const services = workspace.services.map(
256 service => serviceIdTranslation[service],
257 );
258
259 // eslint-disable-next-line no-await-in-loop
260 await Workspace.create({
261 workspaceId, 257 workspaceId,
262 name: workspace.name, 258 name: workspace.name,
263 order: workspace.order, 259 order: workspace.order,
@@ -270,9 +266,7 @@ class UserController {
270 return response.status(401).send(errorMessage); 266 return response.status(401).send(errorMessage);
271 } 267 }
272 268
273 return response.send( 269 return response.send('Your account has been imported. You can now use your Franz account in Ferdi.');
274 'Your account has been imported. You can now use your Franz account in Ferdi.',
275 );
276 } 270 }
277 271
278 // Account import/export 272 // Account import/export
@@ -297,7 +291,10 @@ class UserController {
297 .send(exportData); 291 .send(exportData);
298 } 292 }
299 293
300 async importFerdi({ request, response }) { 294 async importFerdi({
295 request,
296 response,
297 }) {
301 const validation = await validateAll(request.all(), { 298 const validation = await validateAll(request.all(), {
302 file: 'required', 299 file: 'required',
303 }); 300 });
@@ -309,9 +306,7 @@ class UserController {
309 try { 306 try {
310 file = JSON.parse(request.input('file')); 307 file = JSON.parse(request.input('file'));
311 } catch (e) { 308 } catch (e) {
312 return response.send( 309 return response.send('Could not import: Invalid file, could not read file');
313 'Could not import: Invalid file, could not read file',
314 );
315 } 310 }
316 311
317 if (!file || !file.services || !file.workspaces) { 312 if (!file || !file.services || !file.workspaces) {
@@ -327,14 +322,9 @@ class UserController {
327 let serviceId; 322 let serviceId;
328 do { 323 do {
329 serviceId = uuid(); 324 serviceId = uuid();
330 } while ( 325 } while ((await Service.query().where('serviceId', serviceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop
331 // eslint-disable-next-line no-await-in-loop 326
332 (await Service.query().where('serviceId', serviceId).fetch()).rows 327 await Service.create({ // eslint-disable-line no-await-in-loop
333 .length > 0
334 );
335
336 // eslint-disable-next-line no-await-in-loop
337 await Service.create({
338 serviceId, 328 serviceId,
339 name: service.name, 329 name: service.name,
340 recipeId: service.recipeId, 330 recipeId: service.recipeId,
@@ -354,19 +344,13 @@ class UserController {
354 let workspaceId; 344 let workspaceId;
355 do { 345 do {
356 workspaceId = uuid(); 346 workspaceId = uuid();
357 } while ( 347 } while ((await Workspace.query().where('workspaceId', workspaceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop
358 // eslint-disable-next-line no-await-in-loop 348
359 (await Workspace.query().where('workspaceId', workspaceId).fetch()) 349 const services = (workspace.services && typeof (workspace.services) === 'object') ?
360 .rows.length > 0 350 workspace.services.map((service) => serviceIdTranslation[service]) :
361 ); 351 [];
362 352
363 const services = 353 await Workspace.create({ // eslint-disable-line no-await-in-loop
364 workspace.services && typeof workspace.services === 'object'
365 ? workspace.services.map(service => serviceIdTranslation[service])
366 : [];
367
368 // eslint-disable-next-line no-await-in-loop
369 await Workspace.create({
370 workspaceId, 354 workspaceId,
371 name: workspace.name, 355 name: workspace.name,
372 order: workspace.order, 356 order: workspace.order,
diff --git a/src/internal-server/app/Controllers/Http/WorkspaceController.js b/src/internal-server/app/Controllers/Http/WorkspaceController.js
index f1a5ddf2b..4189fbcdd 100644
--- a/src/internal-server/app/Controllers/Http/WorkspaceController.js
+++ b/src/internal-server/app/Controllers/Http/WorkspaceController.js
@@ -1,11 +1,16 @@
1const Workspace = use('App/Models/Workspace'); 1const Workspace = use('App/Models/Workspace');
2const { validateAll } = use('Validator'); 2const {
3 validateAll,
4} = use('Validator');
3 5
4const { v4: uuid } = require('uuid'); 6const uuid = require('uuid/v4');
5 7
6class WorkspaceController { 8class WorkspaceController {
7 // Create a new workspace for user 9 // Create a new workspace for user
8 async create({ request, response }) { 10 async create({
11 request,
12 response,
13 }) {
9 // Validate user input 14 // Validate user input
10 const validation = await validateAll(request.all(), { 15 const validation = await validateAll(request.all(), {
11 name: 'required', 16 name: 'required',
@@ -24,10 +29,7 @@ class WorkspaceController {
24 let workspaceId; 29 let workspaceId;
25 do { 30 do {
26 workspaceId = uuid(); 31 workspaceId = uuid();
27 } while ( 32 } while ((await Workspace.query().where('workspaceId', workspaceId).fetch()).rows.length > 0); // eslint-disable-line no-await-in-loop
28 (await Workspace.query().where('workspaceId', workspaceId).fetch()).rows
29 .length > 0
30 ); // eslint-disable-line no-await-in-loop
31 33
32 const order = (await Workspace.all()).rows.length; 34 const order = (await Workspace.all()).rows.length;
33 35
@@ -48,7 +50,11 @@ class WorkspaceController {
48 }); 50 });
49 } 51 }
50 52
51 async edit({ request, response, params }) { 53 async edit({
54 request,
55 response,
56 params,
57 }) {
52 // Validate user input 58 // Validate user input
53 const validation = await validateAll(request.all(), { 59 const validation = await validateAll(request.all(), {
54 name: 'required', 60 name: 'required',
@@ -63,19 +69,20 @@ class WorkspaceController {
63 } 69 }
64 70
65 const data = request.all(); 71 const data = request.all();
66 const { id } = params; 72 const {
73 id,
74 } = params;
67 75
68 // Update data in database 76 // Update data in database
69 await Workspace.query() 77 await (Workspace.query()
70 .where('workspaceId', id) 78 .where('workspaceId', id)).update({
71 .update({ 79 name: data.name,
72 name: data.name, 80 services: JSON.stringify(data.services),
73 services: JSON.stringify(data.services), 81 });
74 });
75 82
76 // Get updated row 83 // Get updated row
77 const workspace = (await Workspace.query().where('workspaceId', id).fetch()) 84 const workspace = (await Workspace.query()
78 .rows[0]; 85 .where('workspaceId', id).fetch()).rows[0];
79 86
80 return response.send({ 87 return response.send({
81 id: workspace.workspaceId, 88 id: workspace.workspaceId,
@@ -104,10 +111,13 @@ class WorkspaceController {
104 }); 111 });
105 } 112 }
106 113
107 const { id } = params; 114 const {
115 id,
116 } = params;
108 117
109 // Update data in database 118 // Update data in database
110 await Workspace.query().where('workspaceId', id).delete(); 119 await (Workspace.query()
120 .where('workspaceId', id)).delete();
111 121
112 return response.send({ 122 return response.send({
113 message: 'Successfully deleted workspace', 123 message: 'Successfully deleted workspace',
@@ -115,7 +125,9 @@ class WorkspaceController {
115 } 125 }
116 126
117 // List all workspaces a user has created 127 // List all workspaces a user has created
118 async list({ response }) { 128 async list({
129 response,
130 }) {
119 const workspaces = (await Workspace.all()).rows; 131 const workspaces = (await Workspace.all()).rows;
120 // Convert to array with all data Franz wants 132 // Convert to array with all data Franz wants
121 let workspacesArray = []; 133 let workspacesArray = [];
@@ -124,10 +136,7 @@ class WorkspaceController {
124 id: workspace.workspaceId, 136 id: workspace.workspaceId,
125 name: workspace.name, 137 name: workspace.name,
126 order: workspace.order, 138 order: workspace.order,
127 services: 139 services: typeof workspace.services === 'string' ? JSON.parse(workspace.services) : workspace.services,
128 typeof workspace.services === 'string'
129 ? JSON.parse(workspace.services)
130 : workspace.services,
131 userId: 1, 140 userId: 1,
132 })); 141 }));
133 } 142 }
diff --git a/src/lib/Tray.js b/src/lib/Tray.js
index c629e212d..f5970f7e7 100644
--- a/src/lib/Tray.js
+++ b/src/lib/Tray.js
@@ -1,14 +1,8 @@
1import { 1import {
2 app, 2 app, Menu, nativeImage, nativeTheme, systemPreferences, Tray, ipcMain,
3 Menu,
4 nativeImage,
5 nativeTheme,
6 systemPreferences,
7 Tray,
8 ipcMain,
9} from 'electron'; 3} from 'electron';
10import { join } from 'path'; 4import { join } from 'path';
11import { isMacOSVersionGreaterThanOrEqualTo } from 'macos-version'; 5import macosVersion from 'macos-version';
12import { isMac, isWindows, isLinux } from '../environment'; 6import { isMac, isWindows, isLinux } from '../environment';
13 7
14const FILE_EXTENSION = isWindows ? 'ico' : 'png'; 8const FILE_EXTENSION = isWindows ? 'ico' : 'png';
@@ -70,9 +64,7 @@ export default class TrayIcon {
70 64
71 if (appSettings.type === 'app') { 65 if (appSettings.type === 'app') {
72 const { isAppMuted } = appSettings.data; 66 const { isAppMuted } = appSettings.data;
73 this.trayMenuTemplate[1].label = isAppMuted 67 this.trayMenuTemplate[1].label = isAppMuted ? 'Enable Notifications && Audio' : 'Disable Notifications && Audio';
74 ? 'Enable Notifications && Audio'
75 : 'Disable Notifications && Audio';
76 this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate); 68 this.trayMenu = Menu.buildFromTemplate(this.trayMenuTemplate);
77 if (isLinux) { 69 if (isLinux) {
78 this.trayIcon.setContextMenu(this.trayMenu); 70 this.trayIcon.setContextMenu(this.trayMenu);
@@ -115,12 +107,9 @@ export default class TrayIcon {
115 } 107 }
116 108
117 if (isMac) { 109 if (isMac) {
118 this.themeChangeSubscriberId = systemPreferences.subscribeNotification( 110 this.themeChangeSubscriberId = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
119 'AppleInterfaceThemeChangedNotification', 111 this._refreshIcon();
120 () => { 112 });
121 this._refreshIcon();
122 },
123 );
124 } 113 }
125 } 114 }
126 115
@@ -160,8 +149,7 @@ export default class TrayIcon {
160 _getAssetFromIndicator(indicator) { 149 _getAssetFromIndicator(indicator) {
161 if (indicator === '•') { 150 if (indicator === '•') {
162 return INDICATOR_TRAY_INDIRECT; 151 return INDICATOR_TRAY_INDIRECT;
163 } 152 } if (indicator !== 0) {
164 if (indicator !== 0) {
165 return INDICATOR_TRAY_UNREAD; 153 return INDICATOR_TRAY_UNREAD;
166 } 154 }
167 return INDICATOR_TRAY_PLAIN; 155 return INDICATOR_TRAY_PLAIN;
@@ -170,16 +158,11 @@ export default class TrayIcon {
170 _refreshIcon() { 158 _refreshIcon() {
171 if (!this.trayIcon) return; 159 if (!this.trayIcon) return;
172 160
173 this.trayIcon.setImage( 161 this.trayIcon.setImage(this._getAsset('tray', this._getAssetFromIndicator(this.indicator)));
174 this._getAsset('tray', this._getAssetFromIndicator(this.indicator)),
175 );
176 162
177 if (isMac) { 163 if (isMac) {
178 this.trayIcon.setPressedImage( 164 this.trayIcon.setPressedImage(
179 this._getAsset( 165 this._getAsset('tray', `${this._getAssetFromIndicator(this.indicator)}-active`),
180 'tray',
181 `${this._getAssetFromIndicator(this.indicator)}-active`,
182 ),
183 ); 166 );
184 } 167 }
185 } 168 }
@@ -187,24 +170,12 @@ export default class TrayIcon {
187 _getAsset(type, asset) { 170 _getAsset(type, asset) {
188 let { platform } = process; 171 let { platform } = process;
189 172
190 if ( 173 if (isMac && (nativeTheme.shouldUseDarkColors || macosVersion.isGreaterThanOrEqualTo('11'))) {
191 isMac &&
192 (nativeTheme.shouldUseDarkColors ||
193 isMacOSVersionGreaterThanOrEqualTo('11'))
194 ) {
195 platform = `${platform}-dark`; 174 platform = `${platform}-dark`;
196 } 175 }
197 176
198 return nativeImage.createFromPath( 177 return nativeImage.createFromPath(join(
199 join( 178 __dirname, '..', 'assets', 'images', type, platform, `${asset}.${FILE_EXTENSION}`,
200 __dirname, 179 ));
201 '..',
202 'assets',
203 'images',
204 type,
205 platform,
206 `${asset}.${FILE_EXTENSION}`,
207 ),
208 );
209 } 180 }
210} 181}
diff --git a/src/webview/notifications.js b/src/webview/notifications.js
index 73cdb89d4..205a3220c 100644
--- a/src/webview/notifications.js
+++ b/src/webview/notifications.js
@@ -1,25 +1,22 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { v1 as uuidV1 } from 'uuid'; 2import uuidV1 from 'uuid/v1';
3 3
4const debug = require('debug')('Ferdi:Notifications'); 4const debug = require('debug')('Ferdi:Notifications');
5 5
6export class NotificationsHandler { 6export class NotificationsHandler {
7 onNotify = data => data; 7 onNotify = (data) => data;
8 8
9 displayNotification(title, options) { 9 displayNotification(title, options) {
10 return new Promise(resolve => { 10 return new Promise((resolve) => {
11 debug('New notification', title, options); 11 debug('New notification', title, options);
12 12
13 const notificationId = uuidV1(); 13 const notificationId = uuidV1();
14 14
15 ipcRenderer.sendToHost( 15 ipcRenderer.sendToHost('notification', this.onNotify({
16 'notification', 16 title,
17 this.onNotify({ 17 options,
18 title, 18 notificationId,
19 options, 19 }));
20 notificationId,
21 }),
22 );
23 20
24 ipcRenderer.once(`notification-onclick:${notificationId}`, () => { 21 ipcRenderer.once(`notification-onclick:${notificationId}`, () => {
25 resolve(); 22 resolve();