mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-02 21:42:15 +08:00
fix(electron): disable the creation of desktop icon at runtime (closes #1488)
This commit is contained in:
parent
b0e584924b
commit
9108ea9b8a
@ -8,9 +8,6 @@ noAuthentication=false
|
|||||||
# set to true to disable backups (e.g. because of limited space on server)
|
# set to true to disable backups (e.g. because of limited space on server)
|
||||||
noBackup=false
|
noBackup=false
|
||||||
|
|
||||||
# Disable automatically generating desktop icon
|
|
||||||
# noDesktopIcon=true
|
|
||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
# host setting is relevant only for web deployments - set the host on which the server will listen
|
# host setting is relevant only for web deployments - set the host on which the server will listen
|
||||||
# host=0.0.0.0
|
# host=0.0.0.0
|
||||||
|
@ -4,7 +4,6 @@ import electron from "electron";
|
|||||||
import electronDebug from "electron-debug";
|
import electronDebug from "electron-debug";
|
||||||
import electronDl from "electron-dl";
|
import electronDl from "electron-dl";
|
||||||
import sqlInit from "./src/services/sql_init.js";
|
import sqlInit from "./src/services/sql_init.js";
|
||||||
import appIconService from "./src/services/app_icon.js";
|
|
||||||
import windowService from "./src/services/window.js";
|
import windowService from "./src/services/window.js";
|
||||||
import tray from "./src/services/tray.js";
|
import tray from "./src/services/tray.js";
|
||||||
|
|
||||||
@ -19,8 +18,6 @@ if ((await import("electron-squirrel-startup")).default) {
|
|||||||
// Adds debug features like hotkeys for triggering dev tools and reload
|
// Adds debug features like hotkeys for triggering dev tools and reload
|
||||||
electronDebug();
|
electronDebug();
|
||||||
|
|
||||||
appIconService.installLocalAppIcon();
|
|
||||||
|
|
||||||
electronDl({ saveAs: true });
|
electronDl({ saveAs: true });
|
||||||
|
|
||||||
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
// needed for excalidraw export https://github.com/zadam/trilium/issues/4271
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
import path from "path";
|
|
||||||
import resourceDir from "./resource_dir.js";
|
|
||||||
import log from "./log.js";
|
|
||||||
import os from "os";
|
|
||||||
import fs from "fs";
|
|
||||||
import config from "./config.js";
|
|
||||||
import { isElectron } from "./utils.js";
|
|
||||||
|
|
||||||
const template = `[Desktop Entry]
|
|
||||||
Type=Application
|
|
||||||
Name=TriliumNext Notes
|
|
||||||
StartupWMClass=TriliumNext Notes
|
|
||||||
Icon=#APP_ROOT_DIR#/icon.png
|
|
||||||
Exec=#EXE_PATH#
|
|
||||||
Categories=Office
|
|
||||||
Terminal=false
|
|
||||||
`;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Installs .desktop icon into standard ~/.local/share/applications directory.
|
|
||||||
* We overwrite this file during every run as it might have been updated.
|
|
||||||
*/
|
|
||||||
function installLocalAppIcon() {
|
|
||||||
if (!isElectron || ["win32", "darwin"].includes(os.platform()) || (config.General && config.General.noDesktopIcon)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.existsSync(path.resolve(resourceDir.ELECTRON_APP_ROOT_DIR, "trilium-portable.sh"))) {
|
|
||||||
// simple heuristic to detect ".tar.xz" linux build (i.e., not flatpak, not debian)
|
|
||||||
// only in such case it's necessary to create an icon
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const desktopDir = path.resolve(os.homedir(), ".local/share/applications");
|
|
||||||
|
|
||||||
fs.stat(desktopDir, function (err, stats) {
|
|
||||||
if (err) {
|
|
||||||
// Directory doesn't exist, so we won't attempt to create the .desktop file
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
const desktopFilePath = path.resolve(desktopDir, "trilium-notes.desktop");
|
|
||||||
|
|
||||||
fs.writeFile(desktopFilePath, getDesktopFileContent(), function (err) {
|
|
||||||
if (err) {
|
|
||||||
log.error("Desktop icon installation to ~/.local/share/applications failed.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDesktopFileContent() {
|
|
||||||
return template.replace("#APP_ROOT_DIR#", escapePath(resourceDir.ELECTRON_APP_ROOT_DIR)).replace("#EXE_PATH#", escapePath(getExePath()));
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapePath(path: string) {
|
|
||||||
return path.replace(/ /g, "\\ ");
|
|
||||||
}
|
|
||||||
|
|
||||||
function getExePath() {
|
|
||||||
return path.resolve(resourceDir.ELECTRON_APP_ROOT_DIR, "trilium");
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
installLocalAppIcon
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user