Skip to content

Commit

Permalink
Added Appearance and tweaked notarize script.
Browse files Browse the repository at this point in the history
Added Appearance and tweaked notarize script.
  • Loading branch information
YuhApps committed Aug 13, 2023
1 parent 4a505c4 commit bd3d9c3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
2 changes: 1 addition & 1 deletion notarize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { notarize } = require('electron-notarize')
const { notarize } = require('@electron/notarize')
const path = require('path')

exports.default = async function notarizing(context) {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "magtorrent",
"productName": "MagTorrent",
"version": "1.0.1",
"version": "1.0.2",
"description": "A torrent app for Desktop, powered by WebTorrent and Electron.",
"main": "src/app.js",
"scripts": {
"start": "electron .",
"pack": "electron-builder -m -w nsis zip -l deb tar.xz"
"pack-all": "npm run pack-mac && npm run pack-windows && npm run pack-linux",
"pack-mac": "electron-builder -m --x64 --arm64",
"pack-linux": "electron-builder -l deb tar.xz --x64",
"pack-windows": "electron-builder -w nsis zip --x64"
},
"keywords": [
"magnet",
Expand Down Expand Up @@ -43,7 +46,7 @@
},
"devDependencies": {
"@electron/notarize": "^2.1.0",
"electron": "^25.4.0",
"electron": "^25.5.0",
"electron-builder": "^24.6.3"
},
"postinstall": "electron-builder install-app-deps"
Expand Down
46 changes: 40 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const soundPlay = require('sound-play')
const sintel = 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent'
const sampleItems = [sintel]

const VERSION_CODE = 1
const build_date = '2023.08.13'

let webTorrentClient
let mainWindow
Expand Down Expand Up @@ -37,6 +37,7 @@ app.whenReady().then(() => importWebTorrent(app)).then((WebTorrent) => {
settings = JSON.parse(fs.readFileSync(path.join(app.getPath('userData'), 'Settings.json')))
} else {
settings = {
'appearance': 'system',
'download_path': path.join(app.getPath('downloads'), 'MagTorrent'),
'last_cfu': 0,
'new_version': {
Expand Down Expand Up @@ -87,6 +88,12 @@ app.on('window-all-closed', () => {
finish()
})

nativeTheme.addListener('updated', (e) => {
if (nativeTheme.themeSource === 'system') {
mainWindow.webContents.send('platform', process.platform, nativeTheme.shouldUseDarkColors)
}
})

/** IPC events sent by ipcRenderer from {@link {view/index.html}} */

ipcMain.on('add-torrent', (e, magnetURI) => {
Expand Down Expand Up @@ -160,11 +167,30 @@ function finish() {
done: torrent.done,
path: torrent.path
}))
settings['appearance'] = nativeTheme.themeSource
fs.writeFileSync(path.join(app.getPath('userData'), 'History.json'), JSON.stringify(torrents))
fs.writeFileSync(path.join(app.getPath('userData'), 'Settings.json'), JSON.stringify(settings))
webTorrentClient.destroy((error) => app.quit())
}

function createAppearanceMenu() {
return [
{ label: 'System', value: 'system' },
{ label: 'Light', value: 'light' },
{ label: 'Dark', value: 'dark' },
].map(({ label, value }) => ({
label: label,
type: 'radio',
checked: settings['appearance'] === value,
click: (item) => {
nativeTheme.themeSource = value
settings['appearance'] = value
item.checked = true
mainWindow.webContents.send('platform', process.platform, nativeTheme.shouldUseDarkColors)
}
}))
}

function createOnTorrentDoneMenu() {
return [
{ label: 'Do nothing', value: 'nothing' },
Expand Down Expand Up @@ -199,13 +225,17 @@ function createAppMenu() {
},
{ type: 'separator' },
{
label: 'Set Download folder',
click: setDownloadFolder,
label: 'Appearance',
submenu: createAppearanceMenu(),
},
{
label: 'On Torrent done', // on_torrent_done torrent_done_sound
submenu: createOnTorrentDoneMenu()
},
{
label: 'Set Download folder',
click: setDownloadFolder,
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
Expand Down Expand Up @@ -272,13 +302,17 @@ function createAppOptionsMenu(point) {
type: 'separator'
},
{
label: 'Set Download folder',
click: setDownloadFolder,
label: 'Appearance',
submenu: createAppearanceMenu(),
},
{
label: 'On Torrent done', // on_torrent_done torrent_done_sound
submenu: createOnTorrentDoneMenu()
},
{
label: 'Set Download folder',
click: setDownloadFolder,
},
{
type: 'separator'
},
Expand Down Expand Up @@ -372,6 +406,7 @@ function createTorrentOptionsMenu({ infoHash }, point) {
* Create the main (and the only, for now) window, the entry point of the UI.
*/
function createMainWindow() {
nativeTheme.themeSource = settings['appearance'] || 'system'
let platform = process.platform // See `if (os.platform() === 'darwin' && platform !== 'darwin')` below
let dark = nativeTheme.shouldUseDarkColors
mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -433,7 +468,6 @@ function createMainWindow() {
}

function showAboutDialog(menuItem, browserWindow, event) {
const build_date = '2023.08.01'
dialog.showMessageBox({
message: 'MagTorrent',
detail: 'Version ' + app.getVersion() + ' (' + build_date + ')\nDeveloped by YUH APPS',
Expand Down
2 changes: 2 additions & 0 deletions src/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@
ipcRenderer.send('close:main-window')
}

/*
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {
if (event.matches) {
document.body.classList.add('dark')
} else {
document.body.classList.remove('dark')
}
})
*/

document.addEventListener('drop', (event) => {
event.preventDefault()
Expand Down

0 comments on commit bd3d9c3

Please sign in to comment.