mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-18 21:54:09 +00:00
feat: open asset directories
This commit is contained in:
committed by
Carlos Valente
parent
6d2b59ef73
commit
bf98f9792a
@@ -17,6 +17,7 @@ const env = process.env.NODE_ENV || 'production';
|
|||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32';
|
||||||
|
const isLinux = process.platform === 'linux';
|
||||||
|
|
||||||
const releaseTag = `v${version}`;
|
const releaseTag = `v${version}`;
|
||||||
|
|
||||||
@@ -43,6 +44,32 @@ const getServerUrl = (port) => `http://localhost:${port}`;
|
|||||||
/** Resolves URL path to download resources */
|
/** Resolves URL path to download resources */
|
||||||
const downloadPath = '/data/db/';
|
const downloadPath = '/data/db/';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Returns public path depending on OS
|
||||||
|
* This is the correct path for the app running in production mode
|
||||||
|
*/
|
||||||
|
function getAppDataPath() {
|
||||||
|
if (isMac) {
|
||||||
|
return path.join(process.env.HOME, 'Library', 'Application Support', 'Ontime');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isWindows) {
|
||||||
|
return path.join(process.env.APPDATA, 'Ontime');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLinux) {
|
||||||
|
return path.join(process.env.HOME, '.Ontime');
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectsPath = path.join(getAppDataPath(), 'projects');
|
||||||
|
const corruptProjectsPath = path.join(getAppDataPath(), 'corrupt files');
|
||||||
|
const crashLogPath = path.join(getAppDataPath(), 'crash logs');
|
||||||
|
const stylesPath = path.join(getAppDataPath(), 'styles');
|
||||||
|
const externalPath = path.join(getAppDataPath(), 'external');
|
||||||
|
|
||||||
/** path to tray icon */
|
/** path to tray icon */
|
||||||
const trayIcon = path.join(__dirname, electronConfig.assets.pathToAssets, 'background.png');
|
const trayIcon = path.join(__dirname, electronConfig.assets.pathToAssets, 'background.png');
|
||||||
/** path to app icon directory */
|
/** path to app icon directory */
|
||||||
@@ -60,6 +87,11 @@ module.exports = {
|
|||||||
nodePath,
|
nodePath,
|
||||||
getClientUrl,
|
getClientUrl,
|
||||||
getServerUrl,
|
getServerUrl,
|
||||||
|
projectsPath,
|
||||||
|
corruptProjectsPath,
|
||||||
|
crashLogPath,
|
||||||
|
stylesPath,
|
||||||
|
externalPath,
|
||||||
downloadPath,
|
downloadPath,
|
||||||
trayIcon,
|
trayIcon,
|
||||||
appIcon,
|
appIcon,
|
||||||
|
|||||||
@@ -1,6 +1,18 @@
|
|||||||
const { Menu, shell } = require('electron');
|
const { Menu, shell } = require('electron');
|
||||||
|
|
||||||
const { linkToGitHub, linkToDocs, linkToDiscord, isMac, releaseTag, downloadPath } = require('../external');
|
const {
|
||||||
|
linkToGitHub,
|
||||||
|
linkToDocs,
|
||||||
|
linkToDiscord,
|
||||||
|
isMac,
|
||||||
|
releaseTag,
|
||||||
|
projectsPath,
|
||||||
|
corruptProjectsPath,
|
||||||
|
crashLogPath,
|
||||||
|
stylesPath,
|
||||||
|
externalPath,
|
||||||
|
downloadPath,
|
||||||
|
} = require('../external');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the application menu
|
* Creates the application menu
|
||||||
@@ -81,6 +93,18 @@ function makeFileMenu(serverUrl, redirectWindow, download) {
|
|||||||
label: 'Download project',
|
label: 'Download project',
|
||||||
click: downloadProject,
|
click: downloadProject,
|
||||||
},
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
|
{
|
||||||
|
label: 'Open directory',
|
||||||
|
submenu: [
|
||||||
|
makeItemOpenInDesktop('Projects', projectsPath),
|
||||||
|
makeItemOpenInDesktop('Corrupted projects', corruptProjectsPath),
|
||||||
|
makeItemOpenInDesktop('Crash logs', crashLogPath),
|
||||||
|
makeItemOpenInDesktop('CSS override', stylesPath),
|
||||||
|
makeItemOpenInDesktop('External', externalPath),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ type: 'separator' },
|
||||||
{ role: isMac ? 'close' : 'quit' },
|
{ role: isMac ? 'close' : 'quit' },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -95,20 +119,20 @@ function makeViewMenu(clientUrl) {
|
|||||||
return {
|
return {
|
||||||
label: 'Views',
|
label: 'Views',
|
||||||
submenu: [
|
submenu: [
|
||||||
makeItemOpenInShell('Public', `${clientUrl}/public`),
|
makeItemOpenInBrowser('Public', `${clientUrl}/public`),
|
||||||
makeItemOpenInShell('Lower Thirds', `${clientUrl}/lower`),
|
makeItemOpenInBrowser('Lower Thirds', `${clientUrl}/lower`),
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
makeItemOpenInShell('Timer', `${clientUrl}/timer`),
|
makeItemOpenInBrowser('Timer', `${clientUrl}/timer`),
|
||||||
makeItemOpenInShell('Minimal Timer', `${clientUrl}/minimal`),
|
makeItemOpenInBrowser('Minimal Timer', `${clientUrl}/minimal`),
|
||||||
makeItemOpenInShell('Clock', `${clientUrl}/clock`),
|
makeItemOpenInBrowser('Clock', `${clientUrl}/clock`),
|
||||||
makeItemOpenInShell('Backstage', `${clientUrl}/backstage`),
|
makeItemOpenInBrowser('Backstage', `${clientUrl}/backstage`),
|
||||||
makeItemOpenInShell('Timeline (beta)', `${clientUrl}/timeline`),
|
makeItemOpenInBrowser('Timeline (beta)', `${clientUrl}/timeline`),
|
||||||
makeItemOpenInShell('Studio Clock', `${clientUrl}/studio`),
|
makeItemOpenInBrowser('Studio Clock', `${clientUrl}/studio`),
|
||||||
makeItemOpenInShell('Countdown', `${clientUrl}/countdown`),
|
makeItemOpenInBrowser('Countdown', `${clientUrl}/countdown`),
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
makeItemOpenInShell('Editor', `${clientUrl}/editor`),
|
makeItemOpenInBrowser('Editor', `${clientUrl}/editor`),
|
||||||
makeItemOpenInShell('Cuesheet', `${clientUrl}/cuesheet`),
|
makeItemOpenInBrowser('Cuesheet', `${clientUrl}/cuesheet`),
|
||||||
makeItemOpenInShell('Operator', `${clientUrl}/op`),
|
makeItemOpenInBrowser('Operator', `${clientUrl}/op`),
|
||||||
|
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ role: 'forceReload' },
|
{ role: 'forceReload' },
|
||||||
@@ -238,9 +262,9 @@ function makeHelpMenu(redirectWindow) {
|
|||||||
{
|
{
|
||||||
type: 'separator',
|
type: 'separator',
|
||||||
},
|
},
|
||||||
makeItemOpenInShell('See on github', linkToGitHub),
|
makeItemOpenInBrowser('See on github', linkToGitHub),
|
||||||
makeItemOpenInShell('Online documentation', linkToDocs),
|
makeItemOpenInBrowser('Online documentation', linkToDocs),
|
||||||
makeItemOpenInShell('Join us on Discord', linkToDiscord),
|
makeItemOpenInBrowser('Join us on Discord', linkToDiscord),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -251,7 +275,7 @@ function makeHelpMenu(redirectWindow) {
|
|||||||
* @param {string} url
|
* @param {string} url
|
||||||
* @returns {object} - MenuItem
|
* @returns {object} - MenuItem
|
||||||
*/
|
*/
|
||||||
function makeItemOpenInShell(label, url) {
|
function makeItemOpenInBrowser(label, url) {
|
||||||
return {
|
return {
|
||||||
label: `${label} ↗`,
|
label: `${label} ↗`,
|
||||||
click: async () => {
|
click: async () => {
|
||||||
@@ -264,4 +288,23 @@ function makeItemOpenInShell(label, url) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to open a file in the OS explorer / finder
|
||||||
|
* @param {string} label
|
||||||
|
* @param {string} path
|
||||||
|
* @returns {object} - MenuItem
|
||||||
|
*/
|
||||||
|
function makeItemOpenInDesktop(label, path) {
|
||||||
|
return {
|
||||||
|
label,
|
||||||
|
click: () => {
|
||||||
|
try {
|
||||||
|
shell.openPath(path);
|
||||||
|
} catch (_error) {
|
||||||
|
/** unhandled error */
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = { getApplicationMenu };
|
module.exports = { getApplicationMenu };
|
||||||
|
|||||||
Reference in New Issue
Block a user