Skip to content

Commit 8b16624

Browse files
committedMay 31, 2019
Fix loading accessories in the main process and Linux
1 parent ec47ef7 commit 8b16624

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed
 

‎src/app/index.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,15 @@ export class App {
5252
}
5353
set websocket_url(url) {
5454
this.client.url = url;
55-
this.client.disconnect().then(() => this.client.tryConnect());
56-
if (this.window) this.window.send('reset-has-connected');
55+
if (this.client.connected) this.client.disconnect().then(() => this.client.tryConnect());
56+
// if (this.window) this.window.send('reset-has-connected');
5757
}
5858

5959
async connected(connection) {
60-
log.info('Connected to %s', client.url);
60+
log.info('Connected to %s', client.url, client);
6161

6262
if (this.window) this.window.send('up');
6363

64-
this.client.connection.getHomeSettings().then(d => this.client.home_settings = d);
65-
this.client.refreshAccessories();
66-
6764
connection.on('received-broadcast', data => {
6865
if (this.window) this.window.send('b', data);
6966
});
@@ -74,7 +71,7 @@ export class App {
7471
this.constructor.menu.items[2].enabled = true;
7572

7673
this.constructor.tray.setContextMenu(this.constructor.menu);
77-
electron.app.dock.setMenu(this.constructor.menu);
74+
if (process.platform === 'darwin') electron.app.dock.setMenu(this.constructor.menu);
7875
}
7976

8077
disconnected(event) {
@@ -88,7 +85,7 @@ export class App {
8885
this.constructor.menu.items[2].enabled = false;
8986

9087
this.constructor.tray.setContextMenu(this.constructor.menu);
91-
electron.app.dock.setMenu(this.constructor.menu);
88+
if (process.platform === 'darwin') electron.app.dock.setMenu(this.constructor.menu);
9289
}
9390

9491
handleUpdateCharateristic(accessory_uuid, service_uuid, characteristic_uuid, details) {
@@ -133,6 +130,9 @@ export class App {
133130

134131
log.info('AuthenticatedUser', authenticated_user);
135132
this.client.connection.authenticated_user = authenticated_user;
133+
134+
this.client.connection.getHomeSettings().then(d => this.client.home_settings = d);
135+
this.client.refreshAccessories();
136136
}
137137
} else {
138138
event.sender.send('r', {messageid, response: null});
@@ -164,7 +164,7 @@ export class App {
164164
this.window.once('ready-to-show', () => {
165165
this.window.show();
166166

167-
electron.app.dock.show();
167+
if (process.platform === 'darwin') electron.app.dock.show();
168168
});
169169

170170
// Emitted when the window is closed
@@ -174,7 +174,7 @@ export class App {
174174
// when you should delete the corresponding element
175175
this.window = null;
176176

177-
if (!BrowserWindow.getAllWindows().length) electron.app.dock.hide();
177+
if (process.platform === 'darwin' && !BrowserWindow.getAllWindows().length) electron.app.dock.hide();
178178
});
179179
}
180180

@@ -193,7 +193,7 @@ export class App {
193193
]);
194194

195195
this.tray.setContextMenu(this.menu);
196-
electron.app.dock.setMenu(this.menu);
196+
if (process.platform === 'darwin') electron.app.dock.setMenu(this.menu);
197197

198198
session.defaultSession.webRequest.onBeforeSendHeaders(this.onBeforeSendHeaders.bind(this));
199199

@@ -206,7 +206,7 @@ export class App {
206206
const url = await this.storage.getItem('URL');
207207
if (url) app.url = url;
208208

209-
app.client.tryConnect();
209+
await app.client.tryConnect();
210210

211211
log.info('Ready, creating window');
212212

@@ -239,7 +239,7 @@ export class App {
239239
this.preferences_window.once('ready-to-show', () => {
240240
this.preferences_window.show();
241241

242-
electron.app.dock.show();
242+
if (process.platform === 'darwin') electron.app.dock.show();
243243
});
244244

245245
// Emitted when the window is closed
@@ -249,7 +249,7 @@ export class App {
249249
// when you should delete the corresponding element
250250
this.preferences_window = null;
251251

252-
if (!BrowserWindow.getAllWindows().length) electron.app.dock.hide();
252+
if (process.platform === 'darwin' && !BrowserWindow.getAllWindows().length) electron.app.dock.hide();
253253
});
254254
}
255255

@@ -264,7 +264,7 @@ export class App {
264264
}
265265
}
266266

267-
electron.app.dock.hide();
267+
if (process.platform === 'darwin') electron.app.dock.hide();
268268

269269
export const app = new App();
270270
const client = app.client;
@@ -293,7 +293,9 @@ ipcMain.on('set-preferences', async (event, data) => {
293293
}
294294
});
295295

296-
electron.systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
296+
if (process.platform === 'darwin') {
297+
electron.systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', () => {
298+
electron.systemPreferences.setAppLevelAppearance(electron.systemPreferences.isDarkMode() ? 'dark' : 'light');
299+
});
297300
electron.systemPreferences.setAppLevelAppearance(electron.systemPreferences.isDarkMode() ? 'dark' : 'light');
298-
});
299-
electron.systemPreferences.setAppLevelAppearance(electron.systemPreferences.isDarkMode() ? 'dark' : 'light');
301+
}

0 commit comments

Comments
 (0)