Skip to content

Commit 64c6f08

Browse files
Merge pull request #110 from ThisIs-Developer/audit-fixes
Audit fixes
2 parents dab2776 + 766e05d commit 64c6f08

9 files changed

Lines changed: 1031 additions & 188 deletions

File tree

desktop-app/neutralino.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/neutralinojs/neutralinojs/main/schemas/neutralino.config.schema.json",
3-
"applicationId": "js.neutralino.sample",
3+
"applicationId": "com.markdownviewer.desktop",
44
"version": "1.0.0",
55
"defaultMode": "window",
66
"port": 0,
@@ -13,7 +13,7 @@
1313
"enabled": true,
1414
"writeToLogFile": true
1515
},
16-
"nativeAllowList": ["app.*", "os.*", "filesystem.readFile", "debug.log"],
16+
"nativeAllowList": ["app.*", "os.*", "filesystem.*", "debug.log"],
1717
"globalVariables": {},
1818
"modes": {
1919
"window": {

desktop-app/prepare.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ html = html.replace(/href="assets\//g, 'href="/assets/');
6565
html = html.replace(/href="styles\.css"/g, 'href="/styles.css"');
6666
/** Replace root script.js tag with neutralino.js + main.js + script.js under /js/ */
6767
html = html.replace(
68-
/<script src="script\.js"><\/script>/,
68+
/<script\s+src="script\.js"\s*><\/script>/i,
6969
'<script src="/js/neutralino.js"></script>\n <script src="/js/main.js"></script>\n <script src="/js/script.js"></script>',
7070
);
7171

desktop-app/resources/index.html

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,51 @@ <h3 class="modal-section-title">Open-source credits</h3>
484484
</div>
485485
</div>
486486

487+
<!-- Share Modal -->
488+
<div id="share-modal" class="reset-modal-overlay modal-overlay" role="dialog" aria-modal="true" aria-labelledby="share-modal-title" aria-hidden="true" style="display:none;">
489+
<div class="reset-modal-box reset-modal-box--wide modal-box">
490+
<div class="modal-header">
491+
<p id="share-modal-title" class="reset-modal-message">Share Document</p>
492+
<button type="button" class="modal-close-btn" id="share-modal-close-icon" aria-label="Close share dialog">
493+
<i class="bi bi-x-lg"></i>
494+
</button>
495+
</div>
496+
<div class="modal-body">
497+
<p class="share-modal-description">Choose how recipients can interact with this document.</p>
498+
<div class="share-mode-cards">
499+
<label class="share-mode-card" id="share-card-view" for="share-mode-view">
500+
<input type="radio" id="share-mode-view" name="share-mode" value="view" checked />
501+
<span class="share-card-icon"><i class="bi bi-eye"></i></span>
502+
<span class="share-card-body">
503+
<span class="share-card-title">View only</span>
504+
<span class="share-card-desc">Opens in preview mode. The editor is hidden.</span>
505+
</span>
506+
<span class="share-card-check"><i class="bi bi-check-lg"></i></span>
507+
</label>
508+
<label class="share-mode-card" id="share-card-edit" for="share-mode-edit">
509+
<input type="radio" id="share-mode-edit" name="share-mode" value="edit" />
510+
<span class="share-card-icon"><i class="bi bi-pencil-square"></i></span>
511+
<span class="share-card-body">
512+
<span class="share-card-title">Edit</span>
513+
<span class="share-card-desc">Opens in split editor + preview mode.</span>
514+
</span>
515+
<span class="share-card-check"><i class="bi bi-check-lg"></i></span>
516+
</label>
517+
</div>
518+
<div class="share-url-row">
519+
<input type="text" id="share-url-input" class="rename-modal-input share-url-input" readonly placeholder="Generating link…" aria-label="Share URL" />
520+
<button class="reset-modal-btn share-copy-btn" id="share-copy-btn" title="Copy link">
521+
<i class="bi bi-clipboard"></i>
522+
</button>
523+
</div>
524+
<p class="share-modal-notice"><i class="bi bi-info-circle"></i> The entire document is encoded in the URL. No data is sent to any server.</p>
525+
</div>
526+
<div class="reset-modal-actions">
527+
<button class="reset-modal-btn reset-modal-cancel" id="share-modal-close">Close</button>
528+
</div>
529+
</div>
530+
</div>
531+
487532
<!-- Rename Modal -->
488533
<div id="rename-modal" class="reset-modal-overlay" role="dialog" aria-modal="true" aria-labelledby="rename-modal-title" style="display:none;">
489534
<div class="reset-modal-box reset-modal-box--wide">
@@ -722,4 +767,4 @@ <h3 class="modal-section-title">Open-source credits</h3>
722767
<script src="/js/main.js"></script>
723768
<script src="/js/script.js"></script>
724769
</body>
725-
</html>
770+
</html>

desktop-app/resources/js/main.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ function openTutorial() {
3838
*/
3939
function setTray() {
4040
// Tray menu is only available in window mode
41-
if (NL_MODE != "window") {
41+
if (typeof NL_MODE === "undefined" || NL_MODE != "window") {
4242
console.log("INFO: Tray menu is only available in the window mode.");
4343
return;
4444
}
4545

4646
// Define tray menu items
4747
let tray = {
48-
icon: "/resources/icons/trayIcon.png",
48+
icon: "/resources/assets/icon.jpg",
4949
menuItems: [
5050
{ id: "VERSION", text: "Get version" },
5151
{ id: "SEP", text: "-" },
@@ -54,7 +54,11 @@ function setTray() {
5454
};
5555

5656
// Set the tray menu
57-
Neutralino.os.setTray(tray);
57+
try {
58+
Neutralino.os.setTray(tray);
59+
} catch (e) {
60+
console.warn("Failed to set system tray:", e);
61+
}
5862
}
5963

6064
/*
@@ -85,39 +89,40 @@ function onWindowClose() {
8589
Neutralino.app.exit();
8690
}
8791

88-
// Initialize Neutralino
89-
Neutralino.init();
92+
// Initialize Neutralino if in native environment
93+
if (typeof Neutralino !== 'undefined') {
94+
Neutralino.init();
9095

91-
// Register event listeners
92-
Neutralino.events.on("trayMenuItemClicked", onTrayMenuItemClicked);
93-
Neutralino.events.on("windowClose", onWindowClose);
96+
// Register event listeners
97+
Neutralino.events.on("trayMenuItemClicked", onTrayMenuItemClicked);
98+
Neutralino.events.on("windowClose", onWindowClose);
9499

95-
// Conditional initialization: Set up system tray if not running on macOS
96-
if (NL_OS != "Darwin") {
97-
// TODO: Fix https://github.com/neutralinojs/neutralinojs/issues/615
98-
setTray();
100+
// Conditional initialization: Set up system tray if not running on macOS
101+
if (typeof NL_OS !== 'undefined' && NL_OS != "Darwin") {
102+
// TODO: Fix https://github.com/neutralinojs/neutralinojs/issues/615
103+
setTray();
104+
}
99105
}
100106

101107
// Open file passed as command-line argument (e.g. when double-clicking a .md file)
102108
(async function loadInitialFile() {
109+
if (typeof Neutralino === 'undefined' || typeof NL_ARGS === 'undefined') return;
103110
const args = Array.isArray(NL_ARGS) ? NL_ARGS : (() => { try { return JSON.parse(NL_ARGS); } catch(e) { return []; } })();
104111
const filePath = args.find(a => typeof a === 'string' && /\.(md|markdown)$/i.test(a));
105112
if (!filePath) return;
106113

107114
try {
108115
const content = await Neutralino.filesystem.readFile(filePath);
116+
const fileName = filePath.split(/[/\\]/).pop().replace(/\.(md|markdown)$/i, '');
117+
118+
window.NL_INITIAL_FILE_CONTENT = {
119+
name: fileName,
120+
content: content
121+
};
109122

110-
function applyContent() {
111-
const editor = document.getElementById('markdown-editor');
112-
if (!editor) return;
113-
editor.value = content;
114-
editor.dispatchEvent(new Event('input'));
115-
}
116-
117-
if (document.readyState === 'loading') {
118-
document.addEventListener('DOMContentLoaded', applyContent);
119-
} else {
120-
setTimeout(applyContent, 0);
123+
// Callback hook in case script.js loaded first
124+
if (window.NL_IMPORT_EXTERNAL_FILE) {
125+
window.NL_IMPORT_EXTERNAL_FILE(content, fileName);
121126
}
122127
} catch (e) {
123128
console.warn('Could not open initial file:', e);

0 commit comments

Comments
 (0)