Skip to content

Commit

Permalink
Non functional code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscalzi committed Nov 25, 2023
1 parent 7e95771 commit 639c699
Show file tree
Hide file tree
Showing 27 changed files with 4,344 additions and 247 deletions.
18 changes: 9 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
},
"overrides": [
{
"files": [ "app/assets/js/scripts/*.js" ],
"rules": {
"no-unused-vars": [
0
],
"no-undef": [
0
"env": {
"browser": true,
"node": false,
"jquery": true
},
"files": [
"app/assets/js/scripts/*.js",
"app/assets/js/renderer/*.js"
]
}
}
]
]
}
7 changes: 5 additions & 2 deletions app/app.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<head>
<meta charset="utf-8" http-equiv="Content-Security-Policy" content="script-src 'self' 'sha256-In6B8teKZQll5heMl9bS7CESTbGvuAt3VVV86BUQBDk='"/>
<title><%= lang('app.title') %></title>
<script src="./assets/js/scripts/uicore.js"></script>
<script src="./assets/js/scripts/uibinder.js"></script>
<!-- TODO FIXME -->
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<!-- <script type="module" src="./assets/js/scripts/uicore.js"></script>
<script type="module" src="./assets/js/scripts/uibinder.js"></script> -->
<link type="text/css" rel="stylesheet" href="./assets/css/launcher.css">
<style>
body {
Expand All @@ -25,6 +27,7 @@
filter: blur(3px) contrast(0.9) brightness(1.0);
}
</style>
<script type="module" src="./assets/js/renderer/megascript.js"></script>
</head>
<body bkid="<%=bkid%>">
<%- include('frame') %>
Expand Down
9 changes: 9 additions & 0 deletions app/assets/@types/preloader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { api } from '../js/preloader.js'

declare global {
interface Window {
api: typeof api
}
}

export {};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { LoggerUtil } = require('helios-core')
const { RestResponseStatus } = require('helios-core/common')
const { MojangRestAPI, mojangErrorDisplayable, MojangErrorCode } = require('helios-core/mojang')
const { MicrosoftAuth, microsoftErrorDisplayable, MicrosoftErrorCode } = require('helios-core/microsoft')
const { AZURE_CLIENT_ID } = require('./ipcconstants')
const { AZURE_CLIENT_ID } = require('../ipcconstants')

const log = LoggerUtil.getLogger('AuthManager')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.e

const dataPath = path.join(sysRoot, '.helioslauncher')

const launcherDir = require('@electron/remote').app.getPath('userData')
const { app } = require('electron')

const launcherDir = app.getPath('userData')

/**
* Retrieve the absolute path of the launcher directory.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const merge = require('lodash.merge')
let lang

exports.loadLanguage = function(id){
lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.toml`))) || {})
lang = merge(lang || {}, toml.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'lang', `${id}.toml`))) || {})
}

exports.query = function(id, placeHolders){
Expand Down Expand Up @@ -40,4 +40,8 @@ exports.setupLanguage = function(){

// Load Custom Language File for Launcher Customizer
exports.loadLanguage('_custom')
}

exports.getLang = () => {
return lang
}
119 changes: 55 additions & 64 deletions app/assets/js/preloader.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
const {ipcRenderer} = require('electron')
const fs = require('fs-extra')
const os = require('os')
const path = require('path')

const ConfigManager = require('./configmanager')
const { DistroAPI } = require('./distromanager')
const LangLoader = require('./langloader')
const { LoggerUtil } = require('helios-core')
// eslint-disable-next-line no-unused-vars
const { HeliosDistribution } = require('helios-core/common')

const logger = LoggerUtil.getLogger('Preloader')

logger.info('Loading..')

// Load ConfigManager
ConfigManager.load()

// Yuck!
// TODO Fix this
DistroAPI['commonDir'] = ConfigManager.getCommonDirectory()
DistroAPI['instanceDir'] = ConfigManager.getInstanceDirectory()

// Load Strings
LangLoader.setupLanguage()

/**
*
* @param {HeliosDistribution} data
*/
function onDistroLoad(data){
if(data != null){

// Resolve the selected server if its value has yet to be set.
if(ConfigManager.getSelectedServer() == null || data.getServerById(ConfigManager.getSelectedServer()) == null){
logger.info('Determining default selected server..')
ConfigManager.setSelectedServer(data.getMainServer().rawServer.id)
ConfigManager.save()
}
const { contextBridge, ipcRenderer } = require('electron')

module.exports.api = {
os: {
totalmem: () => ipcRenderer.invoke('os.totalmem'),
freemem: () => ipcRenderer.invoke('os.freemem')
},
semver: {
prerelease: (version) => ipcRenderer.invoke('semver.prerelease', version)
},
path: {
join: (...args) => ipcRenderer.invoke('path.join', args)
},
app: {
isDev: () => ipcRenderer.invoke('app.isDev'),
getVersion: () => ipcRenderer.invoke('app.getVersion')
},
shell: {
openExternal: (url) => ipcRenderer.invoke('shell.openExternal', url),
openPath: (path) => ipcRenderer.invoke('shell.openPath', path),
},
xwindow: {
close: () => ipcRenderer.invoke('xwindow.close'),
setProgressBar: (progress) => ipcRenderer.invoke('xwindow.setProgressBar', progress),
toggleDevTools: () => {
console.log('%cThe console is dark and full of terrors.', 'color: white; -webkit-text-stroke: 4px #a02d2a; font-size: 60px; font-weight: bold')
console.log('%cIf you\'ve been told to paste something here, you\'re being scammed.', 'font-size: 16px')
console.log('%cUnless you know exactly what you\'re doing, close this window.', 'font-size: 16px')
return ipcRenderer.invoke('xwindow.toggleDevTools')
},
minimize: () => ipcRenderer.invoke('xwindow.minimize'),
maximize: () => ipcRenderer.invoke('xwindow.maximize'),
unmaximize: () => ipcRenderer.invoke('xwindow.unmaximize'),
isMaximized: () => ipcRenderer.invoke('xwindow.isMaximized')
},
process: {
platform: () => ipcRenderer.invoke('process.platform'),
arch: () => ipcRenderer.invoke('process.arch')
},
hc: {
type: () => ipcRenderer.invoke('hc.type')
},
AuthManager: {
addMojangAccount: (username, password) => ipcRenderer.invoke('AuthManager.addMojangAccount', username, password),
addMicrosoftAccount: (authCode) => ipcRenderer.invoke('AuthManager.addMicrosoftAccount', authCode),
removeMojangAccount: (uuid) => ipcRenderer.invoke('AuthManager.removeMojangAccount', uuid),
removeMicrosoftAccount: (uuid) => ipcRenderer.invoke('AuthManager.removeMicrosoftAccount', uuid),
validateSelected: () => ipcRenderer.invoke('AuthManager.validateSelected')
},
Lang: {
getLang: () => ipcRenderer.invoke('Lang.getLang')
},
AutoUpdater: {
port2: () => ipcRenderer.invoke('AutoUpdater.port2')
}
ipcRenderer.send('distributionIndexDone', data != null)
}

// Ensure Distribution is downloaded and cached.
DistroAPI.getDistribution()
.then(heliosDistro => {
logger.info('Loaded distribution index.')

onDistroLoad(heliosDistro)
})
.catch(err => {
logger.info('Failed to load an older version of the distribution index.')
logger.info('Application cannot run.')
logger.error(err)

onDistroLoad(null)
})

// Clean up temp dir incase previous launches ended unexpectedly.
fs.remove(path.join(os.tmpdir(), ConfigManager.getTempNativeFolder()), (err) => {
if(err){
logger.warn('Error while cleaning natives directory', err)
} else {
logger.info('Cleaned natives directory.')
}
})
contextBridge.exposeInMainWorld('api', module.exports.api)
30 changes: 30 additions & 0 deletions app/assets/js/renderer/langrenderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// HACK FIXME

let lang

export async function loadLanguage() {
lang = await window.api.Lang.getLang()
}

export function query(id, placeHolders){
let query = id.split('.')
let res = lang
for(let q of query){
res = res[q]
}
let text = res === lang ? '' : res
if (placeHolders) {
Object.entries(placeHolders).forEach(([key, value]) => {
text = text.replace(`{${key}}`, value)
})
}
return text
}

export function queryJS(id, placeHolders){
return query(`js.${id}`, placeHolders)
}

export function queryEJS(id, placeHolders){
return query(`ejs.${id}`, placeHolders)
}
Loading

0 comments on commit 639c699

Please sign in to comment.