From 118703356d51cd115aced3e4ef41687443508b13 Mon Sep 17 00:00:00 2001
From: Felix Rieseberg
Date: Sun, 26 Jul 2020 23:07:08 -0700
Subject: [PATCH] feat: Some help
---
.gitignore | 2 +-
src/main/devmode.js | 30 ++++++++++++++++++++--
src/main/ipc.js | 7 ++++++
src/main/windows.js | 6 ++---
src/renderer/help.html | 50 +++++++++++++++++++++++++++++++++++++
src/renderer/help.js | 35 ++++++++++++++++++++++++++
src/renderer/index.html | 1 +
src/renderer/style/base.css | 4 +++
src/renderer/style/help.css | 7 ++++++
src/renderer/worker.js | 5 +---
10 files changed, 137 insertions(+), 10 deletions(-)
create mode 100644 src/renderer/help.html
create mode 100644 src/renderer/help.js
create mode 100644 src/renderer/style/help.css
diff --git a/.gitignore b/.gitignore
index b289791..f00701f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -89,6 +89,6 @@ typings/
out/
# Custom stuff
-src/basilisk/user_data
+src/basilisk/user_files
src/basilisk/disk
diff --git a/src/main/devmode.js b/src/main/devmode.js
index 3b77d54..a9d710b 100644
--- a/src/main/devmode.js
+++ b/src/main/devmode.js
@@ -1,5 +1,31 @@
-const isDevMode = true;
+const fs = require('fs');
+const path = require('path');
+const { app } = require('electron');
+
+const appDataPath = app.getPath('userData');
+const devFilePath = path.join(appDataPath, 'developer');
+
+let isDevMode = true;
+
+function getIsDevMode() {
+ if (isDevMode !== undefined) {
+ return isDevMode;
+ }
+
+ return isDevMode = fs.existsSync(devFilePath);
+}
+
+function setIsDevMode(set) {
+ if (set && !getIsDevMode()) {
+ fs.writeFileSync(devFilePath, `So you're a developer, huh? Neat! Welcome aboard!`);
+ } else if (!set && getIsDevMode()) {
+ fs.unlinkSync(devFilePath);
+ }
+
+ isDevMode = set;
+}
module.exports = {
- isDevMode,
+ getIsDevMode,
+ setIsDevMode
};
diff --git a/src/main/ipc.js b/src/main/ipc.js
index 62cc160..e6d309f 100644
--- a/src/main/ipc.js
+++ b/src/main/ipc.js
@@ -1,4 +1,5 @@
const { ipcMain, app, BrowserWindow } = require("electron");
+const { setIsDevMode, getIsDevMode } = require("./devmode");
function registerIpcHandlers() {
ipcMain.handle("quit", () => app.quit());
@@ -8,6 +9,12 @@ function registerIpcHandlers() {
w.webContents.toggleDevTools()
);
});
+
+ ipcMain.handle("getIsDevMode", () => getIsDevMode());
+
+ ipcMain.handle("setIsDevMode", (event, set) => {
+ setIsDevMode(set);
+ });
}
module.exports = {
diff --git a/src/main/windows.js b/src/main/windows.js
index fd58905..399e6f6 100644
--- a/src/main/windows.js
+++ b/src/main/windows.js
@@ -1,7 +1,7 @@
const { app, BrowserWindow, shell } = require("electron");
const path = require("path");
-const { isDevMode } = require("./devmode");
+const { getIsDevMode } = require("./devmode");
const windowList = {};
let mainWindow;
@@ -42,7 +42,7 @@ function handleNewWindow(event, url, frameName, disposition, options) {
newWindow.setMenu(null);
windowList[url] = newWindow;
- if (isDevMode) {
+ if (getIsDevMode()) {
newWindow.webContents.toggleDevTools();
}
@@ -78,7 +78,7 @@ function createWindow() {
// Ensure we create child windows with the correct settings
mainWindow.webContents.on("new-window", handleNewWindow);
- if (isDevMode) {
+ if (getIsDevMode()) {
mainWindow.webContents.toggleDevTools();
}
}
diff --git a/src/renderer/help.html b/src/renderer/help.html
new file mode 100644
index 0000000..25af978
--- /dev/null
+++ b/src/renderer/help.html
@@ -0,0 +1,50 @@
+
+
+
+
+
+ Help
+
+
+
+ Help
+
+ Passing files into the machine
+
+
+
+ Open the folder "macintosh.js" in your user directory .
+ Put any files you want to use in your VM (virtual machine) into that folder.
+ Restart the app.
+ On the VM's (virtual machine) desktop, find the "Unix" volume and double-click to open it.
+ Find the "macintosh.js" folder, which now contains all your files.
+
+
+ Files will be copied over when you start your VM (virtual machine). They are not synchronized while the VM is running. However, any changes made to the "macintosh.js" folder in your VM will be saved to the corresponding folder in your home directory once you shut the VM down.
+
+
+ Getting files out of machine
+
+
+
+ On the VM's (virtual machine) desktop, find the "Unix" volume and double-click to open it.
+ Find the "macintosh.js" folder.
+ Copy any files you want to move out of your VM into that folder.
+ Shut the VM down. The app will now copy all files into the "macintosh.js" folder in your user directory .
+
+
+
+ Developer Tools
+
+
+ If you're curious, you can enable developer tools. They will automatically open when you start the app. Some transparency features
+ will break. Restart the app for this change to take effect.
+
+ Enable developer tools
+
+
+
+
+
\ No newline at end of file
diff --git a/src/renderer/help.js b/src/renderer/help.js
new file mode 100644
index 0000000..83e8ca6
--- /dev/null
+++ b/src/renderer/help.js
@@ -0,0 +1,35 @@
+const { shell, ipcRenderer } = require('electron');
+const path = require('path');
+const fs = require('fs');
+const homedir = require('os').homedir();
+const macDir = path.join(homedir, 'macintosh.js');
+
+let isDevTools;
+
+// Setup dev mode
+function fetchIsDevTools() {
+ ipcRenderer.invoke('getIsDevMode').then((result) => {
+ isDevTools = result;
+
+ if (result) {
+ devtools.innerHTML = 'Disable developer tools';
+ } else {
+ devtools.innerHTML = 'Enable developer tools';
+ }
+ });
+}
+
+user_dir.onclick = user_dir2.onclick = () => {
+ if (!fs.existsSync(macDir)) {
+ fs.mkdirSync(macDir);
+ }
+
+ shell.showItemInFolder(macDir);
+}
+
+devtools.onclick = async () => {
+ await ipcRenderer.invoke('setIsDevMode', !isDevTools);
+ fetchIsDevTools();
+}
+
+fetchIsDevTools();
diff --git a/src/renderer/index.html b/src/renderer/index.html
index 1ebe5a5..959fd47 100644
--- a/src/renderer/index.html
+++ b/src/renderer/index.html
@@ -20,6 +20,7 @@
diff --git a/src/renderer/style/base.css b/src/renderer/style/base.css
index a71c7a2..45cf6e6 100644
--- a/src/renderer/style/base.css
+++ b/src/renderer/style/base.css
@@ -16,6 +16,10 @@ body {
text-align: center;
}
+* {
+ user-select: none;
+}
+
a {
color: #3366CC;
}
diff --git a/src/renderer/style/help.css b/src/renderer/style/help.css
new file mode 100644
index 0000000..3d8e9bb
--- /dev/null
+++ b/src/renderer/style/help.css
@@ -0,0 +1,7 @@
+@import "base.css";
+
+body {
+ font-size: 16px;
+ margin: 15px;
+ text-align: left;
+}
\ No newline at end of file
diff --git a/src/renderer/worker.js b/src/renderer/worker.js
index ee6559f..7947e43 100644
--- a/src/renderer/worker.js
+++ b/src/renderer/worker.js
@@ -14,7 +14,6 @@ const {
AUDIO_DATA_BUFFER_SIZE,
} = require("./audio");
const { quit } = require("./ipc");
-const { isDevMode } = require("../main/devmode");
let isWorkerRunning = false;
let isWorkerSaving = false;
@@ -40,9 +39,7 @@ function handleDiskSaved() {
isWorkerSaving = false;
// We're just gonna quit
- if (!isDevMode) {
- quit();
- }
+ quit();
}
async function handleWorkerShutdown() {