Skip to content

Commit

Permalink
Merge pull request #629 from martpie/remote
Browse files Browse the repository at this point in the history
Switch from remote to @electron/remote
  • Loading branch information
martpie authored Dec 28, 2021
2 parents 7fc1bf0 + e12fcea commit c4f7ea1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"package:checksums": "bash scripts/checksum.sh"
},
"dependencies": {
"@electron/remote": "^2.0.1",
"@reduxjs/toolkit": "^1.7.1",
"bluebird": "^3.7.2",
"chardet": "^1.4.0",
Expand Down Expand Up @@ -90,7 +91,7 @@
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^5.8.0",
"electron": "^13.6.2",
"electron": "^16.0.5",
"electron-builder": "^22.14.5",
"esbuild": "^0.14.8",
"esbuild-plugin-postcss2": "^0.1.1",
Expand Down
8 changes: 7 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { app, BrowserWindow } from 'electron';
import { initialize as remoteInitialize, enable as remoteEnable } from '@electron/remote/main';

import AppModule from './modules/app';
import ApplicationMenuModule from './modules/application-menu';
Expand All @@ -19,6 +20,9 @@ import { checkBounds } from './lib/utils';
const appRoot = path.resolve(__dirname, '..'); // Careful, not future-proof
const rendererDistPath = path.join(appRoot, 'renderer');

// @deprecated Remove all usage of remote in the app
remoteInitialize();

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
let mainWindow: Electron.BrowserWindow | null = null;
Expand Down Expand Up @@ -52,7 +56,6 @@ app.on('ready', async () => {
show: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true,
contextIsolation: false,
autoplayPolicy: 'no-user-gesture-required',
},
Expand All @@ -71,6 +74,9 @@ app.on('ready', async () => {
return { action: 'deny' };
});

// @deprecated Remove all usage of remote in the app
remoteEnable(mainWindow.webContents);

// ... and load the html page generated by ESBuild
mainWindow.loadURL(`file://${rendererDistPath}/app.html#/${config.defaultView}`);

Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/PlaylistsNav/PlaylistsNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jsx-a11y/no-autofocus */

import electron from 'electron';
import { Menu } from '@electron/remote';
import React from 'react';
import Icon from 'react-fontawesome';

Expand All @@ -10,8 +11,6 @@ import { PlaylistModel } from '../../../shared/types/museeks';

import styles from './PlaylistsNav.module.css';

const { Menu } = electron.remote;

interface Props {
playlists: PlaylistModel[];
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/TracksList/TracksList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import electron from 'electron';
import { Menu } from '@electron/remote';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import KeyBinding from 'react-keybinding-component';
import chunk from 'lodash-es/chunk';
Expand All @@ -22,8 +23,7 @@ import scrollbarStyles from '../CustomScrollbar/CustomScrollbar.module.css';
import headerStyles from '../Header/Header.module.css';
import styles from './TracksList.module.css';

const { shell, remote } = electron;
const { Menu } = remote;
const { shell } = electron;

const CHUNK_LENGTH = 20;
const ROW_HEIGHT = 30; // FIXME
Expand Down
9 changes: 3 additions & 6 deletions src/renderer/lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import path from 'path';
import electron from 'electron';
import { app, getCurrentWindow } from '@electron/remote';
import linvodb from 'linvodb3';
import leveljs from 'level-js';
import teeny from 'teeny-conf';
import Promise from 'bluebird';
import { TrackModel, PlaylistModel } from '../../shared/types/museeks';

const { remote } = electron;
const { app } = remote;

/*
|--------------------------------------------------------------------------
| Some variables
|--------------------------------------------------------------------------
*/

export const browserWindows = {
main: remote.getCurrentWindow(),
main: getCurrentWindow(),
};

export const pathUserData = app.getPath('userData');
Expand All @@ -30,7 +27,7 @@ export const pathSrc = __dirname;

// TODO: only working on macOS, issue to follow:
// https://github.com/electron/electron/issues/27116
remote.app.on('open-file', (event, path) => {
app.on('open-file', (event, path) => {
event.preventDefault();
console.info(path); // absolute path to file
});
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/store/actions/PlaylistsActions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import electron from 'electron';
import * as m3u from 'm3ujs';

import { Playlist, TrackModel, PlaylistModel } from '../../../shared/types/museeks';
Expand All @@ -10,7 +9,7 @@ import * as app from '../../lib/app';
import * as ToastsActions from './ToastsActions';
import * as PlayerActions from './PlayerActions';

const { dialog } = electron.remote;
const remote = require('@electron/remote');

/**
* Start playing playlist (on double click)
Expand Down Expand Up @@ -211,9 +210,9 @@ export const exportToM3u = async (playlistId: string): Promise<void> => {
const playlist: PlaylistModel = await app.db.Playlist.findOneAsync({ _id: playlistId });
const tracks: TrackModel[] = await app.db.Track.findAsync({ _id: { $in: playlist.tracks } });

const { filePath } = await dialog.showSaveDialog(app.browserWindows.main, {
const { filePath } = await remote.dialog.showSaveDialog(app.browserWindows.main, {
title: 'Export playlist',
defaultPath: path.resolve(electron.remote.app.getPath('music'), playlist.name),
defaultPath: path.resolve(remote.app.getPath('music'), playlist.name),
filters: [
{
extensions: ['m3u'],
Expand Down
17 changes: 11 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@
ajv "^6.12.0"
ajv-keywords "^3.4.1"

"@electron/get@^1.0.1":
"@electron/get@^1.13.0":
version "1.13.1"
resolved "https://registry.yarnpkg.com/@electron/get/-/get-1.13.1.tgz#42a0aa62fd1189638bd966e23effaebb16108368"
integrity sha512-U5vkXDZ9DwXtkPqlB45tfYnnYBN8PePp1z/XDCupnSpdrxT8/ThCv9WCwPLf9oqiSGZTkH6dx2jDUPuoXpjkcA==
Expand All @@ -1245,6 +1245,11 @@
global-agent "^3.0.0"
global-tunnel-ng "^2.7.1"

"@electron/remote@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@electron/remote/-/remote-2.0.1.tgz#810cbc595a21f0f94641eb2d7e8264063a3f84de"
integrity sha512-bGX4/yB2bPZwXm1DsxgoABgH0Cz7oFtXJgkerB8VrStYdTyvhGAULzNLRn9rVmeAuC3VUDXaXpZIlZAZHpsLIA==

"@electron/[email protected]":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@electron/universal/-/universal-1.0.5.tgz#b812340e4ef21da2b3ee77b2b4d35c9b86defe37"
Expand Down Expand Up @@ -3567,12 +3572,12 @@ electron-to-chromium@^1.4.17:
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.24.tgz#9cf8a92d5729c480ee47ff0aa5555f57467ae2fa"
integrity sha512-erwx5r69B/WFfFuF2jcNN0817BfDBdC4765kQ6WltOMuwsimlQo3JTEq0Cle+wpHralwdeX3OfAtw/mHxPK0Wg==

electron@^13.6.2:
version "13.6.3"
resolved "https://registry.yarnpkg.com/electron/-/electron-13.6.3.tgz#c0217178807d3e0b2175c49dbe33ea8dac447e73"
integrity sha512-kevgR6/RuEhchJQbgCKhHle9HvJhi2dOJlicFZJqbbqa9BVpZARqqFDlwTSatYxmUPUJwu09FvyMwJG2DMQIng==
electron@^16.0.5:
version "16.0.5"
resolved "https://registry.yarnpkg.com/electron/-/electron-16.0.5.tgz#16394c196e42215a82da1f4f39a3f757caf33cb1"
integrity sha512-TgQXWmEGQ3uH2P2JDq5GyJDEu/fimRgqp1iNisARtGreU1k3630PqWlR+4SPnSEHN9NuSv92ng6NWxtefeFzxg==
dependencies:
"@electron/get" "^1.0.1"
"@electron/get" "^1.13.0"
"@types/node" "^14.6.2"
extract-zip "^1.0.3"

Expand Down

0 comments on commit c4f7ea1

Please sign in to comment.