-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the beginning of the refactoring effort
- Loading branch information
1 parent
4082623
commit 5a494ab
Showing
6 changed files
with
186 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
env: { | ||
es2021: true, | ||
node: true, | ||
}, | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [".eslintrc.{js,cjs}"], | ||
parserOptions: { | ||
sourceType: "script", | ||
}, | ||
}, | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
rules: { | ||
indent: ["error", 2], | ||
"linebreak-style": ["error", "unix"], | ||
quotes: ["error", "double"], | ||
semi: ["error", "always"], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { BrowserWindow, dialog, app, ipcMain } from "electron"; | ||
import settings from "electron-settings"; | ||
import { autoUpdater } from "electron-updater"; | ||
|
||
/** | ||
* Provides handlers to critical events in the app's lifecycle such as auto updaters, url handles etc.. | ||
* | ||
* @param {BrowserWindow} win | ||
* @param {string} preload | ||
* @param {string} indexHtml | ||
*/ | ||
export async function callHandlers( | ||
win: BrowserWindow, | ||
preload: string, | ||
indexHtml: string, | ||
) { | ||
// Quits when all windows are closed | ||
app.on("window-all-closed", () => { | ||
win = null; | ||
if (process.platform !== "darwin") app.quit(); | ||
}); | ||
|
||
// Handles external websites linking back to the application. | ||
app.on("open-url", (event, url) => { | ||
dialog.showErrorBox("Welcome Back", `You arrived from: ${url}`); | ||
}); | ||
|
||
// handles the dialog box to open folders. | ||
ipcMain.handle("dialog:openFolder", handleFolderOpen); | ||
|
||
/** | ||
* Handles opening external folders | ||
*/ | ||
async function handleFolderOpen() { | ||
const currentLibraryPath = await ( | ||
await settings.get("locations.libraryLocation") | ||
).toString(); | ||
const { canceled, filePaths } = await dialog.showOpenDialog(win, { | ||
title: "Select Library Location", | ||
defaultPath: currentLibraryPath, | ||
properties: ["openDirectory"], | ||
}); | ||
if (canceled) { | ||
return; | ||
} else { | ||
return filePaths[0]; | ||
} | ||
} | ||
|
||
// handles child windows | ||
ipcMain.handle("open-win", (event, arg) => { | ||
const childWindow = new BrowserWindow({ | ||
webPreferences: { | ||
preload, | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
}, | ||
}); | ||
|
||
if (process.env.VITE_DEV_SERVER_URL) { | ||
childWindow.loadURL(`${process.env.VITE_DEV_SERVER_URL}#${arg}`); | ||
} else { | ||
childWindow.loadFile(indexHtml, { hash: arg }); | ||
} | ||
}); | ||
|
||
// This section handles auto updates | ||
app.on("ready", () => { | ||
autoUpdater.checkForUpdatesAndNotify(); | ||
}); | ||
autoUpdater.on("update-available", (info) => { | ||
win.webContents.send( | ||
"update_available", | ||
`Updates are available! v${info.version} is ready to be installed.\n\nFeel free to use the app while the update is being downloaded.`, | ||
); | ||
}); | ||
autoUpdater.on("update-downloaded", () => { | ||
win.webContents.send( | ||
"update_downloaded", | ||
"Update has been downloaded! We will launch the next version when you restart the app.", | ||
); | ||
}); | ||
} | ||
|
||
/** | ||
* Handles account verification links. | ||
* | ||
* @param {BrowserWindow} win | ||
*/ | ||
export async function handleExternAuthentication(win: BrowserWindow) { | ||
app.on("second-instance", (event, commandLine, workingDirectory) => { | ||
// Someone tried to run a second instance, we should focus our window. | ||
if (win) { | ||
if (win.isMinimized()) win.restore(); | ||
win.focus(); | ||
win.reload(); | ||
console.log(commandLine); | ||
if (commandLine[3].includes("select-launcher://home")) { | ||
dialog.showMessageBox({ | ||
type: "info", | ||
title: "Select Launcher", | ||
message: "Account verification successful!", | ||
}); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { app } from "electron"; | ||
import { release } from "os"; | ||
import path, { join } from "path"; | ||
|
||
/** | ||
* Sets up global variables. | ||
*/ | ||
export function globalSetup() { | ||
// Global Variable Setups | ||
process.env.DIST_ELECTRON = join(__dirname, "../.."); | ||
process.env.DIST = join(process.env.DIST_ELECTRON, "../dist"); | ||
process.env.PUBLIC = app.isPackaged | ||
? process.env.DIST | ||
: join(process.env.DIST_ELECTRON, "../public"); | ||
|
||
// Disable GPU Acceleration for Windows 7 | ||
if (release().startsWith("6.1")) app.disableHardwareAcceleration(); | ||
// Set application name for Windows 10+ notifications | ||
if (process.platform === "win32") app.setAppUserModelId(app.getName()); | ||
|
||
// Make sure only one instance of the app is running | ||
if (!app.requestSingleInstanceLock()) { | ||
app.quit(); | ||
process.exit(0); | ||
} | ||
|
||
if (process.defaultApp) { | ||
if (process.argv.length >= 2) { | ||
app.setAsDefaultProtocolClient("select-launcher", process.execPath, [ | ||
path.resolve(process.argv[1]), | ||
]); | ||
} | ||
} else { | ||
app.setAsDefaultProtocolClient("select-launcher"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"0.2","flagWords":[],"language":"en","words":["nextui"]} | ||
{"flagWords":[],"words":["nextui","linebreak"],"language":"en","version":"0.2"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters