Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Electron 33 #1234

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ jobs:
macos:
xcode: '13.4.1'
steps:
- run:
name: Swap node versions
command: |
set +e
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
nvm install v18.20.4
nvm alias default v18.20.4

echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
- checkout
- run: yarn
- run: mkdir -p ~/reports
- run: yarn lint
- run: yarn test:ci
# - run: yarn lint
# - run: yarn test:ci
- run: yarn run dist
- run: mv dist/*-x64.dmg dist/Kap-x64.dmg
- run: mv dist/*-arm64.dmg dist/Kap-arm64.dmg
Expand Down
7 changes: 7 additions & 0 deletions main/aperture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ApertureOptions, StartRecordingOptions} from './common/types';
import {InstalledPlugin} from './plugins/plugin';
import {RecordService, RecordServiceHook} from './plugins/service';
import {getCurrentDurationStart, getOverallDuration, setCurrentDurationStart, setOverallDuration} from './utils/track-duration';
import {ipcMain} from 'electron-better-ipc';

const createAperture = require('aperture');
const aperture = createAperture();
Expand Down Expand Up @@ -68,6 +69,12 @@ const cleanup = async () => {
setCropperShortcutAction();
};

export function initializeAperture() {
ipcMain.answerRenderer('start-recording', async (options: StartRecordingOptions) => {
return startRecording(options);
});
}

export const startRecording = async (options: StartRecordingOptions) => {
if (past) {
return;
Expand Down
5 changes: 5 additions & 0 deletions main/common/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import util from 'electron-util';
import {parse} from 'semver';
import {settings} from './settings';
import {ipcMain} from 'electron-better-ipc';

// TODO: Disabled because of https://github.com/wulkano/Kap/issues/1126
/// const Insight = require('insight');
Expand Down Expand Up @@ -31,4 +32,8 @@ export const initializeAnalytics = () => {
track('install');
settings.set('version', pkg.version);
}

ipcMain.answerRenderer<string[]>('track-event', paths => {
track(...paths);
});
};
34 changes: 34 additions & 0 deletions main/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import {homedir} from 'os';
import Store from 'electron-store';
import {ipcMain as ipc} from 'electron';
import {ipcMain} from 'electron-better-ipc';

const {defaultInputDeviceId} = require('./constants');
const shortcutToAccelerator = require('../utils/shortcut-to-accelerator');
Expand Down Expand Up @@ -141,3 +143,35 @@ if (settings.has('cropperShortcut')) {

settings.set('cropper' as any, {});
settings.set('actionBar' as any, {});

ipc.on('get-setting', (event, key) => {
event.returnValue = settings.get(key);
});

ipc.on('set-setting', (_, args) => {
settings.set(args.key, args.value);
});

ipc.on('get-settings-store', event => {
event.returnValue = settings.store;
});

ipcMain.answerRenderer<string>('subscribe-setting', (key, window) => {
const unsubscribeChange = settings.onDidChange(key as keyof Settings, value => {
ipcMain.callRenderer<{key: string; value: unknown}>(window, 'setting-changed', {key, value});
});

const unsubscribe = ipcMain.answerRenderer<string>('unsubscribe-setting', (unsubscribeKey, unsubscribeWindow) => {
if (key === unsubscribeKey && window.id === unsubscribeWindow.id) {
cleanup();
}
});

const cleanup = () => {
unsubscribeChange();
unsubscribe();
window.off('closed', cleanup);
};

window.on('closed', cleanup);
});
35 changes: 35 additions & 0 deletions main/common/system-colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

export const systemColorNames = [
'control-background',
'control',
'control-text',
'disabled-control-text',
'find-highlight',
'grid',
'header-text',
'highlight',
'keyboard-focus-indicator',
'label',
'link',
'placeholder-text',
'quaternary-label',
'scrubber-textured-background',
'secondary-label',
'selected-content-background',
'selected-control',
'selected-control-text',
'selected-menu-item-text',
'selected-text-background',
'selected-text',
'separator',
'shadow',
'tertiary-label',
'text-background',
'text',
'under-page-background',
'unemphasized-selected-content-background',
'unemphasized-selected-text-background',
'unemphasized-selected-text',
'window-background',
'window-frame-text'
] as const;
17 changes: 17 additions & 0 deletions main/common/system-permissions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {systemPreferences, shell, dialog, app} from 'electron';
import {ipcMain} from 'electron-better-ipc';
import {OpenDialogOptions} from 'electron/main';
const {hasScreenCapturePermission, hasPromptedForPermission} = require('mac-screen-capture-permissions');
const {ensureDockIsShowing} = require('../utils/dock');

Expand Down Expand Up @@ -87,3 +89,18 @@ export const ensureScreenCapturePermissions = (fallback = screenCaptureFallback)

export const hasScreenCaptureAccess = () => hasScreenCapturePermission();

ipcMain.answerRenderer('ensure-microphone-permissions', async () => {
return ensureMicrophonePermissions();
});

ipcMain.answerRenderer('get-open-at-login', async () => {
return app.getLoginItemSettings().openAtLogin;
});

ipcMain.answerRenderer('set-open-at-login', async ({openAtLogin}) => {
app.setLoginItemSettings({openAtLogin});
});

ipcMain.answerRenderer<OpenDialogOptions>('show-open-dialog', async (args, window) => {
return dialog.showOpenDialog(window, args);
});
16 changes: 16 additions & 0 deletions main/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {askForTargetFilePath} from './plugins/built-in/save-file-plugin';
import path from 'path';
import {ensureDockIsShowingSync} from './utils/dock';
import {windowManager} from './windows/manager';
import {flags} from './common/flags';

export interface ExportOptions {
plugin: InstalledPlugin;
Expand Down Expand Up @@ -329,4 +330,19 @@ export const setUpExportsListeners = () => {
});
}
});

ipc.answerRenderer('show-exports-background-dialog', async (_, window) => {
if (!flags.get('backgroundEditorConversion')) {
return;
}

await dialog.showMessageBox(window, {
type: 'info',
message: 'Your export will continue in the background. You can access it through the Export History window.',
buttons: ['Ok'],
defaultId: 0
});

flags.set('backgroundEditorConversion', true);
});
};
24 changes: 17 additions & 7 deletions main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {autoUpdater} from 'electron-updater';
import toMilliseconds from '@sindresorhus/to-milliseconds';

import './windows/load';
import './utils/sentry';
import {initializeSentryListeners} from './utils/sentry';

require('electron-timber').hookConsole({main: true, renderer: true});
// require('electron-timber').hookConsole({main: true, renderer: true});

import {settings} from './common/settings';
import {plugins} from './plugins';
Expand All @@ -21,9 +21,13 @@ import {handleDeepLink} from './utils/deep-linking';
import {hasActiveRecording, cleanPastRecordings} from './recording-history';
import {setupRemoteStates} from './remote-states';
import {setUpExportsListeners} from './export';
import {windowManager} from './windows/manager';
// import {windowManager} from './windows/manager';
import {setupProtocol} from './utils/protocol';
import {stopRecordingWithNoEdit} from './aperture';
import {initializeAperture, stopRecordingWithNoEdit} from './aperture';
import {initializeWindows} from './utils/windows';
import {initializeWindowControls} from './utils/window-controls';
import {initializeCogMenu} from './menus/cog';
import {initializeMenus} from './utils/menus';

const prepareNext = require('electron-next');

Expand Down Expand Up @@ -103,6 +107,12 @@ const checkForUpdates = () => {
initializeTray();
initializeGlobalAccelerators();
setUpExportsListeners();
initializeWindows();
initializeWindowControls();
initializeAperture();
initializeCogMenu();
initializeSentryListeners();
initializeMenus();

if (!app.isDefaultProtocolClient('kap')) {
app.setAsDefaultProtocolClient('kap');
Expand All @@ -118,15 +128,15 @@ const checkForUpdates = () => {
ensureScreenCapturePermissions() &&
(!settings.get('recordAudio') || hasMicrophoneAccess())
) {
windowManager.cropper?.open();
// windowManager.cropper?.open();
}

checkForUpdates();
})();

app.on('window-all-closed', (event: any) => {
app.on('window-all-closed', () => {
app.dock.hide();
event.preventDefault();
// event.preventDefault();
});

app.on('will-finish-launching', () => {
Expand Down
8 changes: 8 additions & 0 deletions main/menus/cog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getAudioDevices, getDefaultInputDevice} from '../utils/devices';
import {settings} from '../common/settings';
import {defaultInputDeviceId} from '../common/constants';
import {hasMicrophoneAccess} from '../common/system-permissions';
import {ipcMain} from 'electron-better-ipc';

const getCogMenuTemplate = async (): Promise<MenuOptions> => [
getAboutMenuItem(),
Expand Down Expand Up @@ -94,6 +95,13 @@ const getMicrophoneItem = async (): Promise<MenuOptions[number]> => {
};
};

export function initializeCogMenu() {
ipcMain.answerRenderer('open-cog-menu', async () => {
const menu = await getCogMenu();
menu.popup();
});
}

export const getCogMenu = async () => {
return Menu.buildFromTemplate(
await getCogMenuTemplate()
Expand Down
49 changes: 48 additions & 1 deletion main/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app} from 'electron';
import {app, shell} from 'electron';
import {EventEmitter} from 'events';
import path from 'path';
import fs from 'fs';
Expand All @@ -11,6 +11,7 @@ import {notify} from '../utils/notifications';
import packageJson from 'package-json';
import {NormalizedPackageJson} from 'read-pkg';
import {windowManager} from '../windows/manager';
import {ipcMain} from 'electron-better-ipc';

const got = require('got');

Expand Down Expand Up @@ -214,3 +215,49 @@ export class Plugins extends EventEmitter {
}

export const plugins = new Plugins();

const mapPlugin = (plugin: NpmPlugin) => {
const isInstalledPlugin = plugin instanceof InstalledPlugin;

return {
name: plugin.name,
prettyName: plugin.prettyName,
version: plugin.version,
description: plugin.description,
isCompatible: plugin.isCompatible,
hasConfig: isInstalledPlugin ? plugin.hasConfig : undefined,
isInstalled: plugin.isInstalled,
kapVersion: plugin.kapVersion,
macosVersion: plugin.macosVersion,
isValid: isInstalledPlugin ? plugin.isValid : undefined,
link: plugin.link,
isSymLink: isInstalledPlugin ? plugin.isSymLink : undefined
};
};

ipcMain.answerRenderer('get-installed-plugins', () => {
return plugins.installedPlugins.sort((a, b) => a.prettyName.localeCompare(b.prettyName)).map(plugin => mapPlugin(plugin));
});

ipcMain.answerRenderer('get-npm-plugins', async () => {
const npmPlugins = await plugins.getFromNpm();
return npmPlugins.map(plugin => mapPlugin(plugin));
});

ipcMain.answerRenderer<{pluginName: string}>('install-plugin', async ({pluginName}) => {
const plugin = await plugins.install(pluginName);
return plugin ? mapPlugin(plugin) : undefined;
});

ipcMain.answerRenderer<{pluginName: string}>('uninstall-plugin', async ({pluginName}) => {
const plugin = await plugins.uninstall(pluginName);
return plugin ? mapPlugin(plugin) : undefined;
});

ipcMain.answerRenderer<{pluginName: string}>('open-plugin-config', async ({pluginName}) => {
return plugins.openPluginConfig(pluginName);
});

ipcMain.answerRenderer('open-plugins-folder', async () => {
shell.openPath(plugins.pluginsDir);
});
Loading