From 6f09720393c9b63bd92c9d6b18c755ef695dab50 Mon Sep 17 00:00:00 2001 From: phyzical Date: Sat, 2 Apr 2022 23:04:48 +0800 Subject: [PATCH 1/3] added logic to add cmd/ctrl and +, cmd/ctrl and - cmd/ctrl and 0 * added logic to atleast allow arm64 to launch due to steam incopatibility --- electron/greenworks.js | 316 +++++++++++++++++++++-------------------- electron/main.js | 6 +- electron/menu.js | 104 +++++++++----- 3 files changed, 231 insertions(+), 195 deletions(-) diff --git a/electron/greenworks.js b/electron/greenworks.js index d883e8803..a6f8b2cdf 100644 --- a/electron/greenworks.js +++ b/electron/greenworks.js @@ -29,189 +29,191 @@ function error_process(err, error_callback) { error_callback(err); } -greenworks.ugcGetItems = function(options, ugc_matching_type, ugc_query_type, +if (greenworks) { + greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = ugc_query_type; - ugc_query_type = ugc_matching_type; - ugc_matching_type = options; - options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 + if (typeof options !== 'object') { + error_callback = success_callback; + success_callback = ugc_query_type; + ugc_query_type = ugc_matching_type; + ugc_matching_type = options; + options = { + 'app_id': greenworks.getAppId(), + 'page_num': 1 + } } - } - greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, + greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, success_callback, error_callback); -} + } -greenworks.ugcGetUserItems = function(options, ugc_matching_type, + greenworks.ugcGetUserItems = function (options, ugc_matching_type, ugc_list_sort_order, ugc_list, success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = ugc_list; - ugc_list = ugc_list_sort_order; - ugc_list_sort_order = ugc_matching_type; - ugc_matching_type = options; - options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 + if (typeof options !== 'object') { + error_callback = success_callback; + success_callback = ugc_list; + ugc_list = ugc_list_sort_order; + ugc_list_sort_order = ugc_matching_type; + ugc_matching_type = options; + options = { + 'app_id': greenworks.getAppId(), + 'page_num': 1 + } } - } - greenworks._ugcGetUserItems(options, ugc_matching_type, ugc_list_sort_order, + greenworks._ugcGetUserItems(options, ugc_matching_type, ugc_list_sort_order, ugc_list, success_callback, error_callback); -} + } -greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, + greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = sync_dir; - sync_dir = options; - options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 + if (typeof options !== 'object') { + error_callback = success_callback; + success_callback = sync_dir; + sync_dir = options; + options = { + 'app_id': greenworks.getAppId(), + 'page_num': 1 + } } - } - greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, + greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, error_callback); -} - -greenworks.publishWorkshopFile = function(options, file_path, image_path, title, - description, success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = description; - description = title; - title = image_path; - image_path = file_path; - file_path = options; - options = { - 'app_id': greenworks.getAppId(), - 'tags': [] - } } - greenworks._publishWorkshopFile(options, file_path, image_path, title, - description, success_callback, error_callback); -} -greenworks.updatePublishedWorkshopFile = function(options, + greenworks.publishWorkshopFile = function (options, file_path, image_path, title, + description, success_callback, error_callback) { + if (typeof options !== 'object') { + error_callback = success_callback; + success_callback = description; + description = title; + title = image_path; + image_path = file_path; + file_path = options; + options = { + 'app_id': greenworks.getAppId(), + 'tags': [] + } + } + greenworks._publishWorkshopFile(options, file_path, image_path, title, + description, success_callback, error_callback); + } + + greenworks.updatePublishedWorkshopFile = function (options, published_file_handle, file_path, image_path, title, description, success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = description; - description = title; - title = image_path; - image_path = file_path; - file_path = published_file_handle; - published_file_handle = options; - options = { - 'tags': [] // No tags are set + if (typeof options !== 'object') { + error_callback = success_callback; + success_callback = description; + description = title; + title = image_path; + image_path = file_path; + file_path = published_file_handle; + published_file_handle = options; + options = { + 'tags': [] // No tags are set + } } + greenworks._updatePublishedWorkshopFile(options, published_file_handle, + file_path, image_path, title, description, success_callback, + error_callback); } - greenworks._updatePublishedWorkshopFile(options, published_file_handle, - file_path, image_path, title, description, success_callback, - error_callback); -} -// An utility function for publish related APIs. -// It processes remains steps after saving files to Steam Cloud. -function file_share_process(file_name, image_name, next_process_func, + // An utility function for publish related APIs. + // It processes remains steps after saving files to Steam Cloud. + function file_share_process(file_name, image_name, next_process_func, error_callback, progress_callback) { - if (progress_callback) - progress_callback("Completed on saving files on Steam Cloud."); - greenworks.fileShare(file_name, function() { - greenworks.fileShare(image_name, function() { - next_process_func(); - }, function(err) { error_process(err, error_callback); }); - }, function(err) { error_process(err, error_callback); }); -} - -// Publishing user generated content(ugc) to Steam contains following steps: -// 1. Save file and image to Steam Cloud. -// 2. Share the file and image. -// 3. publish the file to workshop. -greenworks.ugcPublish = function(file_name, title, description, image_name, - success_callback, error_callback, progress_callback) { - var publish_file_process = function() { if (progress_callback) - progress_callback("Completed on sharing files."); - greenworks.publishWorkshopFile(file_name, image_name, title, description, - function(publish_file_id) { success_callback(publish_file_id); }, - function(err) { error_process(err, error_callback); }); - }; - greenworks.saveFilesToCloud([file_name, image_name], function() { - file_share_process(file_name, image_name, publish_file_process, - error_callback, progress_callback); - }, function(err) { error_process(err, error_callback); }); -} + progress_callback("Completed on saving files on Steam Cloud."); + greenworks.fileShare(file_name, function () { + greenworks.fileShare(image_name, function () { + next_process_func(); + }, function (err) { error_process(err, error_callback); }); + }, function (err) { error_process(err, error_callback); }); + } -// Update publish ugc steps: -// 1. Save new file and image to Steam Cloud. -// 2. Share file and images. -// 3. Update published file. -greenworks.ugcPublishUpdate = function(published_file_id, file_name, title, + // Publishing user generated content(ugc) to Steam contains following steps: + // 1. Save file and image to Steam Cloud. + // 2. Share the file and image. + // 3. publish the file to workshop. + greenworks.ugcPublish = function (file_name, title, description, image_name, + success_callback, error_callback, progress_callback) { + var publish_file_process = function () { + if (progress_callback) + progress_callback("Completed on sharing files."); + greenworks.publishWorkshopFile(file_name, image_name, title, description, + function (publish_file_id) { success_callback(publish_file_id); }, + function (err) { error_process(err, error_callback); }); + }; + greenworks.saveFilesToCloud([file_name, image_name], function () { + file_share_process(file_name, image_name, publish_file_process, + error_callback, progress_callback); + }, function (err) { error_process(err, error_callback); }); + } + + // Update publish ugc steps: + // 1. Save new file and image to Steam Cloud. + // 2. Share file and images. + // 3. Update published file. + greenworks.ugcPublishUpdate = function (published_file_id, file_name, title, description, image_name, success_callback, error_callback, progress_callback) { - var update_published_file_process = function() { - if (progress_callback) - progress_callback("Completed on sharing files."); - greenworks.updatePublishedWorkshopFile(published_file_id, + var update_published_file_process = function () { + if (progress_callback) + progress_callback("Completed on sharing files."); + greenworks.updatePublishedWorkshopFile(published_file_id, file_name, image_name, title, description, - function() { success_callback(); }, - function(err) { error_process(err, error_callback); }); + function () { success_callback(); }, + function (err) { error_process(err, error_callback); }); + }; + + greenworks.saveFilesToCloud([file_name, image_name], function () { + file_share_process(file_name, image_name, update_published_file_process, + error_callback, progress_callback); + }, function (err) { error_process(err, error_callback); }); + } + + // Greenworks Utils APIs implmentation. + greenworks.Utils.move = function (source_dir, target_dir, success_callback, + error_callback) { + fs.rename(source_dir, target_dir, function (err) { + if (err) { + if (error_callback) error_callback(err); + return; + } + if (success_callback) + success_callback(); + }); + } + + greenworks.init = function () { + if (this.initAPI()) return true; + if (!this.isSteamRunning()) + throw new Error("Steam initialization failed. Steam is not running."); + var appId; + try { + appId = fs.readFileSync('steam_appid.txt', 'utf8'); + } catch (e) { + throw new Error("Steam initialization failed. Steam is running," + + "but steam_appid.txt is missing. Expected to find it in: " + + require('path').resolve('steam_appid.txt')); + } + if (!/^\d+ *\r?\n?$/.test(appId)) { + throw new Error("Steam initialization failed. " + + "steam_appid.txt appears to be invalid; " + + "it should contain a numeric ID: " + appId); + } + throw new Error("Steam initialization failed, but Steam is running, " + + "and steam_appid.txt is present and valid." + + "Maybe that's not really YOUR app ID? " + appId.trim()); + } + + var EventEmitter = require('events').EventEmitter; + greenworks.__proto__ = EventEmitter.prototype; + EventEmitter.call(greenworks); + + greenworks._steam_events.on = function () { + greenworks.emit.apply(greenworks, arguments); }; - greenworks.saveFilesToCloud([file_name, image_name], function() { - file_share_process(file_name, image_name, update_published_file_process, - error_callback, progress_callback); - }, function(err) { error_process(err, error_callback); }); + process.versions['greenworks'] = greenworks._version; } -// Greenworks Utils APIs implmentation. -greenworks.Utils.move = function(source_dir, target_dir, success_callback, - error_callback) { - fs.rename(source_dir, target_dir, function(err) { - if (err) { - if (error_callback) error_callback(err); - return; - } - if (success_callback) - success_callback(); - }); -} - -greenworks.init = function() { - if (this.initAPI()) return true; - if (!this.isSteamRunning()) - throw new Error("Steam initialization failed. Steam is not running."); - var appId; - try { - appId = fs.readFileSync('steam_appid.txt', 'utf8'); - } catch (e) { - throw new Error("Steam initialization failed. Steam is running," + - "but steam_appid.txt is missing. Expected to find it in: " + - require('path').resolve('steam_appid.txt')); - } - if (!/^\d+ *\r?\n?$/.test(appId)) { - throw new Error("Steam initialization failed. " + - "steam_appid.txt appears to be invalid; " + - "it should contain a numeric ID: " + appId); - } - throw new Error("Steam initialization failed, but Steam is running, " + - "and steam_appid.txt is present and valid." + - "Maybe that's not really YOUR app ID? " + appId.trim()); -} - -var EventEmitter = require('events').EventEmitter; -greenworks.__proto__ = EventEmitter.prototype; -EventEmitter.call(greenworks); - -greenworks._steam_events.on = function () { - greenworks.emit.apply(greenworks, arguments); -}; - -process.versions['greenworks'] = greenworks._version; - module.exports = greenworks; diff --git a/electron/main.js b/electron/main.js index 0fb9eae67..9bc78c878 100644 --- a/electron/main.js +++ b/electron/main.js @@ -25,7 +25,7 @@ process.on('uncaughtException', function () { // We want to fail gracefully if we cannot connect to Steam try { - if (greenworks.init()) { + if (greenworks && greenworks.init()) { log.info("Steam API has been initialized."); } else { const error = "Steam API has failed to initialize."; @@ -149,7 +149,7 @@ function setStopProcessHandler(app, window, enabled) { } const { save, ...other } = arg; - log.silly("Received game saved info", {...other, save: `${save.length} bytes`}); + log.silly("Received game saved info", { ...other, save: `${save.length} bytes` }); if (storage.isAutosaveEnabled()) { saveToDisk(save, arg.fileName); @@ -159,7 +159,7 @@ function setStopProcessHandler(app, window, enabled) { const playtime = window.gameInfo.player.playtime; log.silly(window.gameInfo); if (playtime > minimumPlaytime) { - saveToCloud(save); + saveToCloud(save); } else { log.debug(`Auto-save to cloud disabled for save game under ${minimumPlaytime}ms (${playtime}ms)`); } diff --git a/electron/menu.js b/electron/menu.js index 9cf62d755..708ef2ec6 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -8,6 +8,40 @@ const storage = require("./storage"); const config = new Config(); function getMenu(window) { + const canZoomIn = utils.getZoomFactor() <= 2 + const zoomIn = () => { + const currentZoom = utils.getZoomFactor(); + const newZoom = currentZoom + 0.1; + if (newZoom <= 2.0) { + utils.setZoomFactor(window, newZoom); + refreshMenu(window); + } else { + log.log('Max zoom out') + utils.writeToast(window, "Cannot zoom in anymore", "warning"); + } + } + + const canZoomOut = utils.getZoomFactor() >= 0.5 + const zoomOut = () => { + const currentZoom = utils.getZoomFactor(); + const newZoom = currentZoom - 0.1; + if (newZoom >= 0.5) { + utils.setZoomFactor(window, newZoom); + refreshMenu(window); + } else { + log.log('Max zoom in') + utils.writeToast(window, "Cannot zoom out anymore", "warning"); + } + } + + const canResetZoom = utils.getZoomFactor() !== 1 + const resetZoom = () => { + utils.setZoomFactor(window, 1); + refreshMenu(window); + log.log("Reset zoom"); + } + + return Menu.buildFromTemplate([ { label: "File", @@ -264,11 +298,11 @@ function getMenu(window) { detail: 'There is an official Visual Studio Code extension that makes use of that feature.\n\n' + 'It allows you to write your script file in an external IDE and have them pushed over to the game automatically.\n' + 'If you want more information, head over to: https://github.com/bitburner-official/bitburner-vscode.', - buttons: ['Dismiss', 'Open Extension Link (GitHub)'], - defaultId: 0, - cancelId: 0, - noLink: true, - }).then(({response}) => { + buttons: ['Dismiss', 'Open Extension Link (GitHub)'], + defaultId: 0, + cancelId: 0, + noLink: true, + }).then(({ response }) => { if (response === 1) { utils.openExternal('https://github.com/bitburner-official/bitburner-vscode'); } @@ -282,45 +316,45 @@ function getMenu(window) { submenu: [ { label: "Zoom In", - enabled: utils.getZoomFactor() <= 2, + enabled: canZoomIn, accelerator: "CommandOrControl+numadd", - click: () => { - const currentZoom = utils.getZoomFactor(); - const newZoom = currentZoom + 0.1; - if (newZoom <= 2.0) { - utils.setZoomFactor(window, newZoom); - refreshMenu(window); - } else { - log.log('Max zoom out') - utils.writeToast(window, "Cannot zoom in anymore", "warning"); - } - }, + click: zoomIn, + }, + { + label: "Zoom In (non numpad)", + enabled: canZoomIn, + visible: false, + accelerator: "CommandOrControl+Plus", + acceleratorWorksWhenHidden: true, + click: zoomIn, }, { label: "Zoom Out", - enabled: utils.getZoomFactor() >= 0.5, + enabled: canZoomOut, accelerator: "CommandOrControl+numsub", - click: () => { - const currentZoom = utils.getZoomFactor(); - const newZoom = currentZoom - 0.1; - if (newZoom >= 0.5) { - utils.setZoomFactor(window, newZoom); - refreshMenu(window); - } else { - log.log('Max zoom in') - utils.writeToast(window, "Cannot zoom out anymore", "warning"); - } - }, + click: zoomOut, + }, + { + label: "Zoom Out (non numpad)", + enabled: canZoomOut, + accelerator: "CommandOrControl+-", + visible: false, + acceleratorWorksWhenHidden: true, + click: zoomOut, }, { label: "Reset Zoom", - enabled: utils.getZoomFactor() !== 1, + enabled: canResetZoom, accelerator: "CommandOrControl+num0", - click: () => { - utils.setZoomFactor(window, 1); - refreshMenu(window); - log.log("Reset zoom"); - }, + click: resetZoom, + }, + { + label: "Reset Zoom (non numpad)", + enabled: canResetZoom, + accelerator: "CommandOrControl+0", + visible: false, + acceleratorWorksWhenHidden: true, + click: resetZoom, }, ], }, From a4d221f709db5b4cd9663098050e571b245623a4 Mon Sep 17 00:00:00 2001 From: phyzical Date: Thu, 7 Apr 2022 16:23:26 +0800 Subject: [PATCH 2/3] missed a conflict opps --- electron/greenworks.js | 599 +++++++++++++++-------------------------- 1 file changed, 211 insertions(+), 388 deletions(-) diff --git a/electron/greenworks.js b/electron/greenworks.js index 4f2738ba4..88a84ffeb 100644 --- a/electron/greenworks.js +++ b/electron/greenworks.js @@ -22,59 +22,73 @@ function error_process(err, error_callback) { if (err && error_callback) error_callback(err); } -<<<<<<< HEAD if (greenworks) { - greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, - success_callback, error_callback) { - if (typeof options !== 'object') { + greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, success_callback, error_callback) { + if (typeof options !== "object") { error_callback = success_callback; success_callback = ugc_query_type; ugc_query_type = ugc_matching_type; ugc_matching_type = options; options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 - } + app_id: greenworks.getAppId(), + page_num: 1, + }; } - greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, - success_callback, error_callback); - } + greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, success_callback, error_callback); + }; - greenworks.ugcGetUserItems = function (options, ugc_matching_type, - ugc_list_sort_order, ugc_list, success_callback, error_callback) { - if (typeof options !== 'object') { + greenworks.ugcGetUserItems = function ( + options, + ugc_matching_type, + ugc_list_sort_order, + ugc_list, + success_callback, + error_callback, + ) { + if (typeof options !== "object") { error_callback = success_callback; success_callback = ugc_list; ugc_list = ugc_list_sort_order; ugc_list_sort_order = ugc_matching_type; ugc_matching_type = options; options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 - } + app_id: greenworks.getAppId(), + page_num: 1, + }; } - greenworks._ugcGetUserItems(options, ugc_matching_type, ugc_list_sort_order, - ugc_list, success_callback, error_callback); - } + greenworks._ugcGetUserItems( + options, + ugc_matching_type, + ugc_list_sort_order, + ugc_list, + success_callback, + error_callback, + ); + }; - greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, - error_callback) { - if (typeof options !== 'object') { + greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, error_callback) { + if (typeof options !== "object") { error_callback = success_callback; success_callback = sync_dir; sync_dir = options; options = { - 'app_id': greenworks.getAppId(), - 'page_num': 1 - } + app_id: greenworks.getAppId(), + page_num: 1, + }; } - greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, - error_callback); - } + greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, error_callback); + }; - greenworks.publishWorkshopFile = function (options, file_path, image_path, title, - description, success_callback, error_callback) { - if (typeof options !== 'object') { + greenworks.publishWorkshopFile = function ( + options, + file_path, + image_path, + title, + description, + success_callback, + error_callback, + ) { + if (typeof options !== "object") { error_callback = success_callback; success_callback = description; description = title; @@ -82,230 +96,22 @@ if (greenworks) { image_path = file_path; file_path = options; options = { - 'app_id': greenworks.getAppId(), - 'tags': [] - } + app_id: greenworks.getAppId(), + tags: [], + }; } - greenworks._publishWorkshopFile(options, file_path, image_path, title, - description, success_callback, error_callback); - } + greenworks._publishWorkshopFile( + options, + file_path, + image_path, + title, + description, + success_callback, + error_callback, + ); + }; - greenworks.updatePublishedWorkshopFile = function (options, - published_file_handle, file_path, image_path, title, description, - success_callback, error_callback) { - if (typeof options !== 'object') { - error_callback = success_callback; - success_callback = description; - description = title; - title = image_path; - image_path = file_path; - file_path = published_file_handle; - published_file_handle = options; - options = { - 'tags': [] // No tags are set - } - } - greenworks._updatePublishedWorkshopFile(options, published_file_handle, - file_path, image_path, title, description, success_callback, - error_callback); - } - - // An utility function for publish related APIs. - // It processes remains steps after saving files to Steam Cloud. - function file_share_process(file_name, image_name, next_process_func, - error_callback, progress_callback) { - if (progress_callback) - progress_callback("Completed on saving files on Steam Cloud."); - greenworks.fileShare(file_name, function () { - greenworks.fileShare(image_name, function () { - next_process_func(); - }, function (err) { error_process(err, error_callback); }); - }, function (err) { error_process(err, error_callback); }); - } - - // Publishing user generated content(ugc) to Steam contains following steps: - // 1. Save file and image to Steam Cloud. - // 2. Share the file and image. - // 3. publish the file to workshop. - greenworks.ugcPublish = function (file_name, title, description, image_name, - success_callback, error_callback, progress_callback) { - var publish_file_process = function () { - if (progress_callback) - progress_callback("Completed on sharing files."); - greenworks.publishWorkshopFile(file_name, image_name, title, description, - function (publish_file_id) { success_callback(publish_file_id); }, - function (err) { error_process(err, error_callback); }); - }; - greenworks.saveFilesToCloud([file_name, image_name], function () { - file_share_process(file_name, image_name, publish_file_process, - error_callback, progress_callback); - }, function (err) { error_process(err, error_callback); }); - } - - // Update publish ugc steps: - // 1. Save new file and image to Steam Cloud. - // 2. Share file and images. - // 3. Update published file. - greenworks.ugcPublishUpdate = function (published_file_id, file_name, title, - description, image_name, success_callback, error_callback, - progress_callback) { - var update_published_file_process = function () { - if (progress_callback) - progress_callback("Completed on sharing files."); - greenworks.updatePublishedWorkshopFile(published_file_id, - file_name, image_name, title, description, - function () { success_callback(); }, - function (err) { error_process(err, error_callback); }); - }; - - greenworks.saveFilesToCloud([file_name, image_name], function () { - file_share_process(file_name, image_name, update_published_file_process, - error_callback, progress_callback); - }, function (err) { error_process(err, error_callback); }); - } - - // Greenworks Utils APIs implmentation. - greenworks.Utils.move = function (source_dir, target_dir, success_callback, - error_callback) { - fs.rename(source_dir, target_dir, function (err) { - if (err) { - if (error_callback) error_callback(err); - return; - } - if (success_callback) - success_callback(); - }); - } - - greenworks.init = function () { - if (this.initAPI()) return true; - if (!this.isSteamRunning()) - throw new Error("Steam initialization failed. Steam is not running."); - var appId; - try { - appId = fs.readFileSync('steam_appid.txt', 'utf8'); - } catch (e) { - throw new Error("Steam initialization failed. Steam is running," + - "but steam_appid.txt is missing. Expected to find it in: " + - require('path').resolve('steam_appid.txt')); - } - if (!/^\d+ *\r?\n?$/.test(appId)) { - throw new Error("Steam initialization failed. " + - "steam_appid.txt appears to be invalid; " + - "it should contain a numeric ID: " + appId); - } - throw new Error("Steam initialization failed, but Steam is running, " + - "and steam_appid.txt is present and valid." + - "Maybe that's not really YOUR app ID? " + appId.trim()); - } - - var EventEmitter = require('events').EventEmitter; - greenworks.__proto__ = EventEmitter.prototype; - EventEmitter.call(greenworks); -======= -greenworks.ugcGetItems = function (options, ugc_matching_type, ugc_query_type, success_callback, error_callback) { - if (typeof options !== "object") { - error_callback = success_callback; - success_callback = ugc_query_type; - ugc_query_type = ugc_matching_type; - ugc_matching_type = options; - options = { - app_id: greenworks.getAppId(), - page_num: 1, - }; - } - greenworks._ugcGetItems(options, ugc_matching_type, ugc_query_type, success_callback, error_callback); -}; - -greenworks.ugcGetUserItems = function ( - options, - ugc_matching_type, - ugc_list_sort_order, - ugc_list, - success_callback, - error_callback, -) { - if (typeof options !== "object") { - error_callback = success_callback; - success_callback = ugc_list; - ugc_list = ugc_list_sort_order; - ugc_list_sort_order = ugc_matching_type; - ugc_matching_type = options; - options = { - app_id: greenworks.getAppId(), - page_num: 1, - }; - } - greenworks._ugcGetUserItems( - options, - ugc_matching_type, - ugc_list_sort_order, - ugc_list, - success_callback, - error_callback, - ); -}; - -greenworks.ugcSynchronizeItems = function (options, sync_dir, success_callback, error_callback) { - if (typeof options !== "object") { - error_callback = success_callback; - success_callback = sync_dir; - sync_dir = options; - options = { - app_id: greenworks.getAppId(), - page_num: 1, - }; - } - greenworks._ugcSynchronizeItems(options, sync_dir, success_callback, error_callback); -}; - -greenworks.publishWorkshopFile = function ( - options, - file_path, - image_path, - title, - description, - success_callback, - error_callback, -) { - if (typeof options !== "object") { - error_callback = success_callback; - success_callback = description; - description = title; - title = image_path; - image_path = file_path; - file_path = options; - options = { - app_id: greenworks.getAppId(), - tags: [], - }; - } - greenworks._publishWorkshopFile(options, file_path, image_path, title, description, success_callback, error_callback); -}; - -greenworks.updatePublishedWorkshopFile = function ( - options, - published_file_handle, - file_path, - image_path, - title, - description, - success_callback, - error_callback, -) { - if (typeof options !== "object") { - error_callback = success_callback; - success_callback = description; - description = title; - title = image_path; - image_path = file_path; - file_path = published_file_handle; - published_file_handle = options; - options = { - tags: [], // No tags are set - }; - } - greenworks._updatePublishedWorkshopFile( + greenworks.updatePublishedWorkshopFile = function ( options, published_file_handle, file_path, @@ -314,95 +120,86 @@ greenworks.updatePublishedWorkshopFile = function ( description, success_callback, error_callback, - ); -}; + ) { + if (typeof options !== "object") { + error_callback = success_callback; + success_callback = description; + description = title; + title = image_path; + image_path = file_path; + file_path = published_file_handle; + published_file_handle = options; + options = { + tags: [], // No tags are set + }; + } + greenworks._updatePublishedWorkshopFile( + options, + published_file_handle, + file_path, + image_path, + title, + description, + success_callback, + error_callback, + ); + }; -// An utility function for publish related APIs. -// It processes remains steps after saving files to Steam Cloud. -function file_share_process(file_name, image_name, next_process_func, error_callback, progress_callback) { - if (progress_callback) progress_callback("Completed on saving files on Steam Cloud."); - greenworks.fileShare( + // An utility function for publish related APIs. + // It processes remains steps after saving files to Steam Cloud. + function file_share_process(file_name, image_name, next_process_func, error_callback, progress_callback) { + if (progress_callback) progress_callback("Completed on saving files on Steam Cloud."); + greenworks.fileShare( + file_name, + function () { + greenworks.fileShare( + image_name, + function () { + next_process_func(); + }, + function (err) { + error_process(err, error_callback); + }, + ); + }, + function (err) { + error_process(err, error_callback); + }, + ); + } + + // Publishing user generated content(ugc) to Steam contains following steps: + // 1. Save file and image to Steam Cloud. + // 2. Share the file and image. + // 3. publish the file to workshop. + greenworks.ugcPublish = function ( file_name, - function () { - greenworks.fileShare( + title, + description, + image_name, + success_callback, + error_callback, + progress_callback, + ) { + var publish_file_process = function () { + if (progress_callback) progress_callback("Completed on sharing files."); + greenworks.publishWorkshopFile( + file_name, image_name, - function () { - next_process_func(); + title, + description, + function (publish_file_id) { + success_callback(publish_file_id); }, function (err) { error_process(err, error_callback); }, ); - }, - function (err) { - error_process(err, error_callback); - }, - ); -} - -// Publishing user generated content(ugc) to Steam contains following steps: -// 1. Save file and image to Steam Cloud. -// 2. Share the file and image. -// 3. publish the file to workshop. -greenworks.ugcPublish = function ( - file_name, - title, - description, - image_name, - success_callback, - error_callback, - progress_callback, -) { - var publish_file_process = function () { - if (progress_callback) progress_callback("Completed on sharing files."); - greenworks.publishWorkshopFile( - file_name, - image_name, - title, - description, - function (publish_file_id) { - success_callback(publish_file_id); - }, - function (err) { - error_process(err, error_callback); - }, - ); - }; - greenworks.saveFilesToCloud( - [file_name, image_name], - function () { - file_share_process(file_name, image_name, publish_file_process, error_callback, progress_callback); - }, - function (err) { - error_process(err, error_callback); - }, - ); -}; - -// Update publish ugc steps: -// 1. Save new file and image to Steam Cloud. -// 2. Share file and images. -// 3. Update published file. -greenworks.ugcPublishUpdate = function ( - published_file_id, - file_name, - title, - description, - image_name, - success_callback, - error_callback, - progress_callback, -) { - var update_published_file_process = function () { - if (progress_callback) progress_callback("Completed on sharing files."); - greenworks.updatePublishedWorkshopFile( - published_file_id, - file_name, - image_name, - title, - description, + }; + greenworks.saveFilesToCloud( + [file_name, image_name], function () { - success_callback(); + file_share_process(file_name, image_name, publish_file_process, error_callback, progress_callback); }, function (err) { error_process(err, error_callback); @@ -410,71 +207,97 @@ greenworks.ugcPublishUpdate = function ( ); }; - greenworks.saveFilesToCloud( - [file_name, image_name], - function () { - file_share_process(file_name, image_name, update_published_file_process, error_callback, progress_callback); - }, - function (err) { - error_process(err, error_callback); - }, - ); -}; + // Update publish ugc steps: + // 1. Save new file and image to Steam Cloud. + // 2. Share file and images. + // 3. Update published file. + greenworks.ugcPublishUpdate = function ( + published_file_id, + file_name, + title, + description, + image_name, + success_callback, + error_callback, + progress_callback, + ) { + var update_published_file_process = function () { + if (progress_callback) progress_callback("Completed on sharing files."); + greenworks.updatePublishedWorkshopFile( + published_file_id, + file_name, + image_name, + title, + description, + function () { + success_callback(); + }, + function (err) { + error_process(err, error_callback); + }, + ); + }; -// Greenworks Utils APIs implmentation. -greenworks.Utils.move = function (source_dir, target_dir, success_callback, error_callback) { - fs.rename(source_dir, target_dir, function (err) { - if (err) { - if (error_callback) error_callback(err); - return; + greenworks.saveFilesToCloud( + [file_name, image_name], + function () { + file_share_process(file_name, image_name, update_published_file_process, error_callback, progress_callback); + }, + function (err) { + error_process(err, error_callback); + }, + ); + }; + + // Greenworks Utils APIs implmentation. + greenworks.Utils.move = function (source_dir, target_dir, success_callback, error_callback) { + fs.rename(source_dir, target_dir, function (err) { + if (err) { + if (error_callback) error_callback(err); + return; + } + if (success_callback) success_callback(); + }); + }; + + greenworks.init = function () { + if (this.initAPI()) return true; + if (!this.isSteamRunning()) throw new Error("Steam initialization failed. Steam is not running."); + var appId; + try { + appId = fs.readFileSync("steam_appid.txt", "utf8"); + } catch (e) { + throw new Error( + "Steam initialization failed. Steam is running," + + "but steam_appid.txt is missing. Expected to find it in: " + + require("path").resolve("steam_appid.txt"), + ); + } + if (!/^\d+ *\r?\n?$/.test(appId)) { + throw new Error( + "Steam initialization failed. " + + "steam_appid.txt appears to be invalid; " + + "it should contain a numeric ID: " + + appId, + ); } - if (success_callback) success_callback(); - }); -}; - -greenworks.init = function () { - if (this.initAPI()) return true; - if (!this.isSteamRunning()) throw new Error("Steam initialization failed. Steam is not running."); - var appId; - try { - appId = fs.readFileSync("steam_appid.txt", "utf8"); - } catch (e) { throw new Error( - "Steam initialization failed. Steam is running," + - "but steam_appid.txt is missing. Expected to find it in: " + - require("path").resolve("steam_appid.txt"), + "Steam initialization failed, but Steam is running, " + + "and steam_appid.txt is present and valid." + + "Maybe that's not really YOUR app ID? " + + appId.trim(), ); - } - if (!/^\d+ *\r?\n?$/.test(appId)) { - throw new Error( - "Steam initialization failed. " + - "steam_appid.txt appears to be invalid; " + - "it should contain a numeric ID: " + - appId, - ); - } - throw new Error( - "Steam initialization failed, but Steam is running, " + - "and steam_appid.txt is present and valid." + - "Maybe that's not really YOUR app ID? " + - appId.trim(), - ); -}; + }; -var EventEmitter = require("events").EventEmitter; -greenworks.__proto__ = EventEmitter.prototype; -EventEmitter.call(greenworks); ->>>>>>> dev + var EventEmitter = require("events").EventEmitter; + greenworks.__proto__ = EventEmitter.prototype; + EventEmitter.call(greenworks); greenworks._steam_events.on = function () { greenworks.emit.apply(greenworks, arguments); }; -<<<<<<< HEAD - process.versions['greenworks'] = greenworks._version; + process.versions["greenworks"] = greenworks._version; } -======= -process.versions["greenworks"] = greenworks._version; ->>>>>>> dev module.exports = greenworks; From 7cc3b8508377226fa9f8ef66f869e96ffd5c37ea Mon Sep 17 00:00:00 2001 From: phyzical Date: Thu, 7 Apr 2022 16:23:31 +0800 Subject: [PATCH 3/3] linting --- electron/menu.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/electron/menu.js b/electron/menu.js index e93885441..c7449efd8 100644 --- a/electron/menu.js +++ b/electron/menu.js @@ -8,7 +8,7 @@ const storage = require("./storage"); const config = new Config(); function getMenu(window) { - const canZoomIn = utils.getZoomFactor() <= 2 + const canZoomIn = utils.getZoomFactor() <= 2; const zoomIn = () => { const currentZoom = utils.getZoomFactor(); const newZoom = currentZoom + 0.1; @@ -16,12 +16,12 @@ function getMenu(window) { utils.setZoomFactor(window, newZoom); refreshMenu(window); } else { - log.log('Max zoom out') + log.log("Max zoom out"); utils.writeToast(window, "Cannot zoom in anymore", "warning"); } - } + }; - const canZoomOut = utils.getZoomFactor() >= 0.5 + const canZoomOut = utils.getZoomFactor() >= 0.5; const zoomOut = () => { const currentZoom = utils.getZoomFactor(); const newZoom = currentZoom - 0.1; @@ -29,18 +29,17 @@ function getMenu(window) { utils.setZoomFactor(window, newZoom); refreshMenu(window); } else { - log.log('Max zoom in') + log.log("Max zoom in"); utils.writeToast(window, "Cannot zoom out anymore", "warning"); } - } + }; - const canResetZoom = utils.getZoomFactor() !== 1 + const canResetZoom = utils.getZoomFactor() !== 1; const resetZoom = () => { utils.setZoomFactor(window, 1); refreshMenu(window); log.log("Reset zoom"); - } - + }; return Menu.buildFromTemplate([ {