• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gitify-app / gitify / 12857889163

19 Jan 2025 10:53PM UTC coverage: 87.169% (-0.2%) from 87.327%
12857889163

Pull #1737

github

web-flow
Merge db015b4b1 into 477658fe8
Pull Request #1737: feat: linux check for updates

595 of 665 branches covered (89.47%)

Branch coverage included in aggregate %.

4 of 7 new or added lines in 2 files covered. (57.14%)

1613 of 1868 relevant lines covered (86.35%)

24.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/main.ts
1
import { app, globalShortcut, ipcMain as ipc, nativeTheme } from 'electron';
×
2
import log from 'electron-log';
×
3
import { menubar } from 'menubar';
×
4

5
import { APPLICATION } from '../shared/constants';
×
6
import { isMacOS, isWindows } from '../shared/platform';
×
7
import { onFirstRunMaybe } from './first-run';
×
8
import { TrayIcons } from './icons';
×
9
import MenuBuilder from './menu';
×
10
import Updater from './updater';
×
11

12
log.initialize();
×
13

14
const browserWindowOpts = {
×
15
  width: 500,
16
  height: 400,
17
  minWidth: 500,
18
  minHeight: 400,
19
  resizable: false,
20
  skipTaskbar: true, // Hide the app from the Windows taskbar
21
  webPreferences: {
22
    enableRemoteModule: true,
23
    nodeIntegration: true,
24
    contextIsolation: false,
25
  },
26
};
27

28
const mb = menubar({
×
29
  icon: TrayIcons.idle,
30
  index: `file://${__dirname}/index.html`,
31
  browserWindow: browserWindowOpts,
32
  preloadWindow: true,
33
  showDockIcon: false, // Hide the app from the macOS dock
34
});
35

36
const menuBuilder = new MenuBuilder(mb);
×
37
const contextMenu = menuBuilder.buildMenu();
×
38

39
/**
40
 * Electron Auto Updater only supports macOS and Windows
41
 * https://github.com/electron/update-electron-app
42
 */
43
if (isMacOS() || isWindows()) {
×
44
  const updater = new Updater(mb, menuBuilder);
×
45
  updater.initialize();
×
46
}
47

48
let shouldUseAlternateIdleIcon = false;
×
49

50
app.whenReady().then(async () => {
×
51
  await onFirstRunMaybe();
×
52

53
  mb.on('ready', () => {
×
54
    mb.app.setAppUserModelId(APPLICATION.ID);
×
55

56
    /**
57
     * TODO: Remove @electron/remote use - see #650
58
     * GitHub OAuth 2 Login Flows - Enable Remote Browser Window Launch
59
     */
60
    require('@electron/remote/main').initialize();
×
61
    require('@electron/remote/main').enable(mb.window.webContents);
×
62

63
    // Tray configuration
64
    mb.tray.setToolTip(APPLICATION.NAME);
×
65
    mb.tray.setIgnoreDoubleClickEvents(true);
×
66
    mb.tray.on('right-click', (_event, bounds) => {
×
67
      mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y });
×
68
    });
69

70
    // Custom key events
71
    mb.window.webContents.on('before-input-event', (event, input) => {
×
72
      if (input.key === 'Escape') {
×
73
        mb.window.hide();
×
74
        event.preventDefault();
×
75
      }
76
    });
77

78
    // DevTools configuration
79
    mb.window.webContents.on('devtools-opened', () => {
×
80
      mb.window.setSize(800, 600);
×
81
      mb.window.center();
×
82
      mb.window.resizable = true;
×
83
      mb.window.setAlwaysOnTop(true);
×
84
    });
85

86
    mb.window.webContents.on('devtools-closed', () => {
×
87
      const trayBounds = mb.tray.getBounds();
×
88
      mb.window.setSize(browserWindowOpts.width, browserWindowOpts.height);
×
89
      mb.positioner.move('trayCenter', trayBounds);
×
90
      mb.window.resizable = false;
×
91
    });
92
  });
93

94
  nativeTheme.on('updated', () => {
×
95
    if (nativeTheme.shouldUseDarkColors) {
×
96
      mb.window.webContents.send('gitify:update-theme', 'DARK');
×
97
    } else {
98
      mb.window.webContents.send('gitify:update-theme', 'LIGHT');
×
99
    }
100
  });
101

102
  /**
103
   * Gitify custom IPC events
104
   */
105
  ipc.handle('gitify:version', () => app.getVersion());
×
106

107
  ipc.on('gitify:window-show', () => mb.showWindow());
×
108

109
  ipc.on('gitify:window-hide', () => mb.hideWindow());
×
110

111
  ipc.on('gitify:quit', () => mb.app.quit());
×
112

113
  ipc.on('gitify:use-alternate-idle-icon', (_, useAlternateIdleIcon) => {
×
114
    shouldUseAlternateIdleIcon = useAlternateIdleIcon;
×
115
  });
116

117
  ipc.on('gitify:icon-active', () => {
×
118
    if (!mb.tray.isDestroyed()) {
×
119
      mb.tray.setImage(
×
120
        menuBuilder.isUpdateAvailable()
×
121
          ? TrayIcons.activeUpdateIcon
122
          : TrayIcons.active,
123
      );
124
    }
125
  });
126

127
  ipc.on('gitify:icon-idle', () => {
×
128
    if (!mb.tray.isDestroyed()) {
×
129
      if (shouldUseAlternateIdleIcon) {
×
130
        mb.tray.setImage(
×
131
          menuBuilder.isUpdateAvailable()
×
132
            ? TrayIcons.idleAlternateUpdateIcon
133
            : TrayIcons.idleAlternate,
134
        );
135
      } else {
136
        mb.tray.setImage(
×
137
          menuBuilder.isUpdateAvailable()
×
138
            ? TrayIcons.idleUpdateIcon
139
            : TrayIcons.idle,
140
        );
141
      }
142
    }
143
  });
144

145
  ipc.on('gitify:update-title', (_, title) => {
×
146
    if (!mb.tray.isDestroyed()) {
×
147
      mb.tray.setTitle(title);
×
148
    }
149
  });
150

151
  ipc.on(
×
152
    'gitify:update-keyboard-shortcut',
153
    (_, { enabled, keyboardShortcut }) => {
154
      if (!enabled) {
×
155
        globalShortcut.unregister(keyboardShortcut);
×
156
        return;
×
157
      }
158

159
      globalShortcut.register(keyboardShortcut, () => {
×
160
        if (mb.window.isVisible()) {
×
161
          mb.hideWindow();
×
162
        } else {
163
          mb.showWindow();
×
164
        }
165
      });
166
    },
167
  );
168

169
  ipc.on('gitify:update-auto-launch', (_, settings) => {
×
170
    app.setLoginItemSettings(settings);
×
171
  });
172
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc